Loading functions from a file during run-time
tjprojects_usenet at yahoo.com
tjprojects_usenet at yahoo.com
Wed Feb 16 13:55:50 EST 2005
Wensheng wrote:
> #--- file bar.py
<snip>
> >>> foo="bar"
> >>> fs=__import__(foo)
<snip>
Wensheng:
The problem with this is that it assumes the text file is a valid
python file, and that the extension is ".py". This may work for the
OP's situation; he would need to weigh in. 'exec'ing the functions
into the global namespace allows you to create functions from any
text-based source -- registry keys, ini files, user input, etc.
T.J.
More information about the Python-list
mailing list