# [Tutor] More image manipulation

Terry Carroll carroll at tjc.com
Tue Jun 7 22:52:08 CEST 2005

```On Tue, 7 Jun 2005, Terry Carroll wrote:

> On Tue, 7 Jun 2005, D. Hartley wrote:
>
> > def findlist():
> >     newlist = []
> >     for i in range(480):
> >         line = fromlist[:640]
> >         del fromlist[:640]
> >         x = line.index(195)
> >         y = x + 5
> >         z = line[x:y]
> >         del line[x:y]
> >         for i in z:
> >             newlist.append(i)
> >         for i in line:
> >             newlist.append(i)
> >     return newlist
>
> where does the variable named "fromlist" come from?  It's not passed into
> the method as a parameter.

I'm thinking more and more that this is the issue.

Take a look at this, and see if it gives you the flavor.  Only the third
approach actually gives you what (I think) you want, rather than reusing
the same list over and over.

def testit1():
print fromlist1[0]
del fromlist1[0]
return
fromlist1 = ['a', 'b', 'c', 'd']
print "testit1: Denise problem"
testit1()
testit1()
testit1()

def testit2(flist):
print flist[0]
del flist[0]
return
fromlist2 = ['a', 'b', 'c', 'd']
print "testit2: Python Gotcha #6"
# http://www.ferg.org/projects/python_gotchas.html
testit2(fromlist2)
testit2(fromlist2)
testit2(fromlist2)

def testit3(flist):
mylist = flist[:]
# copy the list rather than mutating it for next time
print mylist[0]
del mylist[0]
return
fromlist3 = ['a', 'b', 'c', 'd']
print "testit3: the right way"
testit3(fromlist3)
testit3(fromlist3)
testit3(fromlist3)

```