path to python file given module

Steve Holden steve at holdenweb.com
Sun Jan 9 20:09:58 EST 2005


Gene wrote:

> that method doesn't seem to work as well on UNIX:
> 
> wla apocalypse[94] ~/filegen > ls
> filegen.py              OLDwla_csv2objects.py   wlaclasses.py
> filegen.pyc             templates/              wlaclasses.pyc
> gen_all_from_csv.py     test.py*
> wla apocalypse[95] ~/filegen > python
> ....

Use the module's __file__ attribute:

  >>> import Image
  >>> Image.__file__
'/usr/lib/python2.4/site-packages/PIL/Image.pyc'
  >>>

While this doesn't give you the source, it goves you enough to make a 
fair guess about where the source is likely to be, and a littel further 
manipulation should be able to confirm that.

regards
  Steve
-- 
Steve Holden               http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC      +1 703 861 4237  +1 800 494 3119



More information about the Python-list mailing list