problem with PyMapping_SetItemString()

R

rahul

i have a c extension

tatic PyObject *upadteCheck(PyObject *self,PyObject *args){
PyObject *var_pyvalue=NULL,*newVar_pyvalue=NULL,*dict=NULL;
char *varName;

if (!PyArg_ParseTuple(args, "s", &varName)){
return NULL;
}
dict=PyEval_GetLocals();
var_pyvalue=PyMapping_GetItemString(dict,varName);

if(inObject==NULL){
dict=PyEval_GetGlobals();
var_pyvalue=PyMapping_GetItemString(dict,varName);
}

printf("\n input value for variable %s is : %s
\n",varName,PyString_AsString(var_pyvalue))

newVar_pyvalue=Py_BuildValue("s","value changed");

PyMapping_SetItemString(dict,varname,newVar_pyvalue);

return Py_BuildValue("");
}



and i have three test cases for this extension

1.(name test1.py)
import upadteCheck
var1= "abcd"

func1():
updateCheck.updateCheck(var1)
print var1


2.(name test2.py)
import upadteCheck
var1= "abcd"
updateCheck.updateCheck(var1)
print var1

3.(name test3.py)
import upadteCheck

func1():
var1= "abcd"
updateCheck.updateCheck(var1)
print var1

if i run these three test cases like
1. import test1
test1.fun1()

2. python test2

3. import test3
test3.func1()

than first two test cases runs correctly and gives result for var1
"value changed" but 3rd test case not gives correct result and value
of var1 remains "abcd"


why this happen and how i correct it ??
 
S

Stefan Behnel

rahul said:
tatic PyObject *upadteCheck(PyObject *self,PyObject *args){
PyObject *var_pyvalue=NULL,*newVar_pyvalue=NULL,*dict=NULL;
char *varName;

if (!PyArg_ParseTuple(args, "s", &varName)){
return NULL;
}
dict=PyEval_GetLocals();
var_pyvalue=PyMapping_GetItemString(dict,varName);

if(inObject==NULL){
dict=PyEval_GetGlobals();
var_pyvalue=PyMapping_GetItemString(dict,varName);
}

what's "inObject"?

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top