[Python-ideas] PEP 8: raw strings & regular expressions
Ned Batchelder
ned at nedbatchelder.com
Fri Oct 23 14:40:29 EDT 2015
On 10/22/15 6:56 PM, Yury Selivanov wrote:
> In principle, there is no reason why *both* of these groups
> of users can't use one tool and be happy. I propose to
> establish a convention in PEP 8, explaining that, while both
> literals are semantically equivalent,
>
> - r'..' strings *should* be used for regexps,
>
> - R'..' strings *should* be used for unstyled raw strings,
>
> and tools *should* treat them as such.
>
> All of this is merely about codifying the current status quo.
But you are not codifying the status quo. The distinction you are
proposing is one that you have invented. I have never used R"" strings.
I think the best solution to the problem is to improve the highlighters,
and luckily you have written one! To me, it is clear which of these
strings is the regex:
r"\d+"
r"\dir"
If the highlighters tried some heuristics, they could do a better job
"being helpful" by making better guesses about the meaning of programs.
I don't mind when highlighters make wrong guesses, as long as they don't
ruin the entire rest of the file. But better guesses will be better. :)
--Ned.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151023/89a012cf/attachment-0001.html>
More information about the Python-ideas
mailing list