By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,715 Members | 768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,715 IT Pros & Developers. It's quick & easy.

How to change a PyObject passed to the C extension

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.