Equivalent of Perl chomp?

Erno Kuusela erno-news at erno.iki.fi
Thu Jan 31 07:26:47 EST 2002


In article <u5i8b8jtee2r13 at corp.supernews.com>, "Paul Watson"
<pwatson at mail.com> writes:

| Thank you for all of the replies.  Given the replies, I am wondering if
| Python treats "\n" as a platform independent newline.  I know it does when
| using print.  However, the re.sub() example below makes me think that \n is
| only a literal LF and does not resolve to CRLF on the DOS/Windows platform.
| Is this just a function of it being used in re?  Yes, clearly, "\n"
| generates CRLF when used in a print statement.

in dos text mode, all cr-lf sequences are translated into lf upon
reading and lf into cr-lf upon writing, at file i/o time. unless you
are using binary mode, in which no translation is done. so even in
dos, the strings you have in memory always end in lf (when read from a
file opened in text mode).

  -- erno



More information about the Python-list mailing list