REPOST: Re: re.match oddity

Hans Nowak wurmy at earthlink.net
Wed Dec 26 19:42:26 EST 2001


Issac wrote:
> 
> A curious thing is happening in my c2py.py 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
accordingly.

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.

--Hans

========= WAS CANCELLED BY =======:
Path: news.sol.net!spool1-nwblwi.newsops.execpc.com!newsfeeds.sol.net!newspump.sol.net!newsfeed.direct.ca!look.ca!newsfeed.dacom.co.kr!feeder.kornet.net!news1.kornet.net!ua4canc3ll3r
From: Hans Nowak <wurmy at earthlink.net>
Newsgroups: comp.lang.python
Subject: cmsg cancel <3C2A6D23.AD1807D9 at earthlink.net>
Control: cancel <3C2A6D23.AD1807D9 at earthlink.net>
Date: Mon, 31 Dec 2001 03:56:52 GMT
Organization: A poorly-installed InterNetNews site
Lines: 2
Message-ID: <cancel.3C2A6D23.AD1807D9 at earthlink.net>
NNTP-Posting-Host: 211.57.49.2
X-Trace: news2.kornet.net 1009776154 27193 211.57.49.2 (31 Dec 2001 05:22:34 GMT)
X-Complaints-To: usenet at news2.kornet.net
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