When you print an object in Python, as well __repr__, and __str__are not determined by the user, Python converts the object to a string, limited angular brackets ...
<bound method Shell.clear of <Shell object at 0x112f6f350>>
The problem is rendering this in a web browser in strings that also contain HTML that should render normally. The browser is clearly confused by angle brackets.
I am trying to find any information on how these views are formed, if there is a name for them.
Is it possible to change the way that Python represents objects as strings, for all objects that do not have a method __repr__, by overriding the __repr__class object?
So, if Python usually returned "<Foo object at 0x112f6f350>", which hook could make it return "{Foo object at {0x112f6f350}}"instead, or something else, without the need to directly modify Fooevery other class?
source
share