var or inout parm?

J. Clifford Dyer jcd at sdf.lonestar.org
Wed Dec 10 18:29:44 EST 2008


On Mon, 2008-12-08 at 00:57 -0800, Chris Rebert wrote:
> On Mon, Dec 8, 2008 at 12:26 AM, Bruno Desthuilliers
> <bruno.42.desthuilliers at websiteburo.invalid> wrote:
> > Colin J. Williams a écrit :
> >>
> >> mh at pixar.com wrote:
> >>>
> >>> 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
> >>>
> >>> Many TIA!!
> >>> Mark
> >>>
> >>>
> >>
> >> Why not run it and see?
> >>
> >> Your function returns None.
> >>
> >> The function in effect takes a copy of n.
> >
> > Nope, it takes the object bound to global name 'n'.
> 
> See Also: the earlier heated debate thread over what evaluation
> strategy Python uses (Survey says!: call-by-object).
> 

Oh dear God.  PLEASE don't see also that thread.  That way lies madness.
Just google for call-by-object, and ignore the hell out of that thread.



> Cheers,
> Chris
> 




More information about the Python-list mailing list