classification
Title: Add discussion of trailing backslash in raw string to tutorial
Type: enhancement Stage: needs patch
Components: Documentation Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: QuantumTim, docs@python, eli.bendersky, ezio.melotti, facundobatista, georg.brandl, gwideman, r.david.murray, v+python
Priority: normal Keywords: patch

Created on 2011-03-13 03:10 by r.david.murray, last changed 2014-09-27 16:38 by r.david.murray.

Files
File name Uploaded Description Edit
tutorial-raw-string.patch r.david.murray, 2011-03-13 03:10 review
Messages (8)
msg130720 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-03-13 03:10
Here is a proposed addition to the tutorial noting the problem with using raw strings for windows paths and how to work around it.
msg130727 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-03-13 06:49
Would it not be better to just recommend Windows users not to put that last backslash in at all? IIUC it's only needed to later append file names to directory names, but that's better achieved with os.path.join
msg130739 - (view) Author: Graham Wideman (gwideman) Date: 2011-03-13 12:36
Eli:  Excellent and thoughtful point. This would indeed be exactly the place to suggest os.path.join as an alternative.

In addition, there are still occasions where one needs to form a string with trailing backslash. Two examples:
1. When writing the string specifying root directory: r'C:\ '[:-1]
2. Using python to prepare command lines to run other command line programs, where an argument may require a final backslash to explicitly specify a target directory (as opposed to a file).
msg130742 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-03-13 12:52
I would rephrase:
+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.

to something like:
+There is one subtle aspect to raw strings: a raw string may not end in
+an odd number of ``\`` characters.  That is of special concern while
+dealing with Windows paths.

Otherwise it seems that this problem only affects raw strings on Windows.
msg130743 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-03-13 13:17
> Ezio Melotti <ezio.melotti@gmail.com> added the comment:
>
> I would rephrase:
> +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.
>
> to something like:
> +There is one subtle aspect to raw strings: a raw string may not end in
> +an odd number of ``\`` characters.  That is of special concern while
> +dealing with Windows paths.
>
> Otherwise it seems that this problem only affects raw strings on Windows.
>

I agree, but I'd also say something about os.path.join when mentioning
Windows paths, because the vast majority of problems that require the
trailing backslashes can be solved with it.
msg130744 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-03-13 14:22
That would of course be a good addition too.
msg130748 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-03-13 15:29
Well, the problem with both [:-1] and os.path.join is that they are inappropriate for that section of the tutorial.  I considered putting the discussion later in the section so that I could use [:-1] (which hasn't been introduced at that point), but it made the flow even worse than adding the text where I did.  I suppose the os.path.join could be put in if the sentence was short and cross referenced the library docs rather than going into a detailed example.
msg227698 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-09-27 16:38
I'm on a quest to clear my 'commit ready' queue.  This issue needs to go back to 'needs patch' stage...I'll leave it to someone else to rewrite my original patch based on the feedback, since it is unlikely I will get back to it any time soon.  I'll commit it if someone else does the revision and moves it back to commit review, though ;)
History
Date User Action Args
2014-09-27 16:38:30r.david.murraysetstage: commit review -> needs patch
messages: + msg227698
versions: + Python 3.5, - Python 3.2, Python 3.3
2013-03-14 07:39:57ezio.melottisetstage: patch review -> commit review
2012-11-08 10:39:16serhiy.storchakasettitle: Add discussion of trailing slash in raw string to tutorial -> Add discussion of trailing backslash in raw string to tutorial
2012-11-08 08:31:54ezio.melottisettype: behavior -> enhancement
versions: + Python 3.4, - Python 3.1
2011-03-13 15:29:05r.david.murraysetnosy: georg.brandl, facundobatista, QuantumTim, ezio.melotti, v+python, r.david.murray, eli.bendersky, docs@python, gwideman
messages: + msg130748
2011-03-13 14:22:50ezio.melottisetnosy: georg.brandl, facundobatista, QuantumTim, ezio.melotti, v+python, r.david.murray, eli.bendersky, docs@python, gwideman
messages: + msg130744
2011-03-13 13:21:28SilentGhostsetfiles: - unnamed
nosy: georg.brandl, facundobatista, QuantumTim, ezio.melotti, v+python, r.david.murray, eli.bendersky, docs@python, gwideman
2011-03-13 13:17:16eli.benderskysetfiles: + unnamed

messages: + msg130743
nosy: georg.brandl, facundobatista, QuantumTim, ezio.melotti, v+python, r.david.murray, eli.bendersky, docs@python, gwideman
2011-03-13 12:52:17ezio.melottisetnosy: + ezio.melotti
messages: + msg130742
2011-03-13 12:36:02gwidemansetnosy: georg.brandl, facundobatista, QuantumTim, v+python, r.david.murray, eli.bendersky, docs@python, gwideman
messages: + msg130739
2011-03-13 06:49:09eli.benderskysetnosy: + eli.bendersky
messages: + msg130727
2011-03-13 03:10:02r.david.murraycreate