Possible to change function name in definition?

Posted by Bird Jaguar IV on Stack Overflow See other posts from Stack Overflow or by Bird Jaguar IV
Published on 2012-06-03T22:28:31Z Indexed on 2012/06/03 22:40 UTC
Read the original article Hit count: 222

Filed under:
|
|
|

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)?

© Stack Overflow or respective owner

Related posts about python

Related posts about function