calling a function from string

Shane Geiger sgeiger at ncee.net
Mon Oct 22 09:59:59 EDT 2007


>>> exec("import datetime") ; exec("x = datetime." + "date." + "today()")
>>> print x
2007-10-22




james_027 wrote:
> hi,
>
> i have a function that I could like to call, but to make it more
> dynamic I am constructing a string first that could equivalent to the
> name of the function I wish to call. how could I do that? the string
> could might include name of the module.
>
> for example
>
> a_string = 'datetime.' + 'today()'
>
> how could I call a_string as function?
>
> Thanks
> james
>
>   


-- 
Shane Geiger
IT Director
National Council on Economic Education
sgeiger at ncee.net  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

-------------- next part --------------
A non-text attachment was scrubbed...
Name: sgeiger.vcf
Type: text/x-vcard
Size: 288 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20071022/3fc7221a/attachment.vcf>


More information about the Python-list mailing list