Boolean Values

Fredrik Lundh fredrik at pythonware.com
Fri Apr 6 03:28:49 EDT 2001


D-Man wrote:
> So what is the difference between __builtin__ and __builtins__?

__builtin__ is a module, __builtins__ is a module-level
attribute that usually (but not always) points to that
module.

in CPython, if you ask for a global name that doesn't
exist, Python looks for a __builtins__ module variable.
if it is present, Python looks for the global name in
there.

if __builtins__ doesn't exist, CPython does an "import
__builtin__ as __builtins__", and looks again.

this is a performance optimization, but more importantly,
it allows you to use your own __builtins__ dictionary when
executing foreign code.

> Why does CPython make __builtins__ visible by default and
> Jython doesn't?  Since messing with __builtins__ like this isn't
> really a good idea, it seems that Jython is better for not
> makeing __builtins__ so readily accessible.

since this behaviour is documented in the language reference,
this looks like a bug in jython...

Cheers /F





More information about the Python-list mailing list