470,849 Members | 686 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

module file

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
3 1611
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
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
"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.

Similar topics

2 posts views Thread by Marc Shapiro | last post: by
1 post views Thread by Peter Åstrand | last post: by
2 posts views Thread by Reid Priedhorsky | last post: by
2 posts views Thread by Kenneth McDonald | last post: by
12 posts views Thread by Steven Bethard | last post: by
5 posts views Thread by sophie_newbie | last post: by
1 post views Thread by alain MONTMORY | last post: by
4 posts views Thread by Nikhil | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.