Shawn Milochik wrote: > How can I check a line (or two) from my input file (or stdin stream) > and still be able to process all the records with my function?
One way: from itertools import chain firstline = instream.next() head = [firstline] # loop over entire file for line in chain(head, instream): process(line) You can of course read more than one line as long as you append it to the head list. Here's an alternative: from itertools import tee a, b = tee(instream) for line in a: # determine file format, # break when done # this is crucial for memory efficiency # but may have no effect in implementations # other than CPython del a # loop over entire file for line in b: # process line Peter -- http://mail.python.org/mailman/listinfo/python-list