The functools @wrap allow to keep attributed function original name
For an example:
And the result:from functools import wrapsdef myAttribute(func):@wraps(func)def WrapprintName (*args, **kwargs):print ("The method is: " + func.__name__ )return func(*args, **kwargs)return WrapprintName@myAttributedef printName (pName ):"""Print my name """print (pName)print (printName.__name__) # prints 'f'print (printName.__doc__) # prints 'does some math'printName ("Zvika")
printName
Print my name
The method isprintName
Zvika
The printName method name was kept although the printName method was annotated with @myAttribute
אין תגובות:
הוסף רשומת תגובה