Pass-by-reference : Could a C#-like approach work in Python?
Peter Otten
__peter__ at web.de
Wed Sep 10 10:55:28 EDT 2003
Stephen Horne wrote:
> ... and here is (roughly) what I'd like to be able to do...
>
>>>> def Inc(ref p) :
> ... p += 1
> ...
>>>> x = 1
>>>> Inc(x)
>>>> x
> 2
>
> Any thoughts?
Obviously, your example could easily be rewritten to
def inc(p):
return p + 1
x = inc(x)
and a similar function with two by-ref parameters would still be readable:
x, y = inc2(x, y)
So here's my question. How many functions are there in your *real* code that
could benefit from, say three or more by-ref parameters?
Hint: for me it comes close to 0 :-)
By the way, this is strictly from a user perspective, I trust the Python
developers to overcome the implementation issuses, *if* there is a
significant usability improvement.
Peter
More information about the Python-list
mailing list