py2exe and dynamic modules
Uwe C. Schroeder
uwe at oss4u.com
Mon Jun 9 16:48:35 EDT 2003
Peter Hansen wrote:
> "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? :-)
>
:-)) You knew the path up front. But I'll probably do just that and install
the modules in a fixed path, although I don't really like it. But I guess
it's easier than fiddling around with the py2exe import stuff.
--
UC
--
Open Source Solutions 4U, LLC 2570 Fleetwood Drive
Phone: +1 650 872 2425 San Bruno, CA 94066
Cell: +1 650 302 2405 United States
Fax: +1 650 872 2417
More information about the Python-list
mailing list