newbie-ish question on exec statement

Grant Edwards grante at visi.com
Mon Mar 11 22:35:54 EST 2002


In article <mailman.1015899200.14905.python-list at python.org>, Gabe Newcomb wrote:
> Hi all:
> 	I'd appreciate any comments people might have on the limitations
> of using exec. Specifically, what I want to do is build function names
> dynamically and call them (don't ask why).

http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.103.htp

> def my_function(arg1, arg2="", arg3=""):
> 	blah blah
> 
> exec "t = my_" + "function('\\\\machine\\share')"

It might be easier to debug if you use some of Python's
introspection features:

destName = "t"
funcName = "my_" + "function"
f = locals()["my_function"]
locals()[destName] = f('\\\\machine\\share')

-- 
Grant Edwards                   grante             Yow!  I'm rated PG-34!!
                                  at               
                               visi.com            



More information about the Python-list mailing list