how to know argument name with which a function of extended c called
Arnaud Delobelle
arnodel at googlemail.com
Tue Apr 14 09:34:26 EDT 2009
rahul <rahul03535 at gmail.com> writes:
> Hi,
> i need to write a 'c extension function' in this function i need to
> change argument value with which this function called.
> ie,
> if a python code like
> import changeValue as c
> arg="old value"
> c.changeValue(arg)
> print arg
>
> then it print "new value"
>
> i write code like this..
>
> static PyObject *changeValue(PyObject *self,PyObject *args){
> PyObject *sampleObj, *m ;
> char *argName;
>
> if (!PyArg_ParseTuple(args, "O", &sampleObj)){
> return NULL;
> }
>
> m = PyImport_AddModule("__main__");
> PyObject_SetAttrString(m, argName, "new value");
> return Py_BuildValue("");
> }
>
> But for this i need to know the argument name with which this function
> called .
> Is this possible to know argument name in extended c function? if yes,
> than how i can do it???
No, you can't and it's a good thing, because when reading your code you
can find out very easily when a variable has been rebound: it's on those
lines of the form
name = expression
Instead, make your 'changeValue" function return the new value, then
write:
import changeValue as c
arg = "old value"
arg = c.changeValue(arg)
print arg
It'll work, with the added benefit that it'll be clearer that arg was
changed.
--
Arnaud
More information about the Python-list
mailing list