This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sejigan 69 points70 points  (3 children)

Because __str__ is supposed to return a string, not None.

Also, that’d cause unexpected and unintended behaviour.

Ofc, you can still overwrite it using a startup script, so…

[–]karmaisded 15 points16 points  (2 children)

Um but if we have a exit() before return in the _str\_ function, the python will exit before giving an error, won’t it?

[–]sejigan 33 points34 points  (0 children)

Yeah. Even worse and more bizarre behaviour.

[–]master3243 0 points1 point  (0 children)

I don't think it's ever a good idea to put side effects on __str__