could ildg wrote: > def a(func): > def _inner(*args, **kwds): > print "decorating..." > return func(*args, **kwds) > _inner.func_name = func.func_name -->when I delete this line, the > rusult is the same. why? > return _inner > > @a > def g(*args): > for x in args: > print x > print "this is in function g" > > g(1,2,3,4,5) > > func_name is writable in python 2.4. I wonder what's the use of > writing it. Consider the code above, to change the func_name or not > will get the completely same result. The result is as > below: > > decorating... > 1 > 2 > 3 > 4 > 5 > this is in function g > > Please tell me how does this happen, thank you~
Well, the function you posted certainly doesn't change the literal string you have inside when you change its func_name. However, the function object *does* change. In [1]:def g(x): ...: pass ...: In [2]:g Out[2]:<function g at 0x5aedf0> In [3]:g.func_name = 'f' In [4]:g Out[4]:<function f at 0x5aedf0> -- Robert Kern [EMAIL PROTECTED] "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list