Apr-27-2020, 07:50 AM
1. My examples all start with code you provided. Flag and cnt are from your code. They are where they are because that is where you put them. Flag does nothing, I don't know why it was in your code. cnt could be initialized at the top of the program or inside the with. It works fine in either location.
2. cnt was your variable from your code. It counts how many lines were read. I assumed since you were counting lines that you wanted to know the line number of log entries that matched lstart and lstr.
2.a. the readLine locations are again from code that you provided. They work fine, so I did not change them. There are lots of ways you could read all the lines from the log file. For example:
2. cnt was your variable from your code. It counts how many lines were read. I assumed since you were counting lines that you wanted to know the line number of log entries that matched lstart and lstr.
2.a. the readLine locations are again from code that you provided. They work fine, so I did not change them. There are lots of ways you could read all the lines from the log file. For example:
while True: line = fp.readline() if not line: break: # Break out of loop elif lstart in line:Or using the new walrus operator available in Python 3.8
while line := fp.readline(): # Loop until all lines were read if lstart in line: