[EMAIL PROTECTED] wrote:
> Try this:
>
> def myfunc():
> print "helo"
>
> s = "myfunc()"
> a = eval(s)
>
No, please don't try that. Good uses for eval are *very* rare, and this
isn't one of them.
Use the 'a = locals()[x]()' suggestion (or vars() instead of locals()), or
even better put al
Try this:
def myfunc():
print "helo"
s = "myfunc()"
a = eval(s)
--
http://mail.python.org/mailman/listinfo/python-list
Aljosa Mohorovic wrote:
> can i do something like this:
>
> s = "myFunction"
> a = s() # equals to: a = myFunction()
Functions are first-class objects in Python, so you can do:
def myFunction():
# whatever
which creates a function object and binds the name myFunction to it. Then:
s = myFu
Aljosa Mohorovic wrote:
can i do something like this:
s = "myFunction"
a = s() # equals to: a = myFunction()
a = locals()[x]()
locals() returns a dictionary with string keys that you can use
--
--
Ola Natvig <[EMAIL PROTECTED]>
infoSense AS / development
--
ht
can i do something like this:
s = "myFunction"
a = s() # equals to: a = myFunction()
--
http://mail.python.org/mailman/listinfo/python-list