[Python-Dev] [python] Re: New lines, carriage returns, and Windows
fuzzyman at voidspace.org.uk
Thu Sep 27 00:14:58 CEST 2007
Dino Viehland wrote:
> My understanding is that users can write code that uses only \n and Python will write the end-of-line character(s) that are appropriate for the platform when writing to a file. That's what I meant by uses \n for everything internally.
> But if you write \r\n to a file Python completely ignores the presence of the \r and transforms the \n into a \r\n anyway, hence the \r\r in the resulting stream. My last question is simply does anyone find writing \r\r\n when the original string contained \r\n a useful behavior - personally I don't see how it is.
> But Guido's response makes this sound like it's a problem w/ VC++ stdio implementation and not something that Python is explicitly doing. Anyway, it'd might be useful to have a text-mode file that you can write \r\n to and only get \r\n in the resulting file. But if the general sentiment is s.replace('\r', '') is the way to go we can advice our users of the behavior when interoperating w/ APIs that return \r\n in strings.
We always do replace('\r\n','\n') but same difference...
> -----Original Message-----
> From: "Martin v. Löwis" [mailto:martin at v.loewis.de]
> Sent: Wednesday, September 26, 2007 3:01 PM
> To: Dino Viehland
> Cc: python-dev at python.org
> Subject: Re: [Python-Dev] New lines, carriage returns, and Windows
>> This works great as long as you stay within an entirely Python world.
>> Because Python uses \n for everything internally
> I think you misunderstand fairly significantly how this all works
> together. Python does not use \n "for everything internally". Python
> is well capable of representing \r separately, and does so if you
> ask it to.
>> So I'm curious: Is there a reason this behavior is useful that I'm
> I think you are missing how it works in the first place (or else
> you failed to communicate to me what precise behavior you find
> Python-Dev mailing list
> Python-Dev at python.org
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk
More information about the Python-Dev