Re: Weirdness comparing strings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mr.SpOOn

    Re: Weirdness comparing strings

    On Tue, Sep 30, 2008 at 12:55 PM, Ken Seehart <ken@seehart.co mwrote:
    Instance comparison is not necessarily the same as string comparison.
    Neither __str__ nor __repr__ are implicitly used at all for comparison.
    Ok, I see.
    In fact, by default a pair of instances are not equal unless they are the
    same object. To define comparison to mean something, you need to define
    __cmp__ or __eq__.
    >
    Trivial example of default comparison:
    >
    >>>class C:
    ... pass
    ...
    >>>c = C()
    >>>d = C()
    >>>c==d
    False
    >>>c==c
    True
    Thanks.

    Almar Klein:
    >but this does not implicitly convert self to a string. You'll have to
    >do in explicitly:
    >use "return str(self) == note" instead.
    Yes, this works.
    Thanks.
Working...