Getting a function name from string

Carsten Haese carsten at uniqsys.com
Tue May 8 07:55:02 EDT 2007


On Tue, 8 May 2007 09:38:48 +0200, Cesar Härdfeldt wrote
> [...]  
> I now have 'module' and 'function' as strings and 'parms' normally as a list of strings. I can import the module by __import__(module) but is there another way to call:
> module.function(parms) than using eval()?

function_to_call = getattr(__import__(module), function)
function_to_call(parms)

Hope this helps,

--
Carsten Haese
http://informixdb.sourceforge.net

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070508/1f6b631c/attachment.html>


More information about the Python-list mailing list