AFAIK,Pythonbuiltins
指的是__builtins__
中包含的那些异常和函数:
>>> import builtins # import __builtin__ in Python 2
>>> dir(builtins) # dir(__builtin__) for Python 2
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException',
'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning',
...many more...
'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed',
'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum',
'super', 'tuple', 'type', 'vars', 'zip']
但是看看下面的代码(Python2和3都给出了相同的结果):
^{pr2}$在最后一行,模块math
被称为built-in
。为什么?模块math
和其他模块如threading
有什么区别?在
从文档(
./Doc/library/stdtypes.rst
)中:相关代码位于模块对象的
repr()
函数中:在您的例子中,}。在
math
模块在构建库时包含在主Python库本身(libpython2.7.{so,dll,dylib}
)中。这是可能的,因为模块是用C编写的,而不是用纯Python编写的。其他类似的模块包括sys
和{Python docs有这样的话:
math
模块是用C语言编写的,它被构建到解释器中,而threading
是用Python编写的,并在源代码中导入。在相关问题 更多 >
编程相关推荐