Question: Dynamic code import

Károly Ladvánszky aa at bb.cc
Thu Oct 25 18:32:53 EDT 2001


Being really new in the Pyhton world, I'm not sure what else than text files
(.py) could come into view.
To put it simple, I'd like to have a def  f11(a)  in a file and read it in
and use f11 like the functions in the
running script. Its something else than using 'import' as the file may not
be existent at all when the script
starts running. In Lisp, the 'load' function does this.

"Bjorn Pettersen" <BPettersen at NAREX.com> az alábbiakat írta a következo
üzenetben: news:mailman.1004046266.4930.python-list at python.org...
> From: Károly Ladvánszky [mailto:aa at bb.cc]
>
> Hi Bjorn,
>
> Thanks for your quick answer. Yes, I was mistaken with the
> global directive. It's clear now. Regarding the first
> question, it works fine with the interpreter but I would like to read
> f11(a) from somewhere else, most likely from a file.

Hmmm... Not quite sure what you mean. Is it in a Python file, a text
file, ??

If it's in a Python file you can just import the module and assign to
the variable as before, if it's in a text file you'd need to use eval or
exec. Let us know which it is and I'm sure we could come up with
examples... :-)

-- bjorn



______________________________________________________________________________
Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net



More information about the Python-list mailing list