> I'm trying to do this with the re module - the two tags looks like: > > <foo> > ... > a bunch of text (~1500 lines) > ... > </foo> > > I need to identify the first tag, and the second, and unconditionally > strip out everything in between those two tags, making it look like: > > <foo> > </foo>
A very simplistic approach uses a flag: atTag = 0 f = open(...) while not atTag: line = f.readline() if line == '<foo>': atTag = True break outFile.write(line) # + \n, I can't remember... while atTag: line = f.readline() if line == '</foo>': atTag = False while f: outfile.write(f.readline()) This flag approach is sometimes called a sentinal... I'm sure somebody can find better ways of doing this but I'm too tired to bother right now! :-( The sentinel approach will work... Alan G. _______________________________________________ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor