I am writing a python package with modules that need to open data files in a ./data/ subdirectory. Right now I have paths to files hard-coded into my classes and functions. I would like to write more reliable code that can access the subdirectory, regardless of where it is installed in the user system.
I tried various methods, but so far I have been out of luck. It appears that most of the "current directory" commands return the python system interpreter directory, not the module directory.
It seems to be a trivial, common problem. But I canβt figure it out. Part of the problem is that my data files are not .py files, so I cannot use import functions, etc.
Any suggestions?
My package directory now looks like this:
/ __init__.py module1.py module2.py data/ data.txt
I am trying to access data.txt from module*.py
Thank!
python packages
Jacob Lyles Apr 22 '09 at 22:17 2009-04-22 22:17
source share