0

I want to do something along the lines of

static PyObject* printArgs(PyObject* self, PyObject* args) {
    PyObject * oarg1 = NULL;
    PyArg_ParseTuple(args,"O",&oarg1);
    return -- magic --
}

Such that calling modulename.printArgs(a) returns 'a'.

Is this possible? The best I could think of is looking through locals() for a variable that points to whatever I got in args, but if there's more than one name for the value I could get the wrong name.

1 Answers1

1

Not really possible. In no way is it guaranteed that the parameter even has a name, it could be an anonymous expression. As such, this is not a limitation of the API, it is a fundamental issue with what you are trying to achieve. Can you give some motivation for the printArgs function?

mornfall
  • 428
  • 2
  • 6
  • I don't mind getting a null pointer if it's anonymous. I'm adding an interpreter to a c++ application and I want to identify objects by their names in the python interpreter. –  Dec 08 '13 at 10:19
  • Then you can just assume that every parameter is anonymous (because in a way, it is) and just return a null pointer right away. :-) – mornfall Dec 08 '13 at 10:23
  • Depending on what objects you want to identify, making them register themselves (through constructors, eg.) sounds like a much better plan. – mornfall Dec 08 '13 at 10:25