[Tutor] List and Indexing error.

SA sarmstrong13@mac.com
Tue, 13 Aug 2002 23:51:36 -0500


I'm getting a persistent indexing error whenever I run the following script:

#!/usr/bin/env python

import re
import os
import string

list = os.listdir('.')
l = len(list)
print "The number of items in this dir is: ",  l
for i in range(l):
    input = open(list[i], "rb")
    text = input.read()
    input.close()
    text2 = re.findall(r".*", text)
    if text2[78] == "<hr>":
        text3 = string.join(text2[79:])
        output = open(list[i], "wb")
        output.write(text3)
        output.close()
    else:
        print list[i] + " does not have the correct begin length ..."

Basically, I have a folder full of html files. I need to get rid of the
first part of each file. I figured the correct index. But when I run it I
get the following:
The number of items in this dir is:  148
Traceback (most recent call last):
  File "./repy2.py", line 20, in ?
    if text2[78] == "<hr>":
IndexError: list index out of range

Anyone know why?

Thanks.
SA

-- 
"I can do everything on my Mac I used to on my PC. Plus a lot more ..."
-Me