What's the use of changing func_name?

Michael Hudson mwh at python.net
Thu May 19 13:05:16 EDT 2005


Robert Kern <rkern at ucsd.edu> writes:

> 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.

Error messages!

Cheers,
mwh

-- 
  There are two kinds of large software systems: those that evolved
  from small systems and those that don't work.
                           -- Seen on slashdot.org, then quoted by amk



More information about the Python-list mailing list