[Q] File Object -- function 'read'
Kragen Sitaker
kragen at dnaco.net
Thu Jul 19 16:09:05 EDT 2001
In article <mailman.995560073.30389.python-list at python.org>,
jackyci <jackyci at sinamail.com> wrote:
>In Windows. "\n" equal "\x0d\x0a"
>But in function "read" of File Object, "\x0d\x0a" equal 1 byte.
Actually "\n" still equals "\x0a". It's just that "\x0d\x0a" gets
translated to "\x0a" on input from a file, and the reverse translation
happens on output to a file, unless you opened the file with "b" binary
mode.
This is brain-damage Python inherited from C; the C standard specifies
that this translation has to happen by default on systems that
represent their line endings in a non-Unix way, so that
text-manipulating C programs written on Unix will Just Work. (At the
time that this was established, this was nearly all C programs.)
--
<kragen at pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Perilous to all of us are the devices of an art deeper than we possess
ourselves.
-- Gandalf the White [J.R.R. Tolkien, "The Two Towers", Bk 3, Ch. XI]
More information about the Python-list
mailing list