[Tutor] How to get python to differentiate between CR, LF, and CRLF in a string (not a file)?

R. Alan Monroe amonroe at columbus.rr.com
Fri Dec 14 21:08:43 CET 2007


Is is possible to get python to differentiate between CR, LF, and CRLF
in a string (not a file)? This is a triple quoted string I've pasted
into the source (putting r to indicate raw string made no difference).
It contains a mixture of CR, LF and CRLF (I can see this by enabling
visible End of Line markers in Scite). I need to distingush between
them.

Whenever I iterate over the string, it's automagically converting all
variants to an ascii 10.

    for x in entry:
        print repr(x), ord(x)

...
'S' 83
'c' 99
'h' 104
'e' 101
'd' 100
'u' 117
'l' 108
'e' 101
'd' 100
'\n' 10  <--- this should be a 13 followed by a 10
...


Alan



More information about the Tutor mailing list