Skip to content

Conversation

MaxGyver83
Copy link

Use raw strings to get rid of these warnings:

$ python vim-plugins-profile.py
/tmp/vim-plugins-profile.py:105: SyntaxWarning: invalid escape sequence '\d'
  matches = re.findall("^\d+.\d+\s+\d+.\d+\s+\d+.\d+: "
/tmp/vim-plugins-profile.py:132: SyntaxWarning: invalid escape sequence '\d'
  matches = re.findall("^\d+.\d+\s+\d+.\d+\s+(\d+.\d+): "
/tmp/vim-plugins-profile.py:151: SyntaxWarning: invalid escape sequence '\d'
  matches = re.findall("^\d+.\d+\s+\d+.\d+\s+(\d+.\d+): "
Running vim to generate startup logs... done.
...

The solution is to use Python’s raw string notation for regular expression patterns; backslashes are not handled in any special way in a string literal prefixed with 'r'. So r"\n" is a two-character string containing '\' and 'n', while "\n" is a one-character string containing a newline. Usually patterns will be expressed in Python code using this raw string notation.

re — Regular expression operations — Python 3.13.0 documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant