[Tutor] Remove
Lloyd Kvam
lkvam@venix.com
Tue, 11 Sep 2001 18:55:20 -0400
I would add some exception handling and some print statements. If there is too much to print, use a log file. (e.g. print >> logfile, "removed %s" % (item) )
I inserted suggested changes below. Is there a higher level try that is hiding a ValueError???
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 function
> below. I've run the first few lines in the interpreter, and I can't see
> anything wrong with it. Any ideas?
>
> def getFile(text, dir):
> hits = []
> dl = os.listdir(dir)
> for item in ignore: # List of directories to ignore
try:
> dl.remove(item) # Works in interpreter, but list comes up empty here
print "removed %s" % (item)
except ValueError:
print "item %s is not present in list" % item
raise ValueError
> 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
>
> Jon Cosby
>
> jcosby@mindspring.com
> www.jcosby.com
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice: 603-443-6155
fax: 801-459-9582