Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Python module filename

I got module name which contains declaration of os.path.isfile. Jedi lib gave me genericpath (without file path). Now i want to get full filename of PY file with this genericpath module. E.g. "C:\Py27\Lib\genericpath.py". How can I do it? Jedi cannot do it?

like image 840
Prog1020 Avatar asked Aug 30 '13 18:08

Prog1020


1 Answers

Like this:

>>> import re
>>> re.__file__
'/usr/lib/python2.7/re.pyc'

For packages that are not part of the Python core, you can also use __path__:

>>> import requests
>>> requests.__file__
'/usr/local/lib/python2.7/dist-packages/requests-1.1.0-py2.7.egg/requests/__init__.pyc'
>>> requests.__path__
['/usr/local/lib/python2.7/dist-packages/requests-1.1.0-py2.7.egg/requests']
like image 108
Burhan Khalid Avatar answered Oct 05 '22 19:10

Burhan Khalid