Beautiful Python

February 1st, 2008 § 4 comments

Another ques­tion for the ‘web — what’s the “best” python code you’ve seen — and I don’t mean things like gra­tu­itous use of list comps and lam­bas. I’m ask­ing for more what module/tool/code have you seen that dis­plays all of python’s best attrib­utes — read­abil­ity, sim­plic­ity, power cou­pled with excel­lent pro­gram­ming prac­tices, i.e: docs, tests, PEP8 com­pli­ance, etc?

Obvi­ously, what con­sti­tutes “beau­ti­ful code” varies for peo­ple — some peo­ple get their hap­pi­ness from writ­ing obfus­cated code, oth­ers find any­thing involv­ing more than one line of code an affront to their deity.

Given that code is more often read than writ­ten: What code do you like read­ing the most?

as a side note: I was mak­ing an anal­ogy that houses are like code bases — filled with cre­ative engi­neer­ing, latent defects, etc to Brett, and rhetor­i­cally asked “but how many code bases have toi­lets”. Brett had an answer: Accord­ing to Google code, about 7000.

  • http://billmill.org Bill Mill

    I loved read­ing Pyblox­som 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’ beau­ti­ful. A very tiny core with just the right hooks for plugins.

  • http://pyblog.drbrett.ca Brett

    I remem­ber when the heapq mod­ule was first writ­ten and real­iz­ing it was really nice. And string.Template was the first use of meta­classes where I real­ized meta­classes can be use­ful for “nor­mal” stuff and not overly complicated.

  • http://www.szakmeister.net/ John Sza­k­meis­ter

    One of my favorite pieces of code is the Trac core. It’s only a cou­ple hun­dred lines, but in it lies every­thing to cre­ate com­po­nents and extend them with inter­faces in a very loosely-coupled way. Sim­ply beau­ti­ful, and one of the best uses of meta­classes that I have seen.

  • http://www.szakmeister.net/ John Sza­k­meis­ter

    One of my favorite pieces of code is the Trac core. It’s only a cou­ple hun­dred lines, but in it lies every­thing to cre­ate com­po­nents and extend them with inter­faces in a very loosely-coupled way. Sim­ply beau­ti­ful, and one of the best uses of meta­classes that I have seen.

What's this?

You are currently reading Beautiful Python at jessenoller.com.

meta