<div dir="ltr"><div><div><div><div><div>Hello,<br></div>I have an extremely simple piece of code which reads a .csv file, which has 1000 lines of fixed fields, one line at a time, and tries to print some values. <br><br> 1 #!/usr/bin/python3<br>
2 # <br> 3 import sys, time, re, os<br> 4 <br> 5 if __name__=="__main__":<br> 6 <br> 7 ifd = open("infile.csv", 'r')<br> 8 <br> 9 linenum = 0<br> 10 for line in ifd:<br>
11 line1 = re.split(",", line)<br> 12 total = 0<br> 13 if linenum == 0:<br> 14 linenum = linenum + 1<br> 15 continue<br> 16 #if linenum == 126:<br> 17 #linenum = linenum + 1<br>
18 #break<br> 19 print("LINE: ", linenum, line1[1])<br> 20 for i in range(1,8):<br> 21 if line1[i].strip():<br> 22 print("line[i] ", int(line1[i]))<br>
23 total = total + int(line1[i])<br> 24 print("Total: ", total)<br> 25 <br> 26 if total >= 4:<br> 27 print("POSITIVE")<br> 28 else:<br> 29 print("Negative")<br>
30 linenum = linenum + 1<br> 31 ifd.close<br><br></div>It works fine till it parses the 1st 126 lines in the input file. For the 127th line (irrespective of the contents of the actual line), it prints the following error:<br>
Traceback (most recent call last):<br> File "p1.py", line 10, in <module><br> for line in ifd:<br> File "/usr/lib/python3.2/codecs.py", line 300, in decode<br> (result, consumed) = self._buffer_decode(data, self.errors, final)<br>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 1173: invalid continuation byte<br>$ <br><br></div>I am not able to figure out the cause of this error. Any clues as to why I am seeing this error, are appreciated.<br>
<br></div>Thanks,<br></div>-SM<br></div>