[Tutor] How to write the __str__ function
shulatif at gmail.com
Sun May 14 14:51:46 EDT 2017
Not exactly sure what you're trying to do here but maybe you want to join those two things instead? Because of course it's a tuple the way you have it now.
Sent from my iTypo (with enhanced embarrassing auto-correcting)
> On May 14, 2017, at 11:03 AM, Sydney Shall <s.shall at virginmedia.com> wrote:
> I need some advice that I have been embarrased to ask for, because I think that my error is so elementary.
> I have written, as advised by the tutors, a complex program in a topic that interests me. The program works well and the tests are OK.
> Now I want to add a __str__ function, which I thought would be straightforward. But I cannot get it right.
> The code that I have so far is as folows:
> def __str__(self):
> " Output from __str__ of POCWP. "
> "\n After the first turnover, during the "
> "'Population Of Capitals Init' cycle,"
> "\n the productivities were raised from 1.0 "
> "\n to a specific Unit Constant Capital (UCC) "
> "for each specific capital: "
> "\n The input value for the mean of UCC "
> "was %7.5f" % (self.ucc),
> "\n The fractional sigma (FractionalSTD)"
> " of UCC that was input was %7.5f " % (self.fractsigma_ucc))
> The error message is:
> TypeError: __str__ returned non-string (type tuple)
> When I omit either or both of the objects; self.ucc or self.fractsigma_ucc, the code works fine.
> So, I guess my code has an error. But I cannot detect the error.
> Guidance would be much appreciated.
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
More information about the Tutor