1.

How Can I Find The Filesystem Locations For My Project?

Answer»

Use the pkg_resources module which comes with setuptools

For example, You can get the full path to the templates directory inside the wiki20 package by:

from pkg_resources import resource_filename
resource_filename('wiki20', 'templates')

You can then easily move up an down in the filesystem by using the functions form the standard os.path module.

Please bear in mind, when you have installed your application as an EGG, there is no “project directory” per se, in fact, the files of your application MAY not even RESIDE directly in the filesystem but in a ZIP archive. You can build an egg that contains additiional data file ALONGSIDE your application’s package directory. See the setuptools documentation for more information.

Use the pkg_resources module which comes with setuptools

For example, You can get the full path to the templates directory inside the wiki20 package by:

from pkg_resources import resource_filename
resource_filename('wiki20', 'templates')

You can then easily move up an down in the filesystem by using the functions form the standard os.path module.

Please bear in mind, when you have installed your application as an egg, there is no “project directory” per se, in fact, the files of your application may not even reside directly in the filesystem but in a ZIP archive. You can build an egg that contains additiional data file alongside your application’s package directory. See the setuptools documentation for more information.



Discussion

No Comment Found