How to change a PyObject passed to the C extension

M

MD

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

Thanks and Regards,
-MD
 
M

Marc 'BlackJack' Rintsch

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'!

Ciao,
Marc 'BlackJack' Rintsch
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top