Re: [Python-Dev] Re: Unix line endings required for PyRun* breaking embedded Python

2005-01-20 Thread Skip Montanaro
Fredrik> s = s.replace("\r", "\n"["\n" in s:]) This fails on admittedly weird strings that mix line endings: >>> s = "abc\rdef\r\n" >>> s = s.replace("\r", "\n"["\n" in s:]) >>> s 'abcdef\n' where universal newline mode or Just's re.sub() gadget would work. Skip ___

[Python-Dev] Re: Unix line endings required for PyRun* breaking embedded Python

2005-01-20 Thread Fredrik Lundh
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.sp