finding pathname from within a module?

Alex Rice alex at
Thu Sep 13 21:24:53 CEST 2001

On Thu, 13 Sep 2001 brueckd at wrote:

> > Is there a way to do something like <thecurrentmodule>.__path__?
> import imp, os
> path = imp.find_module('yourmodule')[1]
> filename = os.path.join(os.path.split(path)[0], 'datafilename')

Thanks- I didn't know about the imp module. This is what I'm using now:
I've verified this works within the module being defined- which is exactly
what I needed.

fileName = os.path.join(imp.find_module('mymodule')[1],'myfilename')


More information about the Python-list mailing list