Is there an easy way to call a function given a string name in mako?
+2
A:
You should be able to look it up in the dict returned by globals()
. Eg.:
<$ func_name = 'my_function_name' %>
${globals()[func_name](...)}
Although, this does smell rather nasty to me. If you could expand upon your end game perhaps we can figure out something a bit saner.
Mike Boers
2010-10-01 21:22:15
thanks, this is related to http://stackoverflow.com/questions/3842458/python-lookup-function so i'm trying to figure out ways around it
Timmy
2010-10-01 21:26:54
I like your interrobang. Also, +1 for a good answer and for getting clarification on why this is needed.
JoshD
2010-10-01 21:27:01