[Pythonmac-SIG] Re: MacPython and line-endings

Doug Wyatt doug@sonosphere.com
Wed, 10 Oct 2001 22:11:06 -0700


Apologies if I'm beating a dead horse, but given that:

[a] Mac OS X is a bit remarkable in that it's common to encounter all 
three flavors of newlines (\n created by Unix and Next-derived software, 
\r from traditional MacOS software, \r\n on ISO-9660 CD's, DOS floppies 
and Zip disks, etc.)

[b] it is programmatically simple to properly read any of these three 
formats

[c] all high-class text editors on Mac OS X (e.g. BBEdit, CodeWarrior, 
Project Builder) do so

I think it would be best if Python were to:

[1] make readline() and all other read methods on text files 
transparently translate \r or \r\n to \n

[2] write newlines to text files using either a string member of the 
file object, or a global member of whatever module is appropriate (os?), 
defaulted to whatever is native.

The implementation could always open the files in binary mode, save a 
flag to remember if the user had actually specified text mode, and use 
the flag to determine whether to perform the above translations on read 
and write.

There might be a catch I haven't thought of ... in seek and tell? ... 
but that must have already been dealt with for OS's that translate \r\n 
to \n for text files?

Doug


On Wednesday, October 10, 2001, at 04:47 , Russell E Owen wrote:
>> A wild idea (and basically why I added Guido to the cc list): file
>> objects could make our life a lot simpler if there was a call
>> file.readtoterminator(termchars, max), where termchars is a string, 
>> which
>> would read data up to and including a character in termchars (or until
>> 'max' bytes have been read). It would have to be implemented as a
>> getc() loop in C, but as we're going to do that looping anyway at some
>> point we might as well do it in C and not in Python...
>
> Wouldn't it make more sense to modify readline with a named keyword 
> argument, e.g. "terminator"? The default would be "none" and would 
> result in using the current platform's favorite terminator.
>
> I personally feel that judicious use of named keyword arguments can 
> result in a nice simple structure of flexible, powerful methods, 
> avoiding a plethora of similar-but-not-quite-the-same methods.

--
Doug Wyatt
work:  dwyatt@apple.com  (CoreAudio)
personal:  doug@sonosphere.com   http://www.sonosphere.com

"When you discard arrogance, complexity, and a few other things that get 
in
  the way, sooner or later you will discover that simple, childlike, and
  mysterious secret known to those of the Uncarved Block: Life is Fun."
	-- The Tao of Pooh