Two conflicting values ​​built into python 3 (python 3.1, python 3k, python3000)

I just posted below a request to comp.lang.python, but I feel that such a question has some right-handed path here in Stack Overflow, so repeat it. essence: why do "built-in" have two different interpretations in Python 3?

I am happy to accept any comments that this sentence, drawn from http://celabs.com/python-3.1/reference/executionmodel.html , is implied, or why the gods decided that this was the way to go. I anticipate that this guy named Kay Shlyur will talk about it, or maybe even the BDFL will want to pronounce the __builtins__ right path to his changes, followers and supporters:

  The built-in namespace associated with the execution of
  a code block is actually found by looking up the name
  __builtins__ in its global namespace; this should be a
  dictionary or a module (in the latter case the module's
  dictionary is used). By default, when in the __main__
  module, __builtins__ is the built-in module builtins;
  when in any other module, __builtins__ is an alias for
  the dictionary of the builtins module itself.
  __builtins__ can be set to a user-created dictionary to
  create a weak form of restricted execution.

this was the case when there were at least two different terms, "Built-in (singular)" and "built-in (plural)), some of which existed both in the module and in the form of dict (" just guessing? " ). Now only exists builtins, therefore, fortunately, the ambivalence between the singular and the plural has passed - a good deliverance.

but why does it __builtins__change its value depending on whether it is the scope of the script (i.e. the module whose name was present during the call python foobar.py), or is it the volume of the additional module (imported or executed, directly or indirectly, on foobar.py)? I cannot understand the reasoning behind this and find it very confusing.

: ? -i , , ( prefix) python, exec( compile( get ( locator ), locator, 'exec' ), R ), R . , - ... , .

+3
1

getattr(__builtins__, '__dict__', __builtins__) dict, , " ", __builtins__ ( __dict__, getattr , dict __builtins__) ( getattr ). . , Python , , , ( ) (). , , Python 3, , - : - (.

+1

Source: https://habr.com/ru/post/1730785/


All Articles