whassup? builtins? python3000? Naah can't be right?

_wolf wolfgang.lipp at gmail.com
Sun Jan 31 22:17:04 CET 2010

dear pythoneers,

i would be very gladly accept any commentaries about what this
sentence, gleaned from http://celabs.com/python-3.1/reference/executionmodel.html,
is meant to mean, or why gods have decided this is the way to go. i
anticipate this guy named Kay Schluehr will have a say on that, or
maybe even the BDFL will care to pronounce ``__builtins__`` the
correct way to his fallovers, followers, and fellownerds::

  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.

it used to be the case that there were at least two distinct terms,
‘builtin’ (in the singular) and ‘builtins’ (in the plural), some of
which existed both in module and in dict form (?just guessing?). now
there is only ‘builtins’, so fortunately the ambivalence between
singular and plural has gone—good riddance.

but why does ``__builtins__`` change its meaning depending on whether
this is the scope of the ‘script’ (i.e. the module whose name was
present, when calling ``python foobar.py``) or whether this is the
scope of a secondary module (imported or executed, directly or
indirectly, by ``foobar.py``)? i cannot understand the reasoning
behind this and find it highly confusing.

rationale: why do i care?—i want to be able to ‘export names to the
global namespace that were not marked private (by an underscore
prefix) in a python module that i execute via ``exec( compile( get
( locator ), locator, 'exec' ), R )`` where ``R`` is supposed to going
to hold the private names of said module’. it *is* a little arcane but
the basic exercise is to by-pass python’s import system and get similr
results... it is all about injecting names into the all-global and the
module-global namespaces.

still i get trapped by the above wordings in tzhe docs, and i have a
weird case of a vanishing names, so maybe some people will care to
share their thoughts.

love & ~flow


More information about the Python-list mailing list