Bernhard said:
This hal always been possible. But it's not reassigning, it's shadowing -
which is a totally different beast. Shadowing builtins is bad style, but
lokal to your context. Which can get nasty of course, if you do the above
on e.g. module level.
But you can't alter the values for True/False globally with this.
Are you sure ? what about the following example ?
Is this also shadowing ?
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.False
I'm not entirely sure what happens there, but that seems to only work in the
interactive prompt.
--------- test.py ------------
print True
if __builtins__.True == 10:
print "I'm reassigned globally"
--------- test.py -------------
Then, in the interpreter do:
droggisch@ganesha:/tmp$ python
Python 2.5.1 (r251:54863, Oct 5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Welcome to rlcompleter2 0.96
10
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test.py", line 5, in <module>
if __builtins__.True == 10:
AttributeError: 'dict' object has no attribute 'True'
Diez