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
  • 23,638
  • 8
  • 74
  • 112
arynaq
  • 6,392
  • 9
  • 40
  • 71
  • 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
  • 23,638
  • 8
  • 74
  • 112
Rohit Jain
  • 203,151
  • 43
  • 392
  • 509
  • 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
  • 5,936
  • 9
  • 38
  • 64
2

You can use __name__ like so integral.__name__

Alex
  • 24,385
  • 6
  • 56
  • 53