Re: Loading functions from a file during run-time

2005-02-15 Thread tjprojects_usenet
I have to say, I was skeptical about your execution method at first --
simply joining all of the lines and then compiling them.  My
understanding of the compile method from the documentation led me to
believe that you needed to process a line at a time.  ''.join ing them
all seems to work very well, however, and it's a lot easier!

My comments about 'exec obj in globals()' still stand, however.  Give
it a try and let me know if it works the way you expect.


T.J.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Loading functions from a file during run-time

2005-02-16 Thread tjprojects_usenet
Wensheng wrote:
> #--- file bar.py



> >>> foo="bar"
> >>> fs=__import__(foo)



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.

-- 
http://mail.python.org/mailman/listinfo/python-list