[Python-Dev] Re: [Pythonmac-SIG] __builtins__ a dictionary or a module?

Tim Peters tim.one@home.com
Fri, 6 Apr 2001 05:06:02 -0400


Please read this the right way <wink>:  it's none of your business whether
__builtins__ is a module or a dictionary.  __builtin__ (no trailing 's') is a
module, but __builtins__ is a module attribute that can be either a module or
a dictionary, depending on what Python feels like doing.  Which it decides to
do is an internal implementation detail of no material consequence to correct
Python code.

More info on why the two choices exist-- and documentation that __builtins__
*can* be either a dict or a module --can be found in the "Code blocks,
execution frames, and namespaces" setion of the Language Reference manual.

BTW, the primary reason __builtins__ is a module when bringing up a native
command-line shell (I know that doesn't apply on a Mac Classic) is simply so
that if a curious user types

    >>> __builtins__

they get

    <module '__builtin__' (built-in)>

instead of a giant dict dump.  The primary use for making __builtins__ a dict
is to support restricted execution modes.