Beginner question - How to effectively pass a large list
Bruno Desthuilliers
bdesth.nospam at removeme.free.fr
Mon Dec 15 17:25:36 EST 2003
J.R. wrote:
> Hi folks,
>
> The python can only support passing value in function call (right?),
let's see :
>>> l = range(5)
>>> def modif(alist): alist[0] = 'allo'
...
>>> l
[0, 1, 2, 3, 4]
>>> modif(l)
>>> l
['allo', 1, 2, 3, 4]
Er... Ok, let's try something else :
>>> class Toto:
... pass
...
>>> t = Toto()
>>> t.name = "Toto"
>>> def rename(t): t.name = "Titi"
...
>>> t
<__main__.Toto instance at 0x402dccec>
>>> t.name
'Toto'
>>> rename(t)
>>> t
<__main__.Toto instance at 0x402dccec>
>>> t.name
'Titi'
Well... You may want to read more about bindings (not 'assignements') in
Python.
(hint : it already *does* work like pointers in C[++] - at least for
mutable objects).
Bruno
More information about the Python-list
mailing list