why do Python functions have name? -
i don't see significance/use of func_name. 2 different function can have same name,it's enough know reference function. refer below sample code
def a(): print "function a" b=a def a(): print "new function a" >>> b.func_name 'a' >>> a.func_name 'a'
a() , b() both have same function name, both reference different function object.
>>> b.func_name 'a' >>> a.func_name 'a'
can 1 me understand why python store func_name has no use?
the name used things. repr(fn)
uses fn.func_name
display name of function. help(fn)
uses fn.func_name
documentation.
pickling function uses func_name
attribute, both name stored in pickle, , check function defined in module (so can't pickle function defined inside function checks there function same name , same code object defined in module).
note stack traces use name attached code object fn.func_code.co_name
can't change name appears in stack trace read-only attribute.
Comments
Post a Comment