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
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
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
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"
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')