Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return function name in python? [duplicate]

Doing a math function of the type def.

def integral_error(integral,f):
    ------stufff-------
    print integral

gives something like: '<function simpsons at 0xb7370a74>'

is there a way to get just simpsons without string manipulations? ie just the function name?

like image 546
arynaq Avatar asked Mar 18 '26 13:03

arynaq


1 Answers

You can use:

integral.func_name

Or:

integral.__name__

Though, they are exactly equivalent. According to docs:

__name__ is Another way of spelling func_name

Here's a sample code:

>>> def f():
    pass

>>> f.__name__
'f'
>>> f.func_name
'f'
>>> 
like image 75
Rohit Jain Avatar answered Mar 21 '26 03:03

Rohit Jain