> I will read lines from file, with the 'for loop', and then I will check them > for > 'foo' matches with a 'while loop', if matches I (somehow) re-initialise the > list, and if there is no matches for foo, I will append line to the list. > When I > get to a blank line (end of block), write myList to an external file. And > start
Can you please explain what you mean by _re-initialize the list_ ? > with another line. > > I am stuck with defining 'blank line', I don't manage to get throught the > while > loop, any hint here I will really appreciate it. > I don't expect the solution, as I think this is a great exercise to get wet > with python, but if anyone thinks that this is the wrong way of solving the > problem, please let me know. > > Can you explain why the following won't work? #!/usr/bin/python import sys import gzip # At the moment not bother with argument part as I am testing it with a # testing log file #fileIn = gzip.open(sys.argv[1]) fileIn = gzip.open('big_log_file.gz', 'r') fileOut = open('outputFile', 'a') for line in fileIn: while line != 'blank_line': if 'foo' not in line: fileOut.write(line) > > > Somehow rename outputFile with big_log_file.gz > > fileIn.close() > fileOut.close() > > ------------------------------------------------------------- > > The log file will be fill with: > > > Tue Nov 17 16:11:47 GMT 2009 > bladi bladi bla > tarila ri la > patatin pataton > tatati tatata > > Tue Nov 17 16:12:58 GMT 2009 > bladi bladi bla > tarila ri la > patatin pataton > foo > tatati tatata > > Tue Nov 17 16:13:42 GMT 2009 > bladi bladi bla > tarila ri la > patatin pataton > tatati tatata > > > etc, etc ,etc > .............................................................. > > Again, thank you. > > -- > ----------------------------- > Antonio de la Fuente Mart?nez > E-mail: t...@muybien.org > ----------------------------- > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor