include files with a package
Mike C. Fletcher
mcfletch at home.com
Mon May 28 19:10:54 CEST 2001
+1 on disk/archive documented query function :)
-1 on removing sys.path entry 'cause it'd break my current project. Wait
three days and I'll give you a +1 ;-) . Seriously, I _like_ the current
semantics, and don't see any reason to remove them, it gives you an easily
understood mechanism for including "excluded" modules that doesn't require
the user to update their scripts specially to be exe-aware. Drop the
excluded modules/packages into the distribution directory and they work.
BTW: Offline discussions suggested using sys.exec_prefix or sys.executable
to get the root directory for exe-d packages.
Enjoy, and thanks for the package,
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Thomas Heller
Sent: May 28, 2001 12:46
To: python-list at python.org
Subject: Re: include files with a package
"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
> not depending on the phase of the moon (mostly when you pack Python
> 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
> of those systems, sys.path 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...
More information about the Python-list