how to get name of function from within function?

Christopher J. Bottaro cjbottaro at alumni.cs.utexas.edu
Fri Jun 3 23:17:00 CEST 2005


I want to get the name of the function from within the function.  Something
like:

def myFunc():
  print __myname__
>>> myFunc()
'myFunc'

Really what I want to do is to easily strip off the prefix of a function
name and call another function.  Like this:

def prefix_myFunc(a, b, c):
  name = __myname__[7:]
  call(name, a, b, c)

That would call myFunc(a, b, c).

How do I accomplish this 'elegantly', err...'pythonicly'..=)

Also, is there a way to turn normal positional args into a tuple without
using *?  Like this:

def f(a, b, c):
  print get_args_as_tuple()
>>> f(1, 2, 3)
(1, 2, 3)

I don't want to use
def f(*args):
  print args
because I want to keep the error checking capability that comes with using a
fixed number of positional args.

Thank you for the help.




More information about the Python-list mailing list