inconsistent value from __builtins__
Alex Martelli
aleaxit at yahoo.com
Fri Oct 1 18:45:34 EDT 2004
Michael Hohn <hohn at hooknose.lbl.gov> wrote:
...
> >>> print type(builtin_check.get_global_binding('__builtins__'))
> <type 'dict'>
> >>> print type(__builtins__)
> <type 'module'>
...
> Is this difference in return value intentional?
Well, it's _documented_ that '__builtins__' can be either a dictionary
or a module, and it's been that way for a long time. Whether it's
intentional (or sensible), I don't know. In any case, the idea is that
if you need to access the built-in namespace directly, you should start
with "import __builtin__" (note, no 's') which will definitely give you
a module. Yeah, it _is_ somewhat confusing:-(.
Alex
More information about the Python-list
mailing list