Last active
August 29, 2015 14:13
-
-
Save chejazi/c37a8c00485750fadf28 to your computer and use it in GitHub Desktop.
Test the priority of __str__ vs __repr__ in string coercion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo(object): | |
def __init__(self): | |
noop = True | |
def __repr__(self): | |
return "using __repr__" | |
def __str__(self): | |
return "using __str__" | |
class Bar(object): | |
def __init__(self): | |
noop = True | |
def __str__(self): | |
return "using __str__" | |
class Baz(Bar): | |
def __init__(self): | |
super(Baz, self).__init__() | |
def __repr__(self): | |
return "using __repr__" | |
class Bad(object): | |
def __init__(self): | |
noop = True | |
def __repr__(self): | |
return "using __repr__" | |
foo = Foo() | |
bar = Bar() | |
baz = Baz() | |
bad = Bad() | |
print "Foo: " + str(foo) | |
print "Bar: " + str(bar) | |
print "Baz: " + str(baz) | |
print "Bad: " + str(bad) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment