In python how can i print only the first matching line from the log output? -


i have input

line 1: [debug]... line 2: [debug]...  line 2: [debug]...  

from want print first matching string meaning first matching line 1: [debug] , stop traversing.

i have tried code below:

for num1,line1 in enumerate(reversed(newline),curline):     ustr1="[debug]"      if ustr1 in line1:         firstnum=num1 

can me in this?

your question not formatted well, cannot see object looking etc.... i'd assume it's way:

input="1: [debug]....\n2: [debug]...\n3:...." # e.g.: print(input.split("\n")[0].strip("\r")) # first line. searching line containing string "ustr1", do: line in input.split("\n"):     if ustr1 in line:         print(line)         break #as dont want more 1 line #furthermore, if need index of line, do: i,line in enumerate(input.split("\n")):      pass #i = index, line = line 

hope understood right ;)


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -