469,588 Members | 2,741 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,588 developers. It's quick & easy.

How to change a PyObject passed to the C extension

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

Aug 11 '07 #1
1 1306
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'!

Ciao,
Marc 'BlackJack' Rintsch
Aug 11 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by BoĆĄtjan Jerko | last post: by
6 posts views Thread by Jacek Generowicz | last post: by
4 posts views Thread by b.milbrandt | last post: by
reply views Thread by Pradnyesh Sawant | last post: by
1 post views Thread by Allen | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.