how to get the path of a module (myself) ?

Vlastimil Brom vlastimil.brom at gmail.com
Tue Jun 2 11:11:30 CEST 2009


2009/6/2 Stef Mientki <stef.mientki at gmail.com>:
...
> and the files generated by Py2Exe, don't work at all.
>
> Through this discussion, I discovered another problem,
> because __file__ isn't the current file,
> I can't run 1 module(file) from another module (file) .
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

There are already  answers regarding other more topical issues with
the initial problem; but just in case the main problem would be the
use of __file__ ...
It seems, that the exe files generated from py2exe don't recognise
this variable;
sometimes I used code like

try:
    __file__
except NameError: # py2exe
    __file__ = sys.path[0]

cf. e.g. http://mail.python.org/pipermail/python-list/2001-May/085384.html


I'm not sure, whether there are any drawbacks, but it works in the
respective context (accessing text and image files in parallel
directories).

vbr



More information about the Python-list mailing list