I have tried to produce a simplified version of what I am trying to accomplish; here it is:
class CustomString():
def __init__(self, function):
self._creator_function = function
@property
def string(self, *args):
return self._creator_function(*args)
def creator1(arg1):
return 'Hello ' + arg1
def creator2(arg1, arg2):
return 'Aloha ' + arg1 + ',' + arg2
The CustomString class is meant to be a dynamic string generator, which is provided a function on initialisation that performs that returns the string given specific arguments. Those functions might take an explicit number of arguments, as in the example below, but the class method should be flexible because each instance might have a different creator function.
If I run the following:
c = CustomString(creator1)
c.string('John')
I would expect to see:
'Hello John'
But I get an error instead:
TypeError: creator1() missing 1 required positional argument: 'arg1'
stringa property?