0

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!

Sarina
  • 77
  • 2
  • In order for us to help you figure out why your `__str__` and/or `__repr__` methods are not working, you'll need to actually show those in your code. We can't debug what we can't see! (Though I guess it's `Person.__str__` you need to show.) – Blckknght Jun 09 '19 at 02:17
  • So I think your issue has to do with the thing I edited in to my last comment (so you might have missed it). You need to write a `__str__` method in the `Person` class, not (or maybe not only) in the `Book` class. – Blckknght Jun 09 '19 at 02:44

0 Answers0