__builtins__ confusion...
Tim Peters
tim.one at comcast.net
Sat May 11 14:22:31 EDT 2002
[Allan Crooks]
> ...
> This seems such a strange thing to me, can anyone explain why the
> value of __builtins__ differs?
Yes, but I'm not going to <wink>. The name of the module holding the
builtins is __builtin__ (no 's'!). __builtins__ is an internal
implementation detail, and user code should never muck with it. From the
Ref Man:
When a global name is not found in the global namespace, it is
searched in the built-in namespace (which is actually the global
namespace of the module __builtin__). 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 its dictionary is
used). Normally, the __builtins__ namespace is the dictionary of the
built-in module __builtin__ (note: no `s'); if it isn't, restricted
execution mode is in effect.
The real reason __builtins__ is bound to the __builtin__ module instead of
to __builtin__'s dict in interactive mode is so that the curious don't get
flooded with output when doing
>>> vars()
at the prompt.
More information about the Python-list
mailing list