A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

PS9 I wrote this method for ShapeSet. This method will work but gives me this error. Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: __str__ returned non-string (type NoneType) I think it I need to return not print but I don't know how do that. any ideas

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    1 Attachment
  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    This is the code I used to test ps9.py

    1 Attachment
  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yes, just have it return a string. ie. def __str__(self): return str(self.theVariableYouWantToPrint)

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    whoops, __str__ method I mean

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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/

  8. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    something happened between me copying and posting the code. here is what I ment to post. REAL CODE: http://dpaste.com/531160/

  9. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.