> I am trying to use a __str__ method to display the values of attribute mood > = self.hunger + self. boredom. > When I try to execute I get this error: > > Traceback (most recent call last): > File "C:/Users/Vincent/Documents/Programming Tutorials/Python Programming > for the Absolute Beginner - Project > Files/source/chapter08/critter_caretaker_vpb3.py", line 105, in <module> > main() > File "C:/Users/Vincent/Documents/Programming Tutorials/Python Programming > for the Absolute Beginner - Project > Files/source/chapter08/critter_caretaker_vpb3.py", line 99, in main > print(crit) > TypeError: __str__ returned non-string (type int)
> def __str__(self): > mood = self.boredom + self.hunger > return mood I believe the problem is that your __str__ method returns an int rather than a string. Try: mood = str(self.boredom + self.hunger) _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
