py2exe and dynamic modules
Peter Hansen
peter at engcorp.com
Mon Jun 9 16:18:36 EDT 2003
"Uwe C. Schroeder" wrote:
>
> The problem is, that I don't use a normal "import blah" statement, since I
> don't know the name yet. AFAIK py2exe actually creates a dict of modules t
> load, so if it doesn't find it at compile time, it's still in the dict -
> making it possible to do a later import. If the module wasn't specified at
> compile time it won't be found.
Oops, I saw that part, but just didn't think clearly enough when I replied.
Let me try again:
File imptest.py, compiled with py2exe as imptest.exe:
import sys
sys.path.append('c:/temp')
filename = sys.argv[1]
try:
mod = __import__(filename)
print mod.test()
except:
print 'test failed!'
File importme.py, stored in c:/temp, containing
def test():
return 'test OK!'
Run imptest.exe from a directory other than c:/temp:
"test OK" results.
Looks like it works... (I'm doing this test first... what did I do
wrong this time? :-)
-Peter
More information about the Python-list
mailing list