regex line by line over file

Peter Pearson ppearson at nowhere.invalid
Thu Mar 27 16:49:02 CET 2014


On Thu, 27 Mar 2014 06:41:55 -0700 (PDT), James Smith wrote:
> On Thursday, March 27, 2014 1:32:03 AM UTC-4, Steven D'Aprano wrote:
>
>> - are you mistaken about the content of the file?
>> 
>> I can't help you with the first. But the second: try running this:
>> 
>> # line2 and pat as defined above
>> filename = sys.argv[1]
>> with open(filename) as f:
>>     for line in f:
>>         print(len(line), line==line2, repr(line))
>>         print(repr(pat.match(line)))
>> 
>> which will show you what you have and whether or not it matches 
>> what you think it has. I expect that the file contents is not what 
>> you think it is, because the regex is matching the sample line.
>> 
>> Good luck!
>> 
>> -- 
>> 
>> Steven
>
> It should match this:
> (134, False, '\'   "SHELF-17:LOG[snip]MODE=NONE"\\r\\n\'')
>
> Is the \r\n on the end of the line screwing it up?

Dude, you've gotten a lot of excellent advice from some extraordinarily
capable (and patient) people, and you appear to be ignoring it.


-- 
To email me, substitute nowhere->spamcop, invalid->net.



More information about the Python-list mailing list