Kurt McKee

lessons learned in production

Hey there! This article was written in 2009.

It might not have aged well for any number of reasons, so keep that in mind when reading (or clicking outgoing links!).

Look ma, no BeautifulSoup!

Posted 11 June 2009 in listparser

I removed the dependency on BeautifulSoup from listparser and pushed the changes to github.

I'm a big fan of sequences in Python. Don't ask me why, but I think more and more in terms of generator expressions and list comprehensions (especially conditional list comprehensions). Take a look at the following:

xmlurl = attrs[[i for i in attrs.keys() if i.lower() == "xmlurl"][0]]

I wrote this because I needed to extract the xmlUrl attribute no matter how it's capitalized (but if anyone knows of a better way to do that, let me know). I considered using a generator expression, but I can't imagine much in the way of CPU or memory savings. Just for comparison, that code would have looked like this:

xmlurl = attrs[(i for i in attrs.keys() if i.lower() == "xmlurl").next()]

Anyway, the point is that I'm pleased with much of the code so far. The overall architecture feels shaky though, so again, please let me know if you have some great ideas.