
I'll apologize in advance for this one since I suspect a lot of people have hit this. The current implementation doesn't allow for a trailing backslash in the string. Why don't raw strings in Python work more like C# @"..." strings? Then it would allow for a trailing backslash and you could still get a single quote by two consecutive quotes characters. f=r'c:\src\f' # This is ok and gives you what you want f=r'c:\src\f\' # Compilation error. String is not terminated. f=r'''c:\src\f\''' # This doesn't work either and causes a compilation error. f=r'Here''s another mistake' # This doesn't do what you would think. # You get 'Heres another mistake' f=r'''Here's another mistake''' # This works but being able to use raw strings for this would be nice. f='c:\\src\\f\\' # this works but is ugly I just don't understand the rationale for the current implementation. I thought the intention of raw strings was to allow for backslashes in the string. The current implementation does a bad job at it. Any chance this could be changed with a backward compatibility option?

On 1 Oct 2007, at 15:11, Clark Maurer wrote:
It's a FAQ: http://www.python.org/doc/faq/general/#why-can-t-raw-strings-r- strings-end-with-a-backslash -- Arnaud

On 10/1/07, Clark Maurer <cmaurer@slickedit.com> wrote:
The current implementation doesn't allow for a trailing backslash in the string.
I believe that will change in Python 3.0. The discussion is here: http://mail.python.org/pipermail/python-3000/2007-May/007684.html And Ron Adam's current patch is here: http://bugs.python.org/issue1720390 STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

I'm still against actually. That's why the patch hasn't been applied yet. On 10/1/07, Steven Bethard <steven.bethard@gmail.com> wrote:
-- --Guido van Rossum (home page: http://www.python.org/~guido/)

On 10/1/07, Guido van Rossum <guido@python.org> wrote:
I'm still against actually. That's why the patch hasn't been applied yet.
Sorry, my mistake. I read the thread as being somewhat in support of the change. Anyway, to the OP, if you want to make this happen, you should help Ron out with his patch. (Code has a much better chance of convincing Guido than anything else does.) STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

On 10/1/07, Steven Bethard <steven.bethard@gmail.com> wrote:
I admit I've been wobbling a lot on this.
Not in this case. It's more the philosophical distinction -- are raw strings meant primarily to hold regexes or Windows pathnames? These two use cases have opposite requirements for trailing backslash treatment. I know the original use case that caused them to be added to the language is regexes, and that's still the only one I use on a regular basis. -- --Guido van Rossum (home page: http://www.python.org/~guido/)

On Mon, Oct 01, 2007 at 12:53:41PM -0700, Guido van Rossum wrote:
Then just rename them to "regex-strings"; prefix 'r' is stll ok. ;) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.

Oleg Broytmann wrote:
Then just rename them to "regex-strings"; prefix 'r' is stll ok. ;)
But then all the Perl-heads will complain that they don't automatically get compiled into regex objects... -- Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | Carpe post meridiem! | Christchurch, New Zealand | (I'm not a morning person.) | greg.ewing@canterbury.ac.nz +--------------------------------------+

On 10/1/07, Clark Maurer <cmaurer@slickedit.com> wrote:
The current implementation doesn't allow for a trailing backslash in the string.
On 10/1/07, Guido van Rossum <guido@python.org> wrote:
FWLIW, I'm in exactly the opposite boat. I use very few regular expressions that include quotes, and when I do run into one I always use the appropriate quote type so that I don't need to escape the quotes. On the other hand, I write quite a few Windows paths, and probably make the final-backslash mistake once a week. (It's quickly flagged and fixed, but I still make it.) STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

Steven Bethard wrote:
I write quite a few Windows paths, and probably make the final-backslash mistake once a week.
If you were using os.path.join(), as you should be, you wouldn't ever have to write a trailing backslash in a path in the first place. Or any backslashes at all, for that matter. -- Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | Carpe post meridiem! | Christchurch, New Zealand | (I'm not a morning person.) | greg.ewing@canterbury.ac.nz +--------------------------------------+

On 10/1/07, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
Sure, but why would I waste my time with that at the interactive prompt? I'm trying to get something done quickly. I can copy-paste from just about anywhere something like this:: C:\Documents and Settings\...\My Documents\projects\causals\treebank-verb-conj-801-1100.xml If I have to use os.path.join, it'll take me 10 times as long to input it. STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

On Tue, Oct 02, 2007, Greg Ewing wrote:
Wrong. And I just got bitten by this yesterday (no backslashes at all). Consider the difference between cp -a foo bar and cp -a foo/ bar The two are almost identical *except* when foo is a symlink to a directory, then the first form copies the symlink instead of giving a brand-new directory. Which, since foo/ is a template dir that gets modified after copying was a very bad thing. (We moved servers around over the weekend and for convenience's sake made foo a symlink to a new location.) And yes, we *were* using os.path.join(). So trailing slashes (or backslashes) are in fact sometimes required. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information.

On Wed, Oct 03, 2007, Greg Ewing wrote:
Well, it often is. See e.g. man rsync. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information.

On 10/1/07, Guido van Rossum <guido@python.org> wrote:
As for my experience with regexps, the current behavior is only useful when using both single and double quotes in a single regexp string; I can't recall when I last did so. On 10/1/07, Clark Maurer <cmaurer@slickedit.com> wrote:
Two quotes should be one single quote. Otherwise, specifying both quote characters in regexes is an issue.
- Tal

On 10/1/07, Tal Einat <taleinat@gmail.com> wrote:
I think this is the crux of the matter. It's not really about comparing use of regular expressions with use of Windows paths. It's about comparing use of regular expressions *that include both types of quotes* and use of Windows paths. Of course, I don't really know how to perform this sort of comparison on a large scale either. ;-)
Exactly my feeling. Thanks for putting it so clearly. =) STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

On 10/1/07, Steven Bethard <steven.bethard@gmail.com> wrote:
On 10/1/07, Tal Einat <taleinat@gmail.com> wrote:
I have seen regular expressions that look for a double-quoted string which might contain an apostrophe, but don't remember writing one. Other than that, I can't remember *ever* needing to unless I was really (at some level) saying "either of these two"; I also can't remember doing it without being annoyed at having to figure out how many ticks were there, and whether it was double-single or three singles, or what. For me, usability and readability would both improve by offering a named special character, such as \q.
Exactly my feeling. Thanks for putting it so clearly. =)
Agreed. And also from a "what do *I* have to remember", or a "how does this interact when it gets passed to something else" perspective, because it would remove one level of escaping. -jJ

Clark Maurer schrieb: [Others have commented about the no-raw-strings-ending-in-backslash thing.]
f=r'Here''s another mistake' # This doesn't do what you would think. # You get 'Heres another mistake'
This is no mistake, and it won't change. The first single quote ends one string literal, and the second starts another, and they are concatenated in the parsing stage.
f=r'''Here's another mistake''' # This works but being able to use raw # strings for this would be nice.
Actually, this is a raw string too. Georg -- Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out.

Clark Maurer wrote:
That's not *exactly* true. The intention is to allow backslashes that are *being used to escape something*, but are to be interpreted by whatever is using the string, not by Python itself. The original use case was regular expressions, I believe. In that case, there is no need to be able to put a backslash at the end of a string. Your suggestion of doubling quotes would actually interfere with this use case, because currently you can write r"a\"b" and it will be correctly interpreted as a regular expression with an escaped quote in it. Under your scheme, it would have to be written r"a\""b" and then it would no longer be WYSIWYG. -- Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | Carpe post meridiem! | Christchurch, New Zealand | (I'm not a morning person.) | greg.ewing@canterbury.ac.nz +--------------------------------------+

On 1 Oct 2007, at 15:11, Clark Maurer wrote:
It's a FAQ: http://www.python.org/doc/faq/general/#why-can-t-raw-strings-r- strings-end-with-a-backslash -- Arnaud

On 10/1/07, Clark Maurer <cmaurer@slickedit.com> wrote:
The current implementation doesn't allow for a trailing backslash in the string.
I believe that will change in Python 3.0. The discussion is here: http://mail.python.org/pipermail/python-3000/2007-May/007684.html And Ron Adam's current patch is here: http://bugs.python.org/issue1720390 STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

I'm still against actually. That's why the patch hasn't been applied yet. On 10/1/07, Steven Bethard <steven.bethard@gmail.com> wrote:
-- --Guido van Rossum (home page: http://www.python.org/~guido/)

On 10/1/07, Guido van Rossum <guido@python.org> wrote:
I'm still against actually. That's why the patch hasn't been applied yet.
Sorry, my mistake. I read the thread as being somewhat in support of the change. Anyway, to the OP, if you want to make this happen, you should help Ron out with his patch. (Code has a much better chance of convincing Guido than anything else does.) STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

On 10/1/07, Steven Bethard <steven.bethard@gmail.com> wrote:
I admit I've been wobbling a lot on this.
Not in this case. It's more the philosophical distinction -- are raw strings meant primarily to hold regexes or Windows pathnames? These two use cases have opposite requirements for trailing backslash treatment. I know the original use case that caused them to be added to the language is regexes, and that's still the only one I use on a regular basis. -- --Guido van Rossum (home page: http://www.python.org/~guido/)

On Mon, Oct 01, 2007 at 12:53:41PM -0700, Guido van Rossum wrote:
Then just rename them to "regex-strings"; prefix 'r' is stll ok. ;) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.

Oleg Broytmann wrote:
Then just rename them to "regex-strings"; prefix 'r' is stll ok. ;)
But then all the Perl-heads will complain that they don't automatically get compiled into regex objects... -- Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | Carpe post meridiem! | Christchurch, New Zealand | (I'm not a morning person.) | greg.ewing@canterbury.ac.nz +--------------------------------------+

On 10/1/07, Clark Maurer <cmaurer@slickedit.com> wrote:
The current implementation doesn't allow for a trailing backslash in the string.
On 10/1/07, Guido van Rossum <guido@python.org> wrote:
FWLIW, I'm in exactly the opposite boat. I use very few regular expressions that include quotes, and when I do run into one I always use the appropriate quote type so that I don't need to escape the quotes. On the other hand, I write quite a few Windows paths, and probably make the final-backslash mistake once a week. (It's quickly flagged and fixed, but I still make it.) STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

Steven Bethard wrote:
I write quite a few Windows paths, and probably make the final-backslash mistake once a week.
If you were using os.path.join(), as you should be, you wouldn't ever have to write a trailing backslash in a path in the first place. Or any backslashes at all, for that matter. -- Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | Carpe post meridiem! | Christchurch, New Zealand | (I'm not a morning person.) | greg.ewing@canterbury.ac.nz +--------------------------------------+

On 10/1/07, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
Sure, but why would I waste my time with that at the interactive prompt? I'm trying to get something done quickly. I can copy-paste from just about anywhere something like this:: C:\Documents and Settings\...\My Documents\projects\causals\treebank-verb-conj-801-1100.xml If I have to use os.path.join, it'll take me 10 times as long to input it. STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

On Tue, Oct 02, 2007, Greg Ewing wrote:
Wrong. And I just got bitten by this yesterday (no backslashes at all). Consider the difference between cp -a foo bar and cp -a foo/ bar The two are almost identical *except* when foo is a symlink to a directory, then the first form copies the symlink instead of giving a brand-new directory. Which, since foo/ is a template dir that gets modified after copying was a very bad thing. (We moved servers around over the weekend and for convenience's sake made foo a symlink to a new location.) And yes, we *were* using os.path.join(). So trailing slashes (or backslashes) are in fact sometimes required. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information.

On Wed, Oct 03, 2007, Greg Ewing wrote:
Well, it often is. See e.g. man rsync. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information.

On 10/1/07, Guido van Rossum <guido@python.org> wrote:
As for my experience with regexps, the current behavior is only useful when using both single and double quotes in a single regexp string; I can't recall when I last did so. On 10/1/07, Clark Maurer <cmaurer@slickedit.com> wrote:
Two quotes should be one single quote. Otherwise, specifying both quote characters in regexes is an issue.
- Tal

On 10/1/07, Tal Einat <taleinat@gmail.com> wrote:
I think this is the crux of the matter. It's not really about comparing use of regular expressions with use of Windows paths. It's about comparing use of regular expressions *that include both types of quotes* and use of Windows paths. Of course, I don't really know how to perform this sort of comparison on a large scale either. ;-)
Exactly my feeling. Thanks for putting it so clearly. =) STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

On 10/1/07, Steven Bethard <steven.bethard@gmail.com> wrote:
On 10/1/07, Tal Einat <taleinat@gmail.com> wrote:
I have seen regular expressions that look for a double-quoted string which might contain an apostrophe, but don't remember writing one. Other than that, I can't remember *ever* needing to unless I was really (at some level) saying "either of these two"; I also can't remember doing it without being annoyed at having to figure out how many ticks were there, and whether it was double-single or three singles, or what. For me, usability and readability would both improve by offering a named special character, such as \q.
Exactly my feeling. Thanks for putting it so clearly. =)
Agreed. And also from a "what do *I* have to remember", or a "how does this interact when it gets passed to something else" perspective, because it would remove one level of escaping. -jJ

Clark Maurer schrieb: [Others have commented about the no-raw-strings-ending-in-backslash thing.]
f=r'Here''s another mistake' # This doesn't do what you would think. # You get 'Heres another mistake'
This is no mistake, and it won't change. The first single quote ends one string literal, and the second starts another, and they are concatenated in the parsing stage.
f=r'''Here's another mistake''' # This works but being able to use raw # strings for this would be nice.
Actually, this is a raw string too. Georg -- Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out.

Clark Maurer wrote:
That's not *exactly* true. The intention is to allow backslashes that are *being used to escape something*, but are to be interpreted by whatever is using the string, not by Python itself. The original use case was regular expressions, I believe. In that case, there is no need to be able to put a backslash at the end of a string. Your suggestion of doubling quotes would actually interfere with this use case, because currently you can write r"a\"b" and it will be correctly interpreted as a regular expression with an escaped quote in it. Under your scheme, it would have to be written r"a\""b" and then it would no longer be WYSIWYG. -- Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | Carpe post meridiem! | Christchurch, New Zealand | (I'm not a morning person.) | greg.ewing@canterbury.ac.nz +--------------------------------------+
participants (11)
-
Aahz
-
Arnaud Delobelle
-
Clark Maurer
-
Georg Brandl
-
Greg Ewing
-
Guido van Rossum
-
Jacob Holm
-
Jim Jewett
-
Oleg Broytmann
-
Steven Bethard
-
Tal Einat