I'm currently writing a class Book and trying to print one of its attributes but keep getting the following returned instead :: <__main__.Person object at 0x1055f5d68>
.
class Book:
def __init__(self, title):
self.title=title
self.person=None
self.waitlist=[]
def __str__(self):
if self.person!=None:
result = str(self.person)
else:
for person in self.waitlist:
result += str(person)
return result
def borrow(self, person):
if self.person==None:
self.person=person
return self.__str__()
#This is where the message is coming.
#Rather than showing the person, it shows:
# <__main__.Person object at 0x1055f5d6>
else:
self.waitlist.append(person)
return self.__str__()
#I would also like to print the people in the waitlist here, but shows the same result.
I've tried printing the attribute person by using the methods __repr__
and __str__
as well, but it's not working in this case.
Any ideas would be very much appreciated!