[Tutor] problem with list remove

Jon Cosby jcosby@mindspring.com
Tue, 11 Sep 2001 17:37:56 -0700


The problem was in the second loop. Once the list had been removed, "remove"
didn't take kindly to removing them a second time. I added the line:

for item in ignore:
	if item in dl:
		dl.remove(item)

Problem gone. Thanks.

Jon

-----Original Message-----
From: Danny Yoo [mailto:dyoo@hkn.eecs.berkeley.edu]
Sent: Tuesday, September 11, 2001 4:49 PM
To: Jon Cosby
Cc: tutor@python.org
Subject: Re: [Tutor] problem with list remove


On Mon, 10 Sep 2001, Jon Cosby wrote:

> I'm doing a Web search that is succesful until I try to configure it
> to ignore specified directories using the "remove" operation. I'm not
> getting any error messages, but the script stops when it comes to the

By the program stopping, does it seem like the program is going into an
infinite loop, or do you mean something else?

Hmm... taking a look at getFile() now...


> def getFile(text, dir):
> 	hits = []
> 	dl = os.listdir(dir)
> 	for item in ignore:	# List of directories to ignore
> 		dl.remove(item)   # Works in interpreter, but list comes up empty here

'ignore' appears to be a global variable of some kind.  Where is ignore
being defined?  Perhaps 'ignore' is a really large list --- I doubt this
possibility, but it might be good to put some debugging statement here to
see what 'ignore' looks like.


> 	text = string.lower(text)
> 	for d in dl:
> 		d = dir + '\\' + d
> 		if os.path.isfile(d):
> 			hits.extend(searchtext(d, text))
> 		elif os.path.isdir(d):
> 			hits.extend(getFile(text, d))
> 	return hits


To tell the truth, I don't see anything here that would cause an infinite
loop, but I might be overlooking something.  Can you tell us more
information?

Best of wishes to you!