Beautiful Python

Another question for the ‘web – what’s the “best” python code you’ve seen – and I don’t mean things like gratuitous use of list comps and lambas. I’m asking for more what module/tool/code have you seen that displays all of python’s best attributes – readability, simplicity, power coupled with excellent programming practices, i.e: docs, tests, PEP8 compliance, etc?

Obviously, what constitutes “beautiful code” varies for people – some people get their happiness from writing obfuscated code, others find anything involving more than one line of code an affront to their deity.

Given that code is more often read than written: What code do you like reading the most?

as a side note: I was making an analogy that houses are like code bases – filled with creative engineering, latent defects, etc to Brett, and rhetorically asked “but how many code bases have toilets”. Brett had an answer: According to Google code, about 7000.

  • One of my favorite pieces of code is the Trac core. It's only a couple hundred lines, but in it lies everything to create components and extend them with interfaces in a very loosely-coupled way. Simply beautiful, and one of the best uses of metaclasses that I have seen.
  • I remember when the heapq module was first written and realizing it was really nice. And string.Template was the first use of metaclasses where I realized metaclasses can be useful for "normal" stuff and not overly complicated.
  • llimllib
    I loved reading Pybloxsom back in the day, even though the low-level code was often pretty bad, because the high-level design of it was just so stinkin' beautiful. A very tiny core with just the right hooks for plugins.
blog comments powered by Disqus