Embedding Python - Passing by Reference

Jean-Paul Calderone exarkun at divmod.com
Fri Nov 30 00:17:03 CET 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