Any other Python flaws?

Michael Hudson mwh at python.net
Sun Jun 17 05:26:59 EDT 2001


Michael Chermside <mcherm at destiny.com> writes:

> Martijn writes:
> > Further things possibly wartlike, though this one never bit me, is
> > the possibly to assign to None, definitely a weird idea when you
> > first encounter it.
> 
> Gee... I had no idea this was possible. Surely it's a bad idea... right?

Well, yes.

> Can anyone name any reason why it's good to be able to assign to None?

Less complexity in the interpreter?

> Barring that, I figure there must be a good reason why this isn't a
> syntax error. None not being a reserved word may be part of it... it's
> just another value in __builtins__. This is a clean and elegent design,
> but there's something dangerous about being able to change None.

Only if the other people working on your project are idiots.  Was it
Phil Hunt who just wrote in other post "there's another thing to stop
me doing <foo> - that it's really really stupid".

> Oh well... at least people don't bump into this one much. And if you
> accidently clobber it, you can restore things with:
> 
> def __None():
>     pass
> None = __None()

Sort of.  Usually None resides in __builtins__, as you pointed out,
and going

    None = 1

will put a variable called "None" into either a local or the global
scope, so to revert this you will need to do 

    del None

(this will only really work in global scope, but never mind...).

> I guess I better start putting that at the top of all my modules as
> defensive programming <1.0 wink>.

Err, yeah <+inf wink>.

Cheers,
M.

-- 
  Get out your salt shakers folks, this one's going to take more
  than one grain.                 -- Ator in an Ars Technica news item



More information about the Python-list mailing list