I was curious about the __builtin__ module and how it’s used, but I can’t find it in Python3! Why was it moved?
Python 2.7
>>> import __builtin__
>>>
Python 3.2
>>> import __builtin__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named __builtin__
>>>
The
__builtin__module was renamed tobuiltinsin Python3.This change solves 2 sources of confusion for the average Python developer.
'__builtins__'or'__builtin__'that is in the global namespace?Darn s!
__builtin__a special method name or a module? I can’ttell.
This confusion mainly arises because of the violation of pep8 convention. Also, the lack of pluralization on the module hinders communication as well. Both of these are greatly illustrated by the lengths Guido must go to explain the following from http://mail.python.org/pipermail/python-ideas/2009-March/003821.html:
For example,
Python2.7
Python3.2
Related resources:
Other name changes – http://docs.pythonsprints.com/python3_porting/py-porting.html#name-changes
For a succinct explanation of how
__builtins__is used in name resolution – __builtin__ module in Python