passing PyIntType objects by reference

Peter Otten __peter__ at web.de
Thu Jun 10 13:18:54 EDT 2004


Patrick Stinson wrote:

> when passing an python integer value to a C function
> ie.
> x = 1
> mymod.myfunc(x)
> 
> is it possible to change the value of the python object "x" as happens in
> c when you pass a pointer to an int? Is there something fundamentally
> wrong with this idea, as this does not happen in pure python anyway?

>>> a = 1
>>> b = 1
>>> a is b
True

If you somehow manage to change a's value into 42, you will change every 1
to 42.

Peter




More information about the Python-list mailing list