script question
Piet van Oostrum
piet at cs.uu.nl
Fri Apr 17 06:32:14 EDT 2009
>>>>> "Stefano" <stefano at vulcanos.it> (S) wrote:
>S> I have a script like this
>S> myscript.py
>S> def func01()
>S> def func02()
>S> def func03()
>S> ....
>S> def funcnn()
>S> How can i execute my func in the code ?
>S> import myscript
>S> for i in range(1,n):
>S> myscript.func??
Others have suggested getattr. I think a cleaner (more pythonic) way
would be:
funclist = [func01, func02, func03, ... ]
for i in range(1,n):
funclist[i]()
Or myscript.funclist[i]() from another module.
--
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org
More information about the Python-list
mailing list