Rob Cliffe wrote:
>
Your docs link states "... they allow you to pass on the string quote
> character by escaping it with a backslash."
>
>
I don't have access to a Python 3 version right now, but that is not
> true in Python 2:
> [snip]
The behavior is the same on Python 3.8.2:
Python 3.8.2 (default, Feb 26 2020, 22:21:03)
[GCC 9.2.1 20200130] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> r'x\'y'
"x\\'y"
>>> list(_)
['x', '\\', "'", 'y']
What is unclear to me (regarding the quoted line from the Design FAQ) is that backslashes can be used in normal strings
to properly escape the same quote type without the above issue:
>>> 'x\'y'
"x'y"
>>> list(_)
['x', "'", 'y']
Perhaps the "they" is intended to mean something other than "raw strings". Based on the context, I think "they" might be instead referring to the previously mentioned text processors (such as regex engines). As in "In return, [those processors] allow you to pass on the string
quote character by escaping it with a backslash". Or perhaps the above behavior wasn't always the case. Either way, I think that part of the Design FAQ could benefit from an update to make that more clear, I can see how the current wording could be a bit ambiguous.
Unless I'm mistaken about the intended meaning, the above fix could make for a decent "newcomer friendly"/easy issue. I can open an issue on
bugs.python.org for someone else to work on as a first PR; it would be a very straightforward (but still helpful) trivial fix.