Developing a Package with Sub Packages

Josh English joshua.r.english at gmail.com
Sun Feb 17 19:34:27 EST 2008


I have created a group of scripts to manage an XML-based database. I'd
like to make it into a proper package that will let me keep track of
the code. I have a lot of files that are similar in name and they just
get crowded in one folder.

Here's a sample of the file structure:

IMS/
IMS/__init__.py
IMS/Config.py
IMS/imsdefaults.cfg
IMS/local.txt
IMS/Data/
IMS/Data/stories.xml
IMS/Story/
IMS/Story/__init__.py
IMS/Story/StoryCreator.py

When the IMS/__init__.py file is loaded, it creates the IMS/Data/
folder and if there are no xml files, it creates them and fills them
in with some default values.
The IMS/Config.py has a subclass of the ConfigParser, and reads the
imsdefaults.cfg and local.txt files.
When I run StoryCreator, buried in it's own package (that imports IMS)
the data folder is created inside the Story folder, and I get an error
message stating the ConfigParser object could not find the
imsdefaults.cfg file.
Here's what I think is happening: IMS/__init__.py uses os.getcwd() to
establish the path to the data folder and the files inside of it. When
I run StoryCreator, os.getcwd() returns the story folder.
If I'm right, how can I get the IMS/__init__.py module to use relative
paths to its own module, and not the current working directory the os
module provides?
This could also solve the problem with Config.py, I think.

Thanks

Josh English
http://joshenglish.livejournal.com



More information about the Python-list mailing list