How do you convert a string (for example, input from a textbox) into a proper function?
A:
def func():
print "hello"
# just eval it
eval(raw_input())
# if you just want to ask for name
fName=raw_input()
if fName in globals():
globals()[fName]()
And there could be various other ways depending on what is the objective?
Anurag Uniyal
2009-10-04 04:42:33
hi anurag, just for a little beginner experiment - get the user to type a function and then i graph it
nickf
2009-10-04 04:47:21
in that case I think eval would be just fine, you can use pycallgraph.start_trace() (http://pycallgraph.slowchop.com) before eval
Anurag Uniyal
2009-10-04 05:22:56