Weirdness comparing strings

M

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')
n2 = Note('B')
print n
print n2
print n.has_the_same_name(n2)

I'd expect to get "True", because their string representation is
actually the same, instead the output is:

B
B
False

I think I'm missing something stupid. Where am I wrong?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top