[Python-ideas] PEP 8: raw strings & regular expressions

Rob Cliffe rob.cliffe at btinternet.com
Thu Oct 22 05:41:44 EDT 2015



On 22/10/2015 08:44, Terry Reedy wrote:
> On 10/21/2015 10:24 PM, Yury Selivanov wrote:
>> Hi,
>>
>> I was a little bit frustrated that Sublime Text and Atom didn't support
>> all Python 3 features (mainly annotations & async/await syntax), so I
>> decided to write a new highlighter:
>>
>>      https://github.com/MagicStack/MagicPython
>>
>> In the process, we had to make a decision on how to highlight raw string
>> literals -- r''.  Many existing highlighters assume that all raw strings
>> are regexps, and highlight them as such, i.e. '\s' and '\n' will be
>> highlighted.
>
> What 3rd parth editors do is their business.
>
>> I think that it might be a good idea to state the following in PEP 8:
>>
>> - use r'...' strings for raw strings that describe regular expressions;
>> these strings might be highlighted specially in some editors.
>>
>> - use R'...' strings for raw strings; editors *should not* highlight
>> any escaped characters in them.
>>
>> What do you think?
>
> I think it a bad idea.  For beginners on Windows, 
> r'windows\path\file.py' might be more common than r're'.  I have never 
> seen R used.
>
> If you wanted to promote the use of the currently rare R for REs, and 
> have editors specially mark raw literals with this special prefix, I 
> would not mind.
>
+1.  I may or may not be typical, but I use regular expressions very rarely.
Rob Cliffe.


More information about the Python-ideas mailing list