Q: name of current function?

gloth at my-deja.com gloth at my-deja.com
Sun Feb 4 00:34:21 EST 2001


I try to implement python wrappers around functions in c++. At compile
time, I can't determine which functions will be wrappered, so I need a
mechanism that allows me to create wrappers dynamically.

My idea was to create a single entry-point for all functions that I
create in python, and do the dispatching there by querying the name
under which the function was called. Basically this...

    PyThreadState *state = PyThreadState_Get();
    PyFrameObject *frame = state->frame;
    PyCodeObject *code = frame->f_code;
    PyObject *name = code->co_name;
    const char *str = PyString_AsString(name);

Unfortunately, I always get "?" as the function name. Basically, the
whole code object is not very useful. The sample code was based on a
solution to the same problem (obtaining the name of the current
function), only in Pythin itself. It seems that this mechanism does not
work for builtin functions.

Is there a way to get this information, perhaps the whole PyMethodDef
structure that I used to register the new function?

Please also reply to mail email address: tobias (at) gloth.net

Any hints or suggestions are greatly appreciated!

-Tobi


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list