How to change a PyObject passed to the C extension

Marc 'BlackJack' Rintsch bj_666 at
Sat Aug 11 18:48:38 CEST 2007

On Sat, 11 Aug 2007 09:43:19 -0700, MD wrote:

>    I have a Python C extension which is passed a PyObject containing
> an integer value. Is it possible to change this same PyObject so that
> now the integer is of a different value?

No it is not.  Even if you poke around in the object ``struct`` this would
have severe consequences for cached/shared objects.  Just imagine:

from your_module import bzzzt

def f():
    print 2 + 2

bzzzt(2)   # This changes the value of 2 to 3.
f()        # This prints '6'!

	Marc 'BlackJack' Rintsch

More information about the Python-list mailing list