I have this piece of code that reads from a gunzip stream and checks if each line contains some pattern. What I have is
if (pattern in line):
do_something()
Some lines contain non-ASCII characters, when my code reaches those lines, I get a UnicodeDecodeError. However, I am unable to reproduce this error in my manual testing. When I copy the repr of the line that causes UnicodeDecodeError and assign it to variable line
and do pattern in line
, I get False
instead of an error. I am confused about this inconsistency. Why does it behave different for the same string?