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

Georg Brandl g.brandl at gmx.net
Wed Aug 15 15:36:56 CEST 2007


Brett Cannon schrieb:
> On 8/14/07, Guido van Rossum <guido at python.org> wrote:
>> I thought some more about the universal newlines situation, and I
>> think I can handle all the use cases with a single 'newline'
>> parameter. The use cases are:
>>
>> (A) input use cases:
>>
>> (1) newline=None: input with default universal newlines mode; lines
>> may end in \r, \n, or \r\n, and these are translated to \n.
>>
>> (2) newline='': input with untranslated universal newlines mode; lines
>> may end in \r, \n, or \r\n, and these are returned untranslated.
>>
>> (3) newline='\r', newline='\n', newline='\r\n': input lines must end
>> with the given character(s), and these are translated to \n.
>>
>> (B) output use cases:
>>
>> (1) newline=None: every \n written is translated to os.linesep.
>>
>> (2) newline='': no translation takes place.
>>
>> (3) newline='\r', newline='\n', newline='\r\n': every \n written is
>> translated to the value of newline.
>>
> 
> 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'd use None and "\r"/... as proposed, but "U" instead of the empty string
for universal newline mode. "U" already has that established meaning, and
you don't have to remember the difference between the two (false) values ""
and None.

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.



More information about the Python-3000 mailing list