On Sun, Mar 23, 2014 at 1:50 AM, Steven D'Aprano
<steve+comp.lang.pyt...@pearwood.info> wrote:
> Line endings are terminators: they end the line. Whether you consider the
> terminator part of the line or not is a matter of opinion (is the cover
> of a book part of the book?) but consider this:
>
>     If you say that the end of lines are *not* part of the line, then
>     that implies that some parts of the file are not inside any line
>     at all. And that would be just weird.

Not so weird IMO. A file is not a concatenation of lines; it is a
stream of bytes. Now, if you ask Python to read you 512 bytes from a
binary file, and then ask for another 512 bytes, and so on until you
reach the end, then it would indeed be VERY weird if there were parts
of the file that weren't in the returned (byte) strings. But if you
ask for a line, and then another line, and another line, then it's
quite reasonable to interpret U+000A as "line separation" rather than
"line termination", and not return it. (Both interpretations make
sense. I just wish the most obvious form of iteration gave the
cleaner/tidier version, or at very least that there be some really
obvious way to ask for lines-without-endings.) Imagine the output of
GNU find as a series of records. You can ask for those to be separated
by newlines (the default, or -print), or by NULs (with the -print0
command). In either case, the records do not *contain* that value,
they're separated by it; the records consist of file names.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to