diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst --- a/Doc/tutorial/introduction.rst +++ b/Doc/tutorial/introduction.rst @@ -253,6 +253,26 @@ This is a rather long string containing\n\ several lines of text much as you would do in C. +There is one subtle aspect to raw strings that is of special concern to Windows +programmers: a raw string may not end in an odd number of ``\`` characters. +This is because the interpreter sees this as an escaped quote character, and so +it does not recognize it as the end of the string:: + + >>> fn = r'C:\this\will\not\work\' + File "", line 1 + fn = r'C:\this\will\not\work\' + ^ + SyntaxError: EOL while scanning string literal + +There are several workarounds for this. One is to use regular strings and +double the backslashes:: + + >>> fn = 'C:\\this\\will\\work\\' + +Another is to add a blank character before the quote and then remove it:: + + >>> fn = r'C:\this\will\work\ '.strip() + Strings can be concatenated (glued together) with the ``+`` operator, and repeated with ``*``::