reassign to builtin possible !?

Tim Chase python.list at
Thu Jan 3 15:05:07 CET 2008

>> 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 ?
>>>> import __builtin__
>>>> __builtin__.True = False
>>>> __builtin__.True
> False

It doesn't seem to screw things up globally

 >>> import __builtin__
 >>> t = __builtin__.True
 >>> __builtin__.True = False
 >>> __builtin__.False = t
 >>> True
 >>> False
 >>> 1 == 1
 >>> import os
 >>> os.path.isdir('.')
 >>> #if they were globally redefined, this would be False
 >>> #you'd have to actually reference __builtin__.True

My thought would be if you do something as daft as 
redefining/shadowing True and False, you get the headaches that 
ensue.  Fortunately, since Python is explicit, you can trace back 
through the code and see where the inanity occurred. 
Additionally, any scoping rules mean that programmer stupidity 
can't leak too badly outside the scope of the block containing 
the stupidity.

It's the old "DIHWIDT! WDDT!" ("Doctor, it hurts when I do 
this!", "well don't do that!") syndrome.


More information about the Python-list mailing list