Can a function access its own name?

bobueland at yahoo.com bobueland at yahoo.com
Sat Nov 19 14:55:03 EST 2005


Thanks Diez and Peter,

Just what I was looking for. In "Library Reference" heading

3.11.1 Types and members

I found the info about the method you described. I also made a little
function to print out not just the name of the function but also the
parameter list. Here it is

    # fname.py
    import sys, string

    def cap(s, n):
      print string.replace("".join([sys._getframe().f_code.co_name, \
            repr(sys._getframe().f_code.co_varnames)]), "\'", "")

    cap('Hello', 'Bob')

Running this yields the result

    cap(s, n)




More information about the Python-list mailing list