csev/py4e

11-regex- ex2 peek problem in VS Code

Atomx3 opened this issue · 1 comments

Dear Chuck,

I am doing exercise 2 on
https://www.py4e.com/html3/11-regex

I found my VS Code peek problem noticed that:
Anomalous backslash in string: '\s'. String constant might be missing an r prefix.pylint(anomalous-backslash-in-string)

but it's no problem to run my code.

import re
hand = open('mbox-short.txt')
for line in hand:
    line = line.rstrip()
    if re.search('^N.*\s.*: [0-9.]+', line):
        print(line)

then I add 'r' before '^N', no peek problem error anymore, what's the problem I should solve ?

r in r'^N.*\s.*: [0-9.]+' tells Python use the following string directly, rather translate the \s first.