Re: Weirdness comparing strings

2008-09-30 Thread Scott David Daniels
Mr.SpOOn wrote: Hi, I have this piece of code: class Note(): Unless you _need_ old-style, use new style. ... def has_the_same_name(self, note): return self == note Define equality (__eq__) if you want to compare for equality. def __str__(self): return self

Re: Weirdness comparing strings

2008-09-30 Thread Mr . SpOOn
On Tue, Sep 30, 2008 at 12:55 PM, Ken Seehart <[EMAIL PROTECTED]> wrote: > 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 the

Re: Weirdness comparing strings

2008-09-30 Thread Ken Seehart
Instance comparison is not necessarily the same as string comparison. Neither __str__ nor __repr__ are implicitly used at all for comparison. 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 __cm

Re: Weirdness comparing strings

2008-09-30 Thread Almar Klein
Hi, Better post complete code. I don't see where self.note_name is defined, and what are these accidentals? you write: def has_the_same_name(self, note): return self == note but this does not implicitly convert self to a string. You'll have to do in explicitly: use "return str(self) == note"

Weirdness comparing strings

2008-09-30 Thread Mr . SpOOn
Hi, I have this piece of code: class Note(): ... ... def has_the_same_name(self, note): return self == note def __str__(self): return self.note_name + accidentals[self.accidentals] __repr__ = __str__ if __name__ == '__main__': n = Note('B')