This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Error creating a raw string of r'\\?\'
Type: compile error Stage:
Components: Interpreter Core Versions: Python 3.2, Python 3.3, Python 2.6
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: John.Jefferies, pitrou, tim.peters
Priority: normal Keywords:

Created on 2013-07-21 18:54 by John.Jefferies, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg193462 - (view) Author: John Jefferies (John.Jefferies) Date: 2013-07-21 18:54
I'm having trouble with a raw string of r'\\?\' as in the following session:
----------------
>>> a = r'\\?\'
  File "<stdin>", line 1
    a = r'\\?\'
              ^
SyntaxError: EOL while scanning string literal
----------------

which seems like a bug to me. I see the same behaviour in v3.3, v3.2, and v2.6. I have tried searching for such a bug but search engines don't work well with a string of non-alphanumerics.

Why is this string important? It's because the Win32 API functions throw an error with path names longer than 260 chars unless the path names are prefixed with this string, e.g:
    shutil.copy2(r'\\?\C:\some\quite\long\path\name', dstname)
    shutil.copy2(r'\\?\' + r'C:\some\quite\long\path\name', dstname)

where the first example throws an exception without the path name prefix; while the second example fails to compile.

FTR. I can create the desired string in various other ways:
----------------
>>> a = '\\\\?\\'
>>> a
'\\\\?\\'
>>> a = r'\\?\ '[0:4]
>>> a
'\\\\?\\'
>>>
----------------

Thanks

John
msg193463 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2013-07-21 19:10
As section 2.4.1. (String literals) of the Python reference manual says, 

"... (even a raw string cannot end in an odd number of backslashes). Specifically, a raw string cannot end in a single backslash (since the backslash would escape the following quote character)."
msg193465 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-07-21 19:39
Indeed, you'll have to use a regular (non-raw) string literal for everything ending up with a backslash. This part of Python's syntax probably won't be changed.
msg193466 - (view) Author: John Jefferies (John.Jefferies) Date: 2013-07-21 19:58
Yes, thankyou; I missed that. Another search reveals the issue has come up under 11451 and 1271 at least.

John
History
Date User Action Args
2022-04-11 14:57:48adminsetgithub: 62722
2013-07-21 19:58:54John.Jefferiessetmessages: + msg193466
2013-07-21 19:39:54pitrousetstatus: open -> closed

nosy: + pitrou
messages: + msg193465

resolution: wont fix
2013-07-21 19:10:23tim.peterssetnosy: + tim.peters
messages: + msg193463
2013-07-21 18:54:41John.Jefferiescreate