include files with a package

Thomas Heller theller at python.net
Mon May 28 12:46:10 EDT 2001


"Mike C. Fletcher" wrote:
> 
> For python files loaded directly from disk, see the __file__ variable in
> your module.  Unfortunately, this variable has a habit of being available or
> not depending on the phase of the moon (mostly when you pack Python packages
> into an exe with Py2EXE or McMillan Installer).

This is probably because the __file__ attribute doesn't make too
much sense on a module imported from an archive, but OTOH
too much breaks if __file__ is not present ;-)

Maybe a _documented_ way to determine whether the module
is loaded from disk or from an archive would make sense?

>  When using those, you need
> hacks to figure out the .exe's directory (which is, with all known versions
> of those systems, sys.path[0] if you don't muck around with the path).

Funny, I was thinking about removing this entry from sys.path in py2exe.
My plans were to run the py2exe-packed executable with an empty
sys.path, and if the script would add something to sys.path
this would enable loading modules from the file system...

Thomas



More information about the Python-list mailing list