There is a script that, on a regular basis, searches for values in the log, but I get not only the required value, but also empty lines.
Here is an example of output, how to get only values where there is text?
[('0', 'R', 'ER')] [] [] [] [] [] [('80', 'S', 'ER')] [] [('21:55:21.210', 'SEVERE', 'ER')] [] [] def FindError():
patterrn1 = r'([\d\:.]+).{6}([SEVERE]+).*(ER\d{3})' regexeper = re.compile(patterrn1) print(regexeper) with open(ExistLogs) as in_file: with open(ResultFile, 'w') as out_file: for line in in_file: try: test1 = regexeper.findall(line) print(test1) except AttributeError: pass While I found the solution of the verification condition itself, I do not know how correct it is, but it works
test1 = regexeper.findall(line) #print(test1) if test1 == []: pass else: print(test1) except AttributeError: pass
if lst:instead ofif lst == []:to check if there are any items in the list. - jfsкак проверить пуст ли массив в python?- ReinRaus