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