Embedding Python - Passing by Reference

Jean-Paul Calderone exarkun at divmod.com
Thu Nov 29 18:17:03 EST 2007


On Thu, 29 Nov 2007 14:39:52 -0800 (PST), andy at britishideas.com wrote:
>I understand the parameters to Python functions are passed by
>reference:
>
>def foo(a):
>  a = a + 1
>
>Will change the value of a in the calling function. How do I implement
>the equivalent in C when extending Python?

You misunderstand how parameters are passed in Python:

    >>> x = 10
    >>> def foo(y):
    ...     y = y + 1
    ...
    >>> foo(x)
    >>> x
    10
    >>>

So there's no behavior here to attempt to emulate when embedding or extending.

Jean-Paul



More information about the Python-list mailing list