I've sub-classed float to alter its __str__() method to end with a symbol (in my case €).
The input is filtered to remove a symbol (in my case €).
class Euro(float):
def __new__(cls, value):
v = ''.join([_ for _ in value if _ != '€' ])
return super(Euro, cls).__new__(cls, v)
def __str__(self):
return f'{self} €'
But when I print, I get a recursive print error.
g = Euro('123.23 €')
print (g)
Error:
Euro.py, line __str__
return f'{self} €'
[Previous line repeated 329 more times]
RecursionError: maximum recursion depth exceeded