[Python-Dev] Re: Unix line endings required for PyRun* breaking embedded Python (original) (raw)
Fredrik Lundh fredrik at pythonware.com
Thu Jan 20 09:57:50 CET 2005
- Previous message: [Python-Dev] Unix line endings required for PyRun* breaking embedded Python
- Next message: [Python-Dev] Re: Unix line endings required for PyRun* breaking embedded Python
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Just van Rossum wrote:
I don't think that in general you want to fold multiple empty lines into one. This would be my prefered regex:
s = re.sub(r"\r\n?", "\n", s) Catches both DOS and old-style Mac line endings. Alternatively, you can use s.splitlines(): s = "\n".join(s.splitlines()) + "\n" This also makes sure the string ends with a \n, which may or may not be a good thing, depending on your application.
s = s.replace("\r", "\n"["\n" in s:])
- Previous message: [Python-Dev] Unix line endings required for PyRun* breaking embedded Python
- Next message: [Python-Dev] Re: Unix line endings required for PyRun* breaking embedded Python
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]