On 2009-06-18 00:57, steve wrote:
"Robert Kern"<robert.k...@gmail.com> wrote in message
news:mailman.1728.1245289092.8015.python-l...@python.org...
On 2009-06-17 19:36, steve wrote:
"Carl Banks"<pavlovevide...@gmail.com> wrote in message
news:2f6271b1-5ffa-4cec-81f8->>0276ad647...@p5g2000pre.googlegroups.com...
On Jun 15, 7:56 pm, "steve"<st...@nospam.au> wrote:
I was just looking at the python tutorial, and I noticed these lines:
http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-...
"Windows makes a distinction between text and binary files;
"the end-of-line characters in text files are automatically altered
"slightly when data is read or written.
I don't see any obvious way to at docs.python.org to get that
corrected:
Is
there some standard procedure?
What's wrong with it?
Carl Banks
1) Windows does not make a distinction between text and binary files.
2) end-of-line characters in text files are not automatically altered by
Windows.
The Windows implementation of the C standard makes the distinction. E.g.
using stdio to write out "foo\nbar\n" in a file opened in text mode will
result in "foo\r\nbar\r\n" in the file. Reading such a file in text mode
will result in "foo\nbar\n" in memory. Reading such a file in binary mode
will result in "foo\r\nbar\r\n". In your bug report, you point out several
proprietary APIs that do not make such a distinction, but that does not
remove the implementations of the standard APIs that do make such a
distinction.
http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx
Perhaps it's a bit dodgy to blame "Windows" per se rather than its C
runtime, but I think it's a reasonable statement on the whole.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma
that is made terrible by our own mad attempt to interpret it as though it
had
an underlying truth."
-- Umberto Eco
Which is where I came in: I was looking for simple file IO in the tutorial.
The tutorial tells me something false about Windows, rather than something
true about Python.
I don't think it's false. I think it's a fair statement given the Windows
implementation of the C standard library. Such things are frequently considered
to be part of the OS. This isn't just some random API; it's the implementation
of the C standard.
I'm looking at a statement that is clearly false (for anyone who knows
anything about Windows file systems and Windows file io), which leaves the
Python behaviour completely undefined (for anyone who knows nothing about
Python).
I understand that many of you don't really have any understanding of
Windows, much less any background with Windows, and I'm here to help. That
part was simple.
The next part is where I can't help: What is the behaviour of Python?
The full technical description is where it belongs, in the reference manual
rather than a tutorial:
http://docs.python.org/library/functions.html#open
I'm sure you don't think that tutorial is only for readers who can guess
that they have to extrapolate from the behaviour of the Visual C library in
order to work out what Python does.
All a tutorial level documentation needs to know is what is described: when a
file is opened in text mode, the actual bytes written to a file for a newline
may be different depending on the platform. The reason that it does not explain
the precise behavior on each and every platform is because it *is* undefined.
Python 2.x does whatever the C standard library implementation for stdio does.
It mentions Windows as a particularly common example of a difference between
text mode and binary mode.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
--
http://mail.python.org/mailman/listinfo/python-list