Musings of an anonymous geek

October 26, 2007

Python, regex, and IRC

Filed under: Python,Scripting,Technology — m0j0 @ 8:53 am

So, I’m on IRC a lot. I’m on a lot of channels, too. I’m on more than one Python channel. One scenario in these chans that comes up somewhat often is one in which a user converting from PHP, Perl, Ruby, or whatever walk in and want to get a better understanding of how regex works in Python.

Flaming ensues.

Flaming the flamers is a topic for another blog post, but for some reason, Python users seem to really be resistant to regex. At one point, I actually suggested in one of the larger channels that someone write an article for Python Magazine about the proper use (or non-use) of regular expressions. That was weeks ago now. I got no bites.

So here again, I’ll put this in a very public place and say that if you can get me a proposal for an article that details when to use or not use regex, and how to use them properly when you *should* use them, we will pay you to write that article.

About these ads

1 Comment »

  1. Speaking as someone who “ported” myself (and my employer) from perl to python a couple of years back… I think the big issue is baggage from other environments. For example, it took us a while to stop using

    if re.search(r”\.jpg$”, line): …

    and switch to the more pythonic and readable

    if line.endswith(“.jpg”): …

    That’s just one example, but there are many other cases where you’ve got to step back and realize that the “natural” conversion of some regexp operation into python is a real native function, and not a regexp at all… and if the original perl RE is especially hairy, you owe it to yourself to (1) make it a function (2) give that function a docstring and some test cases!

    So, if I were to write such an article, it wouldn’t *be* a “regexp” article…

    Comment by eichin — October 26, 2007 @ 11:56 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Rubric Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 69 other followers

%d bloggers like this: