paths in modules (solved)

Brandon Mintern mintern at cse.ohio-state.edu
Thu Feb 22 11:40:43 EST 2007


On Thu, 22 Feb 2007 08:28:50 -0800, Paul Boddie wrote:
> And you really want to refer to utility_dir relative to some_wrapper.
> What you can try is to split the __file__ attribute of some_wrapper -
> it's a standard attribute on imported modules - in order to refer to
> the module's parent directory (which should correspond to
> wrapper_dir):
> 
> parent_dir, filename = os.path.split(__file__)
> 
> Then you can join the parent directory to the path of the command:
> 
> cmd = os.path.join(parent_dir, "utility_dir", "some_external_utility")
> 
> The __file__ attribute of modules is documented here:
> 
> http://docs.python.org/ref/ty__file__ is the pathname of the file from
> which the module was loadedpes.html#l2h-109
> 
> Paul

Thanks a lot.  I was hoping for a solution like that, and it worked
perfectly for me (admittedly, in my trivial test files, but I'm sure that
the solution will extend to my actual use case).

Also, I had actually read that documentation you pointed me to, but the
language, "__file__ is the pathname of the file from which the module was
loaded" had me thinking that it was the pathname of the file doing the
loading, rather than the file being loaded.  I guess I should have
actually tried it out.

Anyways, thanks for the quick response and for the clarification.



More information about the Python-list mailing list