I tried several ways to change the function name in the definition, but they failed.
>>> def f():
pass
>>> f.__name__
'f'
>>> def f():
f.__name__ = 'new name'
>>> f.__name__
'f'
>>> def f():
self.__name__ = 'new name'
>>> f.__name__
'f'
But I can change the name attribute after defining it.
>>> def f():
pass
>>> f.__name__ = 'new name'
>>> f.__name__
'new name'
Any way to change/set it in the definition (other than using a decorator)?
The function body is not executed until you execute the function. You could use a decorator though:
And then use it like this:
However, the function is still only reachable as
f.