[issue21283] A escape character is used when a REGEXP is an argument of "strip" string function

Eric V. Smith report at bugs.python.org
Thu Apr 17 16:50:33 CEST 2014


Eric V. Smith added the comment:

In addition, you probably want "\\server\path\to" to be a raw string, too. That way, the backslashes are not given special meaning. Notice the difference in output between these two:

>>> "\\server\path\to".strip(r'"\'<>') 
'server\\path\to'
>>> r"\\server\path\to".strip(r'"\'<>') 
'server\\path\\to'

In the first one, '\t' is being treated as a tab character, in the second one you see a backslash followed by a 't'.

My rule of thumb is: any time you have a string with a filename containing backslashes, you want it to be a raw string.

----------
components:  -Regular Expressions
nosy: +eric.smith
resolution:  -> not a bug
stage:  -> committed/rejected
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21283>
_______________________________________


More information about the Python-bugs-list mailing list