py2exe and dynamic modules

Peter Hansen peter at
Mon Jun 9 22:18:36 CEST 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, compiled with py2exe as imptest.exe:

import sys
filename = sys.argv[1]
    mod = __import__(filename)
    print mod.test()
    print 'test failed!'

File, 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?  :-)


More information about the Python-list mailing list