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 ??
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 ??