Python: question "import posix"
If I import the os module, I can run the following to locate os.py
>>> import os >>> print os.__file__ /usr/lib/python2.6/os.pyc However, when I import posix , it does not have the __file__ attribute. Is it because it is implemented as part of the python runtime, and not as a standard library?
How can I find out additional information like this using only official python documentation?
You can also use the "check" module to find information (for example, path to the source file, etc.) about the python module. For instance:
import inspect import os inspect.getsourcefile(os) '/usr/local/lib/python2.7/os.py' inspect.getsourcefile(inspect) '/usr/local/lib/python2.7/inspect.py' import sys inspect.getsourcefile(sys) Traceback (most recent call last): [...] raise TypeError('{!r} is a built-in module'.format(object)) TypeError: <module 'sys' (built-in)> is a built-in module