var or inout parm?
Diez B. Roggisch
deets at nospam.web.de
Sun Dec 7 12:13:59 CET 2008
mh at pixar.com schrieb:
> How can I make a "var" parm, where the called function can modify
> the value of the parameter in the caller?
>
> def f(x):
> x = x + 1
>
> n = 1
> f(n)
> # n should now be 2
Chris showed one way, another is simply returning it. As python can
return ad-hoc created tuples & unpack them, some C++-wrappers for
example treat out/inout vars like this:
def foo(in, inout):
return inout, out1, out2
x, y, z = foo(a, x)
Obviously you are responsible for properly assigning the returned inout
to the right name again.
Diez
More information about the Python-list
mailing list