Python Line Noise

Perl gets flack because it is such a good language for managing and using regular expressions. The reality is that anyone who uses regular expressions will write code that some will use the pejorative “line noise” against.

To drive the point home, look up “python one liner” on Google. The first hit will contain this gem:

    [dict(re.compile('(?s)([^\n:] ): (.*?)(?=\n[^ \t]|\Z)').findall(item))       for item in s.split('\n\n')]  

Looks like line noise to me!

And, yes, Perl’s implicit variables and use of regular expressions in the language core make the equivalent slightly shorter:

    [{/(?s)([^\n:] ): (.*?)(?=\n[^ \t]|\Z)/g}      for split("\n\n")]  

Note, though, that the “line-noise” portion of the code is practically identical.

Regular expressions are a little language that you can use in lots of places. I think the above example shows the truth of this statement. Don’t let people scare you off of them. Don’t be scared by them. Learn them and love them.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.