2

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?

Paul Fleming
  • 24,238
  • 8
  • 76
  • 113
arynaq
  • 6,710
  • 9
  • 44
  • 74
  • Well you got a bunch of answers quickly, probably because of a catchy title, but you really could have given a better description of the problem and what exactly you're looking for. – Junuxx Oct 25 '12 at 20:00

3 Answers3

8

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'
>>> 
Paul Fleming
  • 24,238
  • 8
  • 76
  • 113
Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
  • You might want to add that according to [the docs](http://docs.python.org/reference/datamodel.html), `func_name` and `__name__` are completely equivalent. – Junuxx Oct 25 '12 at 19:58
3

You can do this by using integral_error.__name__.

IT Ninja
  • 6,174
  • 10
  • 42
  • 65
2

You can use __name__ like so integral.__name__

Alex
  • 25,147
  • 6
  • 59
  • 55