[Python-Dev] Re: What to do about invalid escape sequences

2019年8月09日 15:30:18 -0700

On 8/9/2019 2:53 PM, Steven D'Aprano wrote:
On Fri, Aug 09, 2019 at 01:12:59PM -0700, Glenn Linderman wrote:
The reason I never use raw strings is in the documentation, it is
because \ still has a special meaning, and the first several times I
felt the need for raw strings, it was for directory names that wanted to
end with \ and couldn't.
Can you elaborate? I find it unlikely that I would ever want a docstring
I didn't mention docstring. I just wanted a string with a path name ending in \.
that ends with a backslash:
 def func():
 r"""Documentation goes here...
 more documentation...
 ending with a Windows path that needs a trailing backslash
 like this C:\directory\"""
That seems horribly contrived. Why use backslashes in the path when the
strong recommendation is to use forward slashes?
Windows users are used to seeing backslashes in paths, I don't care to be the one to explain why my program uses / and all the rest use \.
And why not solve the problem by simply moving the closing quotes to the
next line, as PEP 8 recommends?
 r"""Documentation ...
 C:\directory\
 """
This isn't my problem, I wasn't using docstrings, and including a newline in a path name doesn't work. I suppose one could "solve" the problem by using
"c:\directory\ "[ :-1]
but that is just as annoying as
"c:\\directory\\"
and back when I discovered the problem, I was still learning Python, and didn't think of the above solution either.
[...]
Even in a raw literal, quotes can be escaped with a backslash
Indeed, they're not so much "raw" strings as only slightly blanched
strings.
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/EHE2CNRDGS6AF6GYO4DX7UNNE24JH6CG/

Reply via email to