How to ignore invalid lines in a file?

Viewed 3364

I'm iterating over a file

for line in io.TextIOWrapper(readFile, encoding = 'utf8'):

when the file contains the following line

b'"""\xea\x11"\t1664\t507\t137\t2\n'

that generates the following exception

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xea in position 3: invalid continuation byte

How can I make my script to ignore such lines and continue with the good ones?

3 Answers
Related