bpo-11479: Added a discussion of trailing backslash in raw string to tutorial#27949
bpo-11479: Added a discussion of trailing backslash in raw string to tutorial#27949dancinglightning wants to merge 6 commits intopython:mainfrom
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
|
|
||
| Another is to add a blank character before the quote and then remove it:: | ||
|
|
||
| >>> fn = r'C:\this\will\work\ '.strip() |
There was a problem hiding this comment.
Personally I wouldn't mention this one -- it adds a runtime cost if it's inside some loop or function call, which on its own isn't a huge deal, but it also means you get unexpected behavior if you don't fully realize what this does and try it on r' foo bar \ baz quux\ .
I'd personally leave things with the last workaround (and not mention there are multiple), but if another workaround is desired, using two string literals with the terminal slash in a second one implicitly concatenated is the next-best-one to me:
fn = r'C:\this\will\work' '\\'
There was a problem hiding this comment.
Yeah, I do agree it adds to the runtime but I am pretty sure that this piece of information can be invaluable and many times go unnoticed. I too faced difficulty in comprehending the issue when I got stuck with it. I was able to resolve it later by reading various discussions.
https://bugs.python.org/issue11479