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

Skip Montanaro skip at pobox.com
Thu Jan 20 13:51:41 CET 2005


    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


More information about the Python-Dev mailing list