[Python-Dev] [Python-3000] Universal newlines support in Python 3.0

Georg Brandl g.brandl at gmx.net
Sun Aug 12 20:24:07 CEST 2007


Paul Moore schrieb:

> Specifically, I'm looking to replicate this behaviour:
> 
>>xxd crlf
> 0000000: 610d 0a62 0d0a                           a..b..
> 
>>xxd lf
> 0000000: 610a 620a                                a.b.
> 
>>python
> Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> open('crlf').read()
> 'a\nb\n'
>>>> open('lf').read()
> 'a\nb\n'
>>>>
> 
> As demonstrated, this is the default in Python 2.5. I'd hope it was so
> in 3.0 as well.

Note that Python does nothing special in the above case. For non-Windows
platforms, you'd get two different results -- the conversion from \r\n to
\n is done by the Windows C runtime since the default open() mode is text mode.

Only with mode 'U' does Python use its own universal newline mode.

With Python 3.0, the C library is not used and Python uses universal newline
mode by default.

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-Dev mailing list