I want to get specific information from a log file and filter this through some strings. I chose to use codecs.open
as I was getting error messages like:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb4 in position 3167: invalid start byte
.
The problem was not that the encoding was inappropriate like utf-16.
Doing so made the error disappear but now this script is taking way longer than before. Is there any way to optimise this to reduce the runtime?
My code looks a lot like this:
listeFull = codecs.open("file", "r",encoding='utf-8', errors='ignore')
strings = ("str1","str2","str3")
net = "0.0.0.0"
for line in listeFull:
if net in line:
if all(s not in line for s in strings):
print(line)
listeFull.close()