[Python-3000] A few small py3k wishes
Greg Ewing
greg.ewing at canterbury.ac.nz
Mon Apr 3 03:38:25 CEST 2006
Talin wrote:
> When I print __file__ from my __main__ module, I get the name of the
> file only, no path.
It seems to be whatever pathname you passed to the
interpreter on the command line. If that's a relative
path, it will end up in the __file__ of __main__ as
a relative path. But it will still work as long as
the working directory of the process hasn't changed.
So either leave the cwd alone, or expand the __file__
to a full path before changing it.
> Note that the impored module has a "__path__" attribute, while the
> main module does not.
__path__ is something different -- it's a list of
directories to search when importing submodules
of a package. Non-package modules don't have a
__path__.
> You'd like to be able to have a single, uniform
> way to locate your module's data, regardless if you are __main__
> or not.
There already is. I do this frequently and it works
fine, as long as you keep the cwd issue in mind.
--
Greg
More information about the Python-3000
mailing list