Library and real path name
fredrik at pythonware.com
Tue Aug 23 12:25:23 CEST 2005
Michele Petrazzo wrote:
> I want to redistribute the library that I create.
> I create a project, its setup.py that when launched copy all files into
> the "site-packages/library" directory. And here it's all ok.
> When I call my library with:
> import library
> I want that my library know where are its real path
you can use the __file__ or __path__ variables to determine this.
# get this module's directory
prefix = os.path.dirname(__file__)
or, inside a package __init__.py file:
# get package's main directory
prefix = __path__
More information about the Python-list