Skip to content

Instantly share code, notes, and snippets.

@asmeurer
Created May 23, 2011 20:31
Show Gist options
  • Save asmeurer/987535 to your computer and use it in GitHub Desktop.
Save asmeurer/987535 to your computer and use it in GitHub Desktop.
str(list) calls __repr__ instead of __str__
>>> class MyClass(object):
... def __repr__(self):
... return "repr"
... def __str__(self):
... return "str"
...
>>> repr(MyClass())
'repr'
>>> str(MyClass())
'str'
>>> str([MyClass()])
'[repr]'
>>> repr([MyClass()])
'[repr]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment