could ildg wrote: > Thank you for your help. > I know the function g is changed after setting the func_name. > But I still can't call funciton g by using f(), when I try to do > this, error will occur: > <code> > >>>>g.func_name="f" >>>>print g > > <function f at 0x00B2CEB0> > >>>>f() > > Traceback (most recent call last): > File "<stdin>", line 1, in ? > NameError: name 'f' is not defined > </code> > Since the name of g is changed into f, why can't I call it by using f()? > Should I call it using f through other ways? Please tell me. Thanks~
You're confusing "the func_name attribute of the function object" with "one of the names to which the function object is bound". If you want to be able to invoke the-function-formerly-known-as-g using the name 'f', you don't want to change the func_name attribute, you want to add 'f' as a name bound to the function object. In Python, name binding is accomplished through the assignment statement: py> f = g py> f() decorating this is in function g What is is you're actually trying to do here? STeVe -- http://mail.python.org/mailman/listinfo/python-list