OK, first point: your output file is configured to automatically encode text written on it as utf-8 , so do not include an explicit call to the encode('utf-8') method when passing arguments to the write() method.
So, the first thing to try is to simply use the following in your inner loop:
writer.write(line)
If this does not work, then the problem will almost certainly be that, as others have noted, you are not properly decoding your input file.
Accepting wild assumptions and assuming that your input files are encoded in cp1252 , you can try a quick test in the inner loop:
for line in codecs.open(infile, 'r', 'cp1252'): writer.write(line)
Minor point: "wtr" is a meaningless mode line (since write access means read access). Simplify it with either wt or even w.
source share