problem with PyMapping_SetItemString()

Aaron Brady castironpi at
Wed Apr 22 02:58:30 CEST 2009

On Apr 21, 2:25 am, rahul <rahul03... at> wrote:
> i have a c extension
>           dict=PyEval_GetLocals();
>           PyMapping_SetItemString(dict,varname,newVar_pyvalue);

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

There's no good way to change the variable space programmatically.
Python has more flexibility than most other languages as it is.
Anyway, your best bet is to use an independent namespace:

class Globals: pass
setattr( Globals, 'itemX', 'value1' )
setattr( Globals, 'itemX', 'value2' )

Your 'updateCheck' function would then have to take the namespace as
an additional parameter.

More information about the Python-list mailing list