Pass-by-reference : Could a C#-like approach work in Python?

Duncan Booth duncan at
Fri Sep 12 11:24:48 CEST 2003

Michael Chermside <mcherm at> wrote in 
news:mailman.1063300996.11325.python-list at

> I started by looking for use cases... where would this proposed
> pass-by-reference actually prove useful? Stephen basically found
> one good use case:
>   I wish to "transfer ownership" of an object that gets passed
>   into a method call, and protect against the caller accidently
>   continuing to use the object. [So, we'll use a "ref" parameter and
>   set the caller's variable to None.]

That only works if the caller hasn't assigned that object to any other 
variables. If they have, they can still accidentally continue to use the 
object. Since you have to trust the caller anyway, why not trust them to 
stop using the object?

Duncan Booth                                             duncan at
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

More information about the Python-list mailing list