On Mon, Dec 24, 2018 at 5:16 AM Mats Wichmann <m...@wichmann.us> wrote:
> On 11/14/18 3:01 PM, Steven D'Aprano wrote: > > On Tue, Nov 13, 2018 at 11:59:24PM -0500, Avi Gross wrote: > >> I have been thinking about the thread we have had where the job seemed > to be > >> to read in a log file and if some string was found, process the line > before > >> it and generate some report. Is that generally correct? > > > > If that description is correct, then the solution is trivial: iterate > > over the file, line by line, keeping the previous line: > > > > previous_line = None > > for current_line in file: > > process(current_line, previous_line) > > previous_line = current_line > > > The classic COBOL programmers idiom :-) That said, sometimes text processing at the shell can precede or even replace some of these. Of course that assumes Unix/Linux OS. In this speciic case grep with its -B option can be used to generate a file that contains only the lines of interest. HTH Asokan Pichai _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor