2022-08-06 06:20:04 +03:00
|
|
|
# Emulate the old behavior of method.__repr__ when printing,
|
|
|
|
# which called repr() on the receiver...
|
|
|
|
def __str__(self):
|
|
|
|
return f'<bound method {self.__qualname__} of {self.__self__!r}>'
|
|
|
|
method.__str__ = __str__
|
|
|
|
|
2021-03-09 17:00:47 +03:00
|
|
|
class Foo(object):
|
|
|
|
def __str__(self):
|
|
|
|
return '<str>'
|
|
|
|
def __repr__(self):
|
|
|
|
return '<repr>'
|
|
|
|
print('Foo:',Foo())
|
|
|
|
|
|
|
|
print(str(Foo()))
|
|
|
|
print(repr(Foo()))
|
|
|
|
|
|
|
|
print(Foo().__str__)
|
|
|
|
print(Foo().__repr__)
|