call by reference howto????

castironpi at gmail.com castironpi at gmail.com
Thu Feb 28 14:51:41 EST 2008


On Feb 27, 6:02 pm, Tamer Higazi <n... at mail.de> wrote:
> Hi!
> Can somebody of you make me a sample how to define a function based on
> "call by reference" ???
>
> I am a python newbie and I am not getting smart how to define functions,
> that should modify the variable I passed by reference.
>
> thanks in advance
>
> Tamer

If it's a mutable object, avoid the pitfalls of rebinding the
parameter, and just modify the object.

BAD:

def f( a ):
   a= { 'this': 'that' }

GOOD:

def f( a ):
   a.clear()
   a[ 'this' ]= 'that'




More information about the Python-list mailing list