The __builtin__ module has been renamed builtins in Python3.
This change addresses two sources of confusion for the average Python developer.
- Is it
'__builtins__' or '__builtin__' in the global namespace? Darn! __builtin__ a special method name or module? I can not tell.
This confusion is mainly due to a violation of pep8 . In addition, the lack of pluralization on the module also interferes with communication. Both of these are largely illustrated by Guido lengths, which should explain the following from http://mail.python.org/pipermail/python-ideas/2009-March/003821.html :
[CPython] looks at globals containing a special magic notation __builtins__ (with the character 's'), which is a dict where built-in functions are viewed. When this dict is the same object as the default inline dict (which is __builtin__.__dict__ , where __builtin__ - without 's' is the module that defines the built-in functions), it gives supervisor privileges; ...
For example,
python2.7
>>> import __builtin__ >>> vars(globals()['__builtins__']) is vars(__builtin__) True >>>
Python3.2
>>> import builtins >>> vars(globals()['__builtins__']) is vars(builtins) True >>>
Related Resources :
Other name changes - http://docs.pythonsprints.com/python3_porting/py-porting.html#name-changes
For a brief explanation of how __builtins__ used for name resolution - __ built-in module in Python
Derek Litz Jan 28 '12 at 19:09 2012-01-28 19:09
source share