[Python-Dev] [Python-3000] in-out parameters (original) (raw)
Edward Loper edloper at gradient.cis.upenn.edu
Sun Apr 30 19:30:07 CEST 2006
- Previous message: [Python-Dev] Adding functools.decorator
- Next message: [Python-Dev] socket module recvmsg/sendmsg
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-Dev] Adding functools.decorator
- Next message: [Python-Dev] socket module recvmsg/sendmsg
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]