I want to give an int
a function, e.g.:
>>> def x.converttostring():
... return str(self)
>>> x = 1
>>> print x.converttostring()
'1'
>>> print x
1
ideally I want to have it operating on select ints, not all ints, e.g.
>>> x.converttostring()
'1'
>>> y.converttostring()
Traceback (most recent call last):
...
AttributeError: 'int' object has no attribute 'converttostring'
Is it possible? The function part is essential (not str(x)
) and creating a class is out of the question.