By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,551 Members | 1,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,551 IT Pros & Developers. It's quick & easy.

module file

P: n/a
I am willing to retrieve the file an imported module came from;
module.__file__, or inspect.getfile(module) only gives me the
relative file name. How do I determine the path?
Its obviously possible from python: ipython displays the information
(interactively: *module?*).
Python 2.4 on Suse 9.3 (clueless, I guess)
Jan 12 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Imbaud Pierre <pi***********@laposte.netwrites:
I am willing to retrieve the file an imported module came from;
module.__file__, or inspect.getfile(module) only gives me the
relative file name. How do I determine the path?
>>import os
os.path.abspath(module.__file__)
--
HTH,
Rob
Jan 12 '07 #2

P: n/a
Imbaud Pierre a écrit :
I am willing to retrieve the file an imported module came from;
module.__file__, or inspect.getfile(module) only gives me the
relative file name. How do I determine the path?
Its obviously possible from python: ipython displays the information
(interactively: *module?*).
Python 2.4 on Suse 9.3 (clueless, I guess)
Apologies: module.__file__, or inspect.getfile(module) only *gave* me
the relative file name, because the module was found in the current
directory! Changing the current directory, and having the module be
found thru the path, changed the returned path to an absolute
directory!
Hence the simplest form at hand was used. Thank you, python!

Jan 13 '07 #3

P: n/a
"Rob Wolfe" <rw@smsnet.plescribió en el mensaje
news:87************@smsnet.pl...
Imbaud Pierre <pi***********@laposte.netwrites:
>I am willing to retrieve the file an imported module came from;
module.__file__, or inspect.getfile(module) only gives me the
relative file name. How do I determine the path?
>>>import os
os.path.abspath(module.__file__)
Note that this works only if the current dir has not changed. So it's a good
idea to store the absolute path as early as possible (before the program
have a chance to change the current dir)

--
Gabriel Genellina

Jan 13 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.