[Python-3000] Proposed new language for newline parameter to TextIOBase

Christian Heimes lists at cheimes.de
Wed Aug 15 15:28:05 CEST 2007


Brett Cannon wrote:
> I like the options, but I would swap the meaning of None and the empty
> string.  My reasoning for this is that for option 3 it says to me
> "here is a string representing EOL, and make it \n".  So I would think
> of the empty string as, "I don't know what EOL is, but I want it
> translated to \n".  Then None means, "I don't want any translation
> done" by the fact that the argument is not a string.  In other words,
> the existence of a string argument means you want EOL translated to
> \n, and the specific value of 'newline' specifying how to determine
> what EOL is.

I like to propose some constants which should be used instead of the
strings:

MAC = '\r'
UNIX = '\n'
WINDOWS = '\r\n'
UNIVERSAL = ''
NOTRANSLATE = None

I think that open(filename, newline=io.UNIVERSAL) or open(filename,
newline=io.WINDOWS) is much more readable than open(filename,
newline=''). Besides I always forget if Windows is '\r\n' or '\n\r'. *g*

Christian



More information about the Python-3000 mailing list