if the module isn't built-in, you can do this:
import your_module
print(your_module.__file__)
test:
>>> import os
>>> print(os.__file__)
L:\Python34\lib\os.py
if module is built-in, you get an error:
>>> import sys
>>> print(sys.__file__)
Traceback (most recent call last):
File "<string>", line 301, in runcode
File "<interactive input>", line 1, in <module>
AttributeError: 'module' object has no attribute '__file__'
>>>
(check if module has the __file__
attribute using hasattr
is also an option to avoid errors; if hasattr(module_name, '__file__'):
)
also: by directly printing the module:
>>> print(os)
<module 'os' from 'L:\\Python34\\lib\\os.py'>