Tuple assignment and generators?

John J. Lee jjl at pobox.com
Fri May 5 16:29:13 EDT 2006


"vdrab" <stijndesaeger at gmail.com> writes:
[...]
> In fact, I think my code contains things like "if len(arg) is 0:" and
> so on,

So you made a mistake.  It's OK, you can forgive yourself, nobody will
notice <wink>


> and I feel I should be able to do so given the way python treats
> (claims to treat?) constant objects, even if I don't care whether the
> values actually represent the same object.

(By "constant" I assume you mean immutable.)

I'm afraid it sounds like your assumptions about "the way python
treats (claims to treat?)  constant objects" were "made up out of your
own head" as Tim Peters once put it :-) Python does not make such
guarantees about the identity of separately-constructed immutable
objects, and that's good, careful design, in my book (you might be
able to see why if you think about what "is" *means* and what it would
take to ensure it *always* remains true for e.g. x is 10E9, where x ==
10E9 but is assigned elsewhere, and at another time during program
execution).

OTOH, it's good practice in Python to use "is" to compare values with
the immutable singleton None ("if x is None").  No harm comes of that,
simply because there is only one None object.


John




More information about the Python-list mailing list