def a():
print 'sss'
print getattr(a, "_decorated_function", a).__name__
it print :
a
thanks
updated
my code:
def a():
w='www'
print getattr(a,'w')
but it print :
Traceback (most recent call last):
File "D:\zjm_code\a.py", line 8, in <module>
print getattr(a,'w')
AttributeError: 'function' object has no attribute 'w'
In response to the Updated question
Functions must be given their attributes after declaration.
Another method that is more similar with other OO languages is to use a class. This example will make a static attribute:
This will make w shared between all instances of class a, which is most useful as a constant in the program. If you on the other will be working with the variable and changing its value, it it better to do the following: