How to change a PyObject passed to the C extension

Discussion in 'Python' started by MD, Aug 11, 2007.

  1. MD

    MD Guest

    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
    MD, Aug 11, 2007
    #1
    1. Advertising

  2. 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
    Marc 'BlackJack' Rintsch, Aug 11, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anand
    Replies:
    2
    Views:
    887
    Anand
    Sep 11, 2003
  2. Christian Seberino
    Replies:
    5
    Views:
    1,032
    Skip Montanaro
    Feb 10, 2004
  3. Olivier Sessink
    Replies:
    0
    Views:
    380
    Olivier Sessink
    Feb 24, 2005
  4. Replies:
    11
    Views:
    477
    David Bolen
    Jul 19, 2006
  5. Allen
    Replies:
    1
    Views:
    328
    Gabriel Genellina
    Jun 12, 2007
Loading...

Share This Page