I am trying to update a Python function's name incrementally based on the number of times it has been called.
An example of the original function can be seen below:
def function():
function.counter += 1
return print('call 0')
function.counter = 0
Below is the function I would like to be generated the second time the above function is called:
def function1():
function.counter1 += 1
return print ('call 1')
And so on with each previous function call resulting in the creation of a new function which adds 1 to the previous function's name. Once function1() is called, function2() would be created, then once function 2() is called function3() would be created, and so on. Is there a straightforward way I could go about this?