Monday, July 23, 2007

Idiomatic Python

I parked Razz near Hollywood and took the Max to the Portland Convention Center. Two geek circuses are already in full swing, so I'm walking around with two badges, two bags with bling.

Now I'm in Code Like a Pythonista: Idiomatic Python by David Goodger, who works in the financial sector, which explains all these (portfolio, equity, position) examples, in addition to the more typical Monty Python based ones, as in:

>>> given = ['John','Eric','Terry','Michael']
>>> family = ['Cleese','Idle','Gilliam','Palin'].
>>> pythons = dict(zip(given, family))

Although the content is very basic, I'm finding it of excellent quality. Safe to say: some of these idioms won't survive into Python 3, but mostly he's encouraging good habits. For example, given the 'in' operator works on so many collections, use 'key in dict' not dict.has_key(). Be less idiosyncratic, i.e. when possible use the more common pattern versus the too special case.

Hey, collections.defaultdict is a pretty cool tool. maybe using int as a factory function, though note you won't get any "no key" errors (it'll just create a new one).

I surprised myself this morning, what with all the switching among laptops and cases: not until I got to the conference room did I realize I was lugging the Toshiba, not the Dell, meaning I'm in Windows, not Ubuntu at the moment.

Good chat with Lars Lohn, now contracting with OSDL on the OLPC project. I hope he introduces me to Justin, a project leader and student, also speaking next session. Lars and I remembered each other from our conversations two years ago. I also met up with my old Plone friend "fifer" (Richard Amerman), plus encountered Kevin Turner (FreeGeek) in the Ubuntu Zone, where I am now.

Maybe I'll finally hook up with Don this evening? S'been a tad hectic since getting back from Lithuania. Tara is still count down for lift off. Hey Nick, leave voice mail if you want me to get back to you. I'm unresponsive to simple vibrations.