reassign to builtin possible !?

Diez B. Roggisch deets at nospam.web.de
Thu Jan 3 08:07:27 EST 2008


Bernhard Merkle wrote:

> Hi there,
> 
> I am reading Learning Python 3e from Mark Lutz and just found out that
> reassigning to builtins is possible.
> What is the reason, why Python allows this ? IMO this is very risky
> and can lead to hard to find errors.
> (see also Learning Python 3e, Chapter 16, Page 315)
> 
>>>> True
> True
>>>> False
> False
>>>> True = 1
>>>> True
> 1
>>>> True = 0
>>>> True
> 0

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.

Diez



More information about the Python-list mailing list