[Python-Dev] py_compile and CR in source files

Tim Peters tim_one@email.msn.com
Sat, 27 May 2000 00:53:14 -0400

> Well, assuming that it is NOT okay with \r\n in there, then read
> the whole blob in and use string.replace() on it.
[Skip Montanaro]
> I thought of that too, but quickly dismissed it.  You may have a CRLF pair
> embedded in a triple-quoted string.  Those should be left untouched.

Why?  When Python compiles a module "normally", line-ends get normalized,
and the CRLF pairs on Windows vanish anyway.  For example, here's cr.py:

def f():
    s = """a
    for ch in s:
        print ord(ch),

import dis

I'm running on Win98 as I type, and the source file has CRLF line ends.

C:\Python16>python misc/cr.py
97 10 98 10 99 10 100 10

That line shows that only the LFs survived.  The rest shows why:

          0 SET_LINENO               1

          3 SET_LINENO               2
          6 LOAD_CONST               1 ('a\012b\012c\012d\012')
          9 STORE_FAST               0 (s)

That is, as far as the generated code is concerned, the CRs never existed.

    y'rs  - tim