Loading functions from a file during run-time

Wensheng wenshengwang at gmail.com
Fri Feb 11 20:29:04 EST 2005


if the file you want to include is not txt, but instead py, it should
be easy.
for example you have fs.py

you just
-------------------------------------
fs=__import__("fs")
f=[a for a in dir(fs) if a[0:2]!='__']
#no you have f1(),f2(),f3() as f[0],f[1],f[2]
then excute desired function, for example f2():
exec("fs."+f[1]+"()")


if you have top level variable in that file, just modify this to test
typs.FunctionType(import types first)




More information about the Python-list mailing list