Pass-by-reference : Could a C#-like approach work in Python?
Stephen Horne
$$$$$$$$$$$$$$$$$ at $$$$$$$$$$$$$$$$$$$$.co.uk
Wed Sep 10 14:04:40 EDT 2003
On Wed, 10 Sep 2003 22:39:23 +0800, Tim Hoffman <timh at zute.net> wrote:
>Hi Stephen
>
>The bit I can't fathom is why you would want to do this ?
>At least in the case of the simple example you give.
It wasn't intended as a real world example - it was only intended to
illustrate what I want to be able to do.
>When you call inc function you are taking an immutable object 1 and
>creating a new object which is the result of adding 1 to 1. And what you
>are then asking it to rebind the variable x to point to the new int
>object 2 inside the function.
Yes - that is exactly it. To rebind the callers variable/whatever that
supplied the parameter from within the function.
>Why you would want to do this is unclear. Secondly if it where a more
>abstract object it would have an increment method which you could call
>on the object which was passed to the function.
No, you are taking the noddy example too literally.
For a more realistic (but still simplified) example, see my reply to
Peter Ottens post.
More information about the Python-list
mailing list