a question regarding call-by-reference

Kent Johnson kent at kentsjohnson.com
Mon Feb 6 19:16:45 EST 2006


enjoying the view wrote:
> Imported normally this would work fine. The list given as a parameter
> would be one element larger. But when the stubs are generated, the
> function doesn't return anything and the list is appended in the server
> and the client-side list is left untouched. At first I thought the
> solution was easy, just return the changed parameters and place them in
> the parameter variables in the client stub:
> def add_elm(list):
>    send_message({'funcname': 'add_elm', 'args': (list)})
>    response = receive_message()
>    (list) = response.get('args')
>    return response.get('result')
> 
> The problem is, this doesn't work. The original list doesn't point to
> the changed list. I have been trying to figure this out and it seems
> that if I just assign to the list variable it just modifies the local
> (to the function) name space, and that those changes aren't reflected
> in the list in the original name space.

Try
   list[:] = response.get('args')
this will change the value of the list passed in.

Kent



More information about the Python-list mailing list