None assigment
Tim Peters
tim_one at email.msn.com
Sun Feb 11 01:22:10 EST 2001
[Peter Hansen]
> ...
> Why, I wonder, do some people think that just because
> something "shouldn't" happen, it must therefore
> never be allowed to happen? If "we all agree that
[Clarence Gardner]
> I think, if there is a reason, it is probably that they want
> the language to prevent the programmer from *accidentally*
> doing bad things that happen to be possible. But nobody
> types
> None = 3
> by accident. And since, unlike some other languages, that
> is the only way to do it, there is no purpose in prohibiting it.
Actually, some people do write stuff like:
for x, y, None in list_of_threetuples:
print f(x, y)
when they don't care about the third tuple elements. I know this because I
was one of them <wink>. Got away with it for months, and just *assumed* the
language supported "None" as a "don't care" assignment target. This is easy
to believe if you're coming from, say, Perl.
There's a bit of Deep Magic that makes this illusion hard to shake if you
fall under it:
>>> def f():
... None = 42
>>> None = 66
>>> print f()
None
>>> type(f())
<type 'None'>
>>>
That is, rebinding None has no effect on that functions that fall off the
end still return "the old" value of None; the "intended" value of None is
hardcoded into the fall-off-the-end function return sequence.
In that respect, None is unique among non-keyword names, and for that reason
alone it should be a keyword instead of a global. I expect that will happen
someday, too. But it's a race between that and hell freezing over <wink>.
hard-to-get-excited-about-it-even-when-i-was-young-ly y'rs - tim
More information about the Python-list
mailing list