REPOST: Re: re.match oddity

Hans Nowak wurmy at
Thu Dec 27 01:42:26 CET 2001

Issac wrote:
> A curious thing is happening in my script (below).
> The resulting files contain little ^M's (when viewed with the Windows
> version of gvim 6.0 but not when viewed with notepad.exe) at the ends
> of the lines.  When I remove the lines
>     line_is_lone_left_curly = re.match(r'^\s*{\s*((//.*)|(/\*.*\*/))?$', line)
>     if line_is_lone_left_curly:
>       pylines[-1] = pylines[-1][:-1] + ':\n'
>       continue
> the ^M's go away.  Does anyone know why?  I'm using Python 2.1.1
> on Cygwin with Windows 2000.

Not sure it has anything to do with re.match. Most likely it's caused 
by the line that appends ':\n'. This is probably written to file 
as '\r\n' (CR/LF) (in Windows). I suspect that some other lines
only have '\n' (LF) as a line separator, otherwise gvim would not show
them; it usually detects the line ending and displays the text

The solution is to make sure that your lines have either a Windows
or a Unix line ending, but not a mix. Use os.linesep when in doubt.


========= WAS CANCELLED BY =======:
From: Hans Nowak <wurmy at>
Newsgroups: comp.lang.python
Subject: cmsg cancel <3C2A6D23.AD1807D9 at>
Control: cancel <3C2A6D23.AD1807D9 at>
Date: Mon, 31 Dec 2001 03:56:52 GMT
Organization: A poorly-installed InterNetNews site
Lines: 2
Message-ID: <cancel.3C2A6D23.AD1807D9 at>
X-Trace: 1009776154 27193 (31 Dec 2001 05:22:34 GMT)
X-Complaints-To: usenet at
NNTP-Posting-Date: Mon, 31 Dec 2001 05:22:34 +0000 (UTC)
X-No-Archive: yes
X-Unac4ncel: yes
X-Commentary: I love NewsAgent 1.10 and the Sandblaster Cancel Engine Build 74 (19 March 1999)

This message was cancelled from within Mozilla.

More information about the Python-list mailing list