[Python-Dev] New lines, carriage returns, and Windows (original) (raw)
Dino Viehland dinov at exchange.microsoft.com
Thu Sep 27 00:09:04 CEST 2007
- Previous message: [Python-Dev] New lines, carriage returns, and Windows
- Next message: [Python-Dev] [python] Re: New lines, carriage returns, and Windows
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
-----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 missing?
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 puzzling).
Regards, Martin
- Previous message: [Python-Dev] New lines, carriage returns, and Windows
- Next message: [Python-Dev] [python] Re: New lines, carriage returns, and Windows
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]