On Sat, 27 Jun 2009 19:55:17 +0200, Piet van Oostrum wrote: >>>>>> Terry Reedy <tjre...@udel.edu> (TR) wrote: > >>TR> Peter Otten wrote: >>>>>> Will your program handle empty lines of input correctly? >>>>> Strangely enough, it seems to do so, but why? >>>> >>>> Because there aren't any. When you read lines from a file there will >>>> always be at least the newline character. Otherwise it would indeed >>>> fail: > >>TR> Except possibly for the last line. > > But then that line wouldn't be empty either. > > If there is an empty line not terminated by a newline after the last > newline, then that is called 'end-of-file' :=)
I try to always write file-handling files under the assumption that some day somebody (possibly me) will pass the function a file-like object, and therefore make the minimum number of assumptions about each line. For example, I wouldn't assume that lines can't be empty, or that they must end in a newline. The later is violated even by ordinary files, but the former could be violated by a file-like object which iterated over (say) ['first line', 'second line', '', 'the previous line was blank']. -- Steven -- http://mail.python.org/mailman/listinfo/python-list