At 09:41 PM 1/25/2006 -0500, Stefan Seefeld wrote:
>Hi there,
>
>I'm working on a python application which uses a number of data files.
>In order to figure out the path to the data files I used to use some
>hacks, such as letting the application file inject a 'prefix' variable
>into the root module (package) for other modules to use.
The simplest way to do this is to use the package_data option, see:
http://docs.python.org/dist/node11.html
And then use the __file__ variable of the containing package module to
determine the data file locations at runtime. So, if a data file 'bar.dat'
is inside your 'foo' package, you can use:
import foo
pkg_dir = os.path.dirname(foo.__file__)
filename = os.path.join(pkg_dir, 'bar.dat')
This will work on any platform, with any installation method, bdist_wininst
or otherwise.
The package_data option was introduced in Python 2.4; if you are using
Python 2.3 you can use setuptools instead. There are also hacks out there
for even earlier versions of Python that accomplish the same thing, but
they're more difficult to implement. Still, even those are far easier than
what you're contemplating doing with bdist_wininst.
_______________________________________________
Distutils-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/distutils-sig