I have multiple.txt files and I'm looking for any of such strings: lst = ['PASSED', 'FAILED', 'PASSED WITH WARNINGS']
I crated code, but it splits on whitespaces and I get just PASSED
instaead of PASSED WITH WARNINGS
. How to correct my code?
for i in range(len(tab)):
with open(tab[i], 'r') as infile:
lines = infile.readlines()
var = [line for line in lines if (set(line.split()) & set(msgs))]
print(var)
Example of my.txt file:
Some info here
Another info
Some more info
And so on...
2021_09_09_09_09_31 PASSED WITH WARNINGS
2021_09_09_09_09_34 PASSED WITH WARNINGS
lst = ['PASSED', 'FAILED', 'PASSED WITH WARNINGS']
for i in range(len(tab)):
with open(tab[i], 'r') as infile:
lines = infile.readlines()
var = [line.split(" ", 1)[-1].strip() for line in lines if any([word in line for word in lst])]
print(var)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.