[SciPy-user] paths relative to a python package
Tue Apr 1 18:40:23 CDT 2008
On Tue, Apr 1, 2008 at 6:37 PM, Zane Selvans <email@example.com> wrote:
> I know this isn't scipy specific but...
> If you have a data file that's distributed with a python package, how do
> you refer to it relative to the location that the package ultimately
> gets installed? Is there a package_root variable or something?
> e.g. in my package directory let's say I have:
> and within datadir:
> How do I, within MyModule.py tell the program to open one of the data files?
dirname = os.path.dirname(os.path.abspath(__file__))
datadir = os.path.join(dirname, 'datadir')
f = open(os.path.join(datadir, 'data1.dat'))
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the SciPy-user