Jun-19-2020, 07:17 AM
oh ok, it was simpler than that sorry. That is what I wanted to do. I just overthought it
class Foo(object): def __init__(self, someVar): self._x = someVar def asList(self): return [self._x] def asString(self): return "'{}'".format(self._x) def __repr__(self): return "{}".format(self._x) foo = Foo(5) # Result: 5 foo.asList() # Result: [5] # foo.asString() # Result: '5' #I don't know why I thought I would be able to have the constructor return an integer, and then "magically" have methods of that object acting on the integer with a "." operator. It makes absolutly no sense. Never mind. Minor lapsus.