finding pathname from within a module?

Alex Rice alex at integretechpub.com
Thu Sep 13 13:05:42 EDT 2001


I know there must be a more pythonic way than this. My module needs to
be able to read a datafile in the same directory the module is defined.
What I came up with for creating the filename is this:

pathEls = string.split(__file__, os.sep)[:-1]
pathEls.append('my.data')
fileName = string.join(pathEls, os.sep)

Is there a way to do something like <thecurrentmodule>.__path__?

Alex



More information about the Python-list mailing list