On 2014-11-09 21:20, Syed Khalid wrote:

Code after adding path of .txt files :

import glob, codecs, re, os

regex = re.compile(r"Age: |Sex: |House No: ") # etc etc

for txt in glob.glob("D:/Python/source/*.txt"):
     with codecs.open(txt, encoding="utf-8") as f:
         oldlines = f.readlines()
     for i, line in enumerate(oldlines):
         if "Elector's Name:" in line:
             break
     newlines = [regex.sub("", line).strip().replace("-", "_") for line
in oldlines[i:]
     with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
         w.write(os.linesep.join(newlines))


I executed code in edit rocket.

Error message :


File "EamClean.log", line 12
     with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
        ^
SyntaxError: invalid syntax

[snip]

The previous line is missing a ']' on the end. It should be:

newlines = [regex.sub("", line).strip().replace("-", "_") for line in oldlines[i:]]

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to