Pep8 for long pattern

Michael Torrie torriem at gmail.com
Tue Mar 27 11:18:38 EDT 2018


On 03/27/2018 08:17 AM, Ganesh Pal wrote:
> Hello Python friends,
> 
> How do I split the below regex , so that it fits within the  character
> limit of 79 words
> 
> 
> pattern =  [
> r'(?P<p_owner>([0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+::HEAD))',
> 
> r'(?P<a_owner>(owner:\s+[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+::HEAD))',
>                 '.']
> 
> I am using Python 2.7 + Linux

I like Serhiy's idea of using fixed number repetition to shorten the
expressions and make them more readable.  Now it could be that in
general a long regular expression is a bad idea (maybe a simple split()
is the way to go instead).  But when it's exactly what you need, why do
you need to shoehorn the expression into 79 characters?  Seems pointless
in a case like this. PEP8 is a guideline, not an absolute rule.  It's
okay to bend it a bit in cases like this.



More information about the Python-list mailing list