problem with PyMapping_SetItemString()

Aaron Brady castironpi at gmail.com
Tue Apr 21 20:58:30 EDT 2009


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

> 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