Result of ``a is b''

Asun Friere afriere at yahoo.co.uk
Wed Mar 17 20:50:01 EST 2004


axelboldt at yahoo.com (Axel Boldt) wrote in message news:<40200384.0403170530.57b6bba4 at posting.google.com>...
>                                       Why would anybody ever want to
> know whether two strings or tupels are internally stored at the same
> location, other than to deduce details of the Python implementation?

Most obviously to tell whether they are the same object or not.  
While this is not an issue with simple strings, have you considered
what effect your suggestions would have on classes inheriting from
str?

For instance I might have a class 'Name', in a names database, which
is a specialised string.  In this case '==' function looks to the
contents of the strings being compared, while 'is' tells me whether
these two strings are the same object.  Thus "if name0 == name1 and
not name0 is name1" will tell me that I am dealing with a duplicate
record.  Now this might not be the best way to find duplicates in
practice, it's simply first thing that popped into my head in response
to your question.  But I don't think I'm able to anticipate all the
ways in which all programmers might want to apply the distinction
between equivalence and identity in their programs?  Are you?

By the way you /have/ written a program in which a large (or at least
important) part of the logic was contained in the __eq__ method to the
class you created, haven't you?  I mean you wouldn't really be in a
situation to advocate a redefinition of the identity/equivalence
relationship unless you had, would you?



More information about the Python-list mailing list