Unrecognized backslash escapes in string literals

Serhiy Storchaka storchaka at gmail.com
Mon Feb 23 05:14:08 EST 2015


On 23.02.15 04:55, Chris Angelico wrote:
> I agree, the fault is primarily with Windows. But I've seen similar
> issues when people use /-\| for box drawing and framing and such;
> Windows paths are by far the most common case of this, but not the
> sole.

There is also issues with regular expressions.

 >>> import re
 >>> re.match(r'a\s', 'a ')
<_sre.SRE_Match object; span=(0, 2), match='a '>
 >>> re.match('a\s', 'a ')
<_sre.SRE_Match object; span=(0, 2), match='a '>
 >>> re.match(r'a\b', 'a ')
<_sre.SRE_Match object; span=(0, 1), match='a'>
 >>> re.match('a\b', 'a ')

Oops.

'a\s' works the same as r'a\s', but 'a\b' works different from r'a\b'.




More information about the Python-list mailing list