finding pathname from within a module?
gmcm at hypernet.com
Fri Sep 14 00:43:00 CEST 2001
Alex Rice wrote:
> 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]
> fileName = string.join(pathEls, os.sep)
> Is there a way to do something like <thecurrentmodule>.__path__?
I'd do it as
BTW, a package (or, the __init__ module that defines a package)
has a __path__ attribute, but it's a list of paths (like sys.path).
More information about the Python-list