Friday, 23 August 2013

Loading data via a module and a text file in another directory

Loading data via a module and a text file in another directory

I have directory structure:
main/
__init__.py
foo/
__init__.py
names.py
names.pickle
bar/
__init__.py
my_module.py
names.py has code that works with names.pickle, including loading the
pickled data.
However, in my_module.py if I do:
from main.foo import names
Then I run my_module.py from main/bar, Python complains to me that it
can't find names.pickle, presumably because it looks inside main/bar/, not
main/foo/.
What is the recommended way to resolve this? Is it to temporarily change
os.curdir?

No comments:

Post a Comment