Re: simplest way to strip a comment from the end of a line?

2008-12-05 Thread eric
On Dec 4, 11:35 pm, Paul McGuire [EMAIL PROTECTED] wrote: Yowza!  My eyes glaze over when I see re's like r'(?m)^(?Pdata.*? (.*?.*?)*)(?:#.*?)?$! yeah, I know ... :( ( I love complicated regexp ... it's like a puzzle game for me) from pyparsing import quotedString, Suppress, restOfLine

Re: simplest way to strip a comment from the end of a line?

2008-12-05 Thread eric
On Dec 5, 11:56 am, eric [EMAIL PROTECTED] wrote: On Dec 4, 11:35 pm, Paul McGuire [EMAIL PROTECTED] wrote: Yowza!  My eyes glaze over when I see re's like r'(?m)^(?Pdata.*? (.*?.*?)*)(?:#.*?)?$! yeah, I know ... :( ( I love complicated regexp ... it's like a puzzle game for me) from

simplest way to strip a comment from the end of a line?

2008-12-04 Thread Joe Strout
I have lines in a config file which can end with a comment (delimited by # as in Python), but which may also contain string literals (delimited by double quotes). A comment delimiter within a string literal doesn't count. Is there any easy way to strip off such a comment, or do I need to

Re: simplest way to strip a comment from the end of a line?

2008-12-04 Thread eric
On Dec 4, 4:50 pm, Joe Strout [EMAIL PROTECTED] wrote: I have lines in a config file which can end with a comment (delimited   by # as in Python), but which may also contain string literals   (delimited by double quotes).  A comment delimiter within a string   literal doesn't count.  Is there

Re: simplest way to strip a comment from the end of a line?

2008-12-04 Thread Arnaud Delobelle
Joe Strout [EMAIL PROTECTED] writes: I have lines in a config file which can end with a comment (delimited by # as in Python), but which may also contain string literals (delimited by double quotes). A comment delimiter within a string literal doesn't count. Is there any easy way to strip

Re: simplest way to strip a comment from the end of a line?

2008-12-04 Thread rdmurray
On Thu, 4 Dec 2008 at 08:50, Joe Strout wrote: I have lines in a config file which can end with a comment (delimited by # as in Python), but which may also contain string literals (delimited by double quotes). A comment delimiter within a string literal doesn't count. Is there any easy way

Re: simplest way to strip a comment from the end of a line?

2008-12-04 Thread Alan G Isaac
[EMAIL PROTECTED] wrote: from shlex import split split(this is a test #with a comment) ['this', 'is', 'a', 'test', '#with', 'a', 'comment'] split(this is a test #with a comment, comments=True) ['this', 'is', 'a', 'test'] split(this is a '#gnarlier' test #with a

Re: simplest way to strip a comment from the end of a line?

2008-12-04 Thread eric
On Dec 4, 5:15 pm, eric [EMAIL PROTECTED] wrote: On Dec 4, 4:50 pm, Joe Strout [EMAIL PROTECTED] wrote: I have lines in a config file which can end with a comment (delimited   by # as in Python), but which may also contain string literals   (delimited by double quotes).  A comment

Re: simplest way to strip a comment from the end of a line?

2008-12-04 Thread MrJean1
Using rsplit('#', 1) works for lines *with* comments: 'this is a test'.rsplit('#', 1) ['this is a test'] 'this is a test #with a comment'.rsplit('#', 1) ['this is a test ', 'with a comment'] this is a '#gnarlier' test #with a comment.rsplit('#', 1) [this is a '#gnarlier' test , 'with a

Re: simplest way to strip a comment from the end of a line?

2008-12-04 Thread Paul McGuire
Yowza! My eyes glaze over when I see re's like r'(?m)^(?Pdata.*? (.*?.*?)*)(?:#.*?)?$! Here's a simple recognizer that reads source code and suppresses comments. A comment will be a '#' character followed by the rest of the line. We need the recognizer to also detect quoted strings, so that