How to bind Object
to a string (primitive) without overloading and cast ( str()
) explicit type?
class Foo: def __init__(self, text): self.text = text def __str__(self): return self.text _string = Foo('text') + 'string'
Conclusion:
Traceback (most recent call last): File "test.py", line 10, in <module> _string = Foo('text') + 'string' TypeError: unsupported operand type(s) for +: 'type' and 'str'
Operator
+
should be overloaded? Are there any other ways (just interesting)?
PS: I know about operator overloads and casting types (e.g. str(Foo('text'))
)
tomas source share