Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > module file

Reply
Thread Tools

module file

 
 
Imbaud Pierre
Guest
Posts: n/a
 
      01-12-2007
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)
 
Reply With Quote
 
 
 
 
Rob Wolfe
Guest
Posts: n/a
 
      01-12-2007
Imbaud Pierre <(E-Mail Removed)> writes:

> 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
 
Reply With Quote
 
 
 
 
Imbaud Pierre
Guest
Posts: n/a
 
      01-13-2007
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!

 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      01-13-2007
"Rob Wolfe" <(E-Mail Removed)> escribió en el mensaje
news:(E-Mail Removed)...
> Imbaud Pierre <(E-Mail Removed)> writes:
>
>> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: module docstring, documentation,anything? please note is the module type/object NOT some module Maric Michaud Python 0 06-24-2006 12:42 PM
Find out the file name of a module from inside the module? Andreas Neudecker Python 4 08-09-2004 03:49 PM
Re: Http Module Problem: not all requests hit my module why? Jiong Feng ASP .Net 2 11-29-2003 05:14 PM
Python-2.3b1 bugs on Windows2000 with: the new csv module, stringreplace, and the re module Daniel Ortmann Python 4 07-02-2003 03:23 PM



Advertisments