How to retrieve Python module path?

PythonServer Side ProgrammingProgramming

For a pure python module you can find the location of the source files by looking at the module.__file__. For example,

 >>> import mymodule
>>> mymodule.__file__
C:/Users/Ayush/mymodule.py 

 Many built-in modules, however,are written in C, and therefore module.__file__ points to a .so file (there is no module.__file__ on Windows), and therefore, you can't see the source.

 Running "python -v"from the command line tells you what is being imported and from where. This is useful if you want to know the location of built-in modules.

raja
Published on 19-Dec-2017 13:55:52
Advertisements