None assigment

Steve Holden sholden at holdenweb.com
Thu Feb 8 12:49:13 EST 2001


"Gregoire Welraeds" <greg at perceval.be> wrote in message
news:mailman.981652444.20002.python-list at python.org...
>
[ ... ]
>
> Now that I look at this problem, I'm totally confused about None. Any
> explanaition is welcome. Anyway, I don't understand that one can override
> None. Could you give me at least one single good reason to do that.
>
The built in name None is defined as the value None, which is the only value
of type None.

When you assign to None, you create a new name in your module (or function)
namespace, and bind it to whatever value is assigned.  This new name will be
found before the built in name, since the built in namespace is the last to
be searched. When you delete None you delete it from your module or function
namespace, and the built in name again becomes available.

To quote Mark Lutz' excellent advice from "Learning Python": don't do that!
There is no "single good reason" to do it. This is Python, however, and just
because there's no good reason to do something doesn't mean the implementers
will implement a prohibition. You are free to shoot yourself in the foot if
you want...

There really is no advantage, except perhaps in obfuscated Python contests,
to redefining None. It's just an implementation artefact that you can do it.
Try to forget it's possible and I'm sure you'll feel better!

> Gregoire & Xavier
> From Perceval Development team, (python division :)
>
regards
 Steve




More information about the Python-list mailing list