module file

Discussion in 'Python' started by Imbaud Pierre, Jan 12, 2007.

  1. 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)
     
    Imbaud Pierre, Jan 12, 2007
    #1
    1. Advertising

  2. Imbaud Pierre

    Rob Wolfe Guest

    Imbaud Pierre <> 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
     
    Rob Wolfe, Jan 12, 2007
    #2
    1. Advertising

  3. closed: module file

    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!
     
    Imbaud Pierre, Jan 13, 2007
    #3
  4. "Rob Wolfe" <> escribió en el mensaje
    news:...
    > Imbaud Pierre <> 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
     
    Gabriel Genellina, Jan 13, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiong Feng
    Replies:
    2
    Views:
    558
    Wade A. Hilmo [MS]
    Nov 29, 2003
  2. Daniel Ortmann
    Replies:
    4
    Views:
    609
    Skip Montanaro
    Jul 2, 2003
  3. Marcus Schneider
    Replies:
    2
    Views:
    350
    Michael Peuser
    Aug 16, 2003
  4. Andreas Neudecker
    Replies:
    4
    Views:
    320
    Andreas Neudecker
    Aug 9, 2004
  5. Maric Michaud
    Replies:
    0
    Views:
    7,222
    Maric Michaud
    Jun 24, 2006
Loading...

Share This Page