[Pythonmac-SIG] Re: [Python-Dev] Import hook to do end-of-line conversion?

Chris Barker chrishbarker@home.net
Mon, 09 Apr 2001 17:47:34 -0700


Greg Ewing wrote:
> Chris Barker <chrishbarker@home.net>:
> > Even if people have been sloppy and used binary mode for text files
> > under *nix, that code would still work with *nix text files, which is
> > the only way it works now anyway.
> 
> That's a good point. The only thing that could break is if
> you opened a non-Unix file in *text* mode, and then expected
> it to behave as though it had been opened in *binary* mode.
> I can't imagine any code being screwy enough to do that!

Actually, I thought about it more, and of course, Guido is right. On
*nix, if you open a binary file in text mode, it works just fine, as
there is no difference. However, under the proposed scheme, the text
mode would translate "\r" into "\n", messing up your binary data. It
would also do it only with a couple of particular byte values, so it
might not be obvious that anything is wrong right away.

I've done that myself, by mistake. I wrote a little tool that used FTP
to transfer some binary files. It worked fine under Linux, but then I
tried to run it on the Mac, and the files got corrupted. It took me WAY
too long to figure out that I had read the file in text mode.
Personally, I've always thought it was unfortunate that the default was
text mode, rather than binary, or even better, there could be no
default: you have to specify either "b" or "t", then there would be no
room for confusion.

-Chris

-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker@home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------