What's the use of changing func_name?

could ildg could.net at gmail.com
Thu May 19 05:03:34 EDT 2005


Thanks to Robert Kern.
You mean that though we can change the func_name of a function,
but we still can't call it by func_name, and the func_name is only
useful in some other circumstances?
I also think so now after I have tried so many times on this puzzled func_name
property.
On 5/19/05, Robert Kern <rkern at ucsd.edu> wrote:
> 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~
> 
> Others have answered this particular question, but you're probably still
> wondering what is the use of changing .func_name if it doesn't also
> change the name by which you call it. The answer is that there are tools
> that use the .func_name attribute for various purposes. For example, a
> documentation generating tool might look at the .func_name attribute to
> make the proper documentation. Actually, that's probably *the* biggest
> use case because I can't think of any more significant ones.
> 
> --
> Robert Kern
> rkern at ucsd.edu
> 
> "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
>



More information about the Python-list mailing list