Type of __builtins__ changes from module import to execution?
adam at hupp.org
Fri Jun 22 05:49:38 CEST 2007
I've noticed some unexpected behavior with __builtins__ during module
import. It seems that during module import __builtins__ is a dict
but at all other times it is a module.
For example, if the file testmod.py has these contents:
print "has str attr", hasattr(__builtins__, 'str')
The output differs depending on how it is run:
$ python ~/testmod.py
has str True
$ python -c 'import testmod'
has str False
Anyone know if there a reason for this behavior? Is it a bug? I've
seen this in 2.4 and 3.0.
More information about the Python-list