[Python-Dev] [Python-3000] in-out parameters

Edward Loper edloper at gradient.cis.upenn.edu
Sun Apr 30 19:30:07 CEST 2006


Rudy Rudolph wrote:
> 2) pass-by-reference: 
> def f(wrappedParam):
> wrappedParam[0] += 5 # ugh
> return "this is my result"
>> # call it
> x = 2
> result = f([x])
> # also ugly, but x is now 7

This example is broken; here's what you get when you run it:
 >>> def f(wrappedParam):
... wrappedParam[0] += 5
... return "this is my result"
...
 >>> # call it
... x = 2
 >>> result = f([x])
 >>> x
2
You probably intended something more like:
 >>> x = [2]
 >>> result = f(x)
 >>> x[0]
7
(As for the actual topic, I'm personally -0 for adding in-out parameters 
to python.)
-Edward


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /