What's the use of changing func_name?
Robert Kern
rkern at ucsd.edu
Thu May 19 02:49:52 EDT 2005
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
More information about the Python-list
mailing list