472,145 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

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 1329
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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.