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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -