How can I revert back to the default function that python uses if there is no __str__
method?
class A :
def __str__(self) :
return "Something useless"
class B(A) :
def __str__(self) :
return some_magic_base_function(self)
You can use object.__str__()
:
class A:
def __str__(self):
return "Something useless"
class B(A):
def __str__(self):
return object.__str__(self)
This gives you the default output for instances of B
:
>>> b = B()
>>> str(b)
'<__main__.B instance at 0x7fb34c4f09e0>'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With