If I import os module, I can run the following to infer the location of 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 a part of the python runtime, not as a standard library?
How can I find out more information lik开发者_如何学运维e this using solely the python official documentation?
It's a C module. It can be either built into the Python binary or compiled as a shared library. In your case it is compiled in
The official docs say not to import it directly, and you should use the functionality provided via os
Run python interactively.
>>> import posix
>>> help(posix)
There's a lot of good stuff there.
FILE
    (built-in)
You can also use the 'inspect' module to find information (say source file path etc) about a python module. For example:
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
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论