PS9 I wrote this method for ShapeSet. This method will work but gives me this error.
Traceback (most recent call last):
File "
This is the code I used to test ps9.py
yes, just have it return a string. ie. def __str__(self): return str(self.theVariableYouWantToPrint)
forgot to say, when you give the print command you are telling Python to go find and execute the __str__ variable for whatever object you called.
whoops, __str__ method I mean
ok that makes sense but I thought that I wanted to write a __str__ which returns the string representation for the set, which consists of the string representation of each shape categorized by type. To do that I would need to loop and print. If I did 'return' that would end the loop before I all the shapes have been printed, right? It is possible I don't understand the question fully. Does the question really want me to set up a str so that when I could use __iter__ to print? However, If I set it up like this It would not print all the shape categorized by type. Or does categorized by type really just mean that I need to set __str__ up in a way that calls the respected class definition up the chain.
well this is what I came up with, I don't know if this is the best way to do it but it does work. code: http://dpaste.com/531158/ test: http://dpaste.com/531157/
something happened between me copying and posting the code. here is what I ment to post. REAL CODE: http://dpaste.com/531160/
Join our real-time social learning platform and learn together with your friends!