Dynamic function calling

Christian Tanzer tanzer at swing.co.at
Fri Sep 1 21:21:17 CEST 2000


Olaf Meyer <olaf.meyer at nokia.com> wrote:

> Thanks to all of you for the suggestions! I do have anoter small question:
> Is it possible to determine the name of the currently executing function?

I'm not sure what you mean here, but the following might give you a
hint:

-------------------------------------------------------------------------------
import traceback

def caller_info (level = -3) :
    """Returns `file-name', `line-number', `function-name' of caller at
       position `level' in the call stack (-3 being the caller of
       `caller_info's caller).
    """
    try :
        raise AssertionError
    except AssertionError :
        return traceback.extract_stack () [level] [:3]
-------------------------------------------------------------------------------

-- 
Christian Tanzer                                         tanzer at swing.co.at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92





More information about the Python-list mailing list