how to force a list to be local?

Mark Harrison mh at dreadnok.pixar.com
Thu Aug 5 19:57:07 EDT 2004


In the following code, t1 does not modify b, while t2 seems to
modify b.  What do I need to do in order to make b local in t2
so that b.remove() does not modify the passed in list?

def t1(a,b):
    b = []

def t2(a,b):
    b.remove(4)


a=[1,2,3]
b=[4,5]

t1(a,b)
print a,b

t2(a,b)
print a,b

results:
[1, 2, 3] [4, 5]
[1, 2, 3] [5]

Many TIA!
Mark

-- 
Mark Harrison
Pixar Animation Studios



More information about the Python-list mailing list