python

Python one-liner of the day

Paul Bissex
This is a function that takes an integer and returns its ordinal representation, e.g. “1st” for 1 and so on. It’s not the most readable thing, but once I saw the pieces falling into place I couldn’t help myself. Repetition of the “th” literal is the only thing that bugs me. Oh well. ord_text = lambda n: "%d%s" % (n, "th" if 10 < n % 100 < 14 else {1:"st", 2:"nd", 3:"rd"}.

How not to advocate via Google Code

Paul Bissex
People sure are excited about the Google App Engine. Especially people who have some other favorite language besides Python. A significant number of the issue tracker items are of the form “Please add support for $MY_LANGUAGE”, where $MY_LANGUAGE might be VB.NET, C#, PHP, Java, Groovy, Ruby, Perl, etc. ad nauseam. I’m not going to comment on the language-wars aspect. But if you want your language supported (this goes for any issue in the tracker in fact), the thing to do is not to go to one of those issue pages and add a comment that consists of “+1”.

99 problems

Paul Bissex
There is a classic set of programming exercises called “Ninety-Nine Prolog Problems”. Though somewhat tailored to logic programming, they form an interesting set of exercises for other languages. I’ve seen adaptations of varying completeness for Haskell, Lisp, Perl 6, and Python. I was reminded of this all by a recent blog post by some bloke called Dave who was using the problems as a way to become more familiar with Python.

Django Mercurial mirror tweaks

Paul Bissex
Update: The mirror described in this post has been retired. Django source now lives on GitHub. I really enjoyed my participation in the last Django sprint, but prior commitments prevent me from participating in the PyCon Django sprint that begins today. On the chance that people may be taking advantage of my Mercurial mirror of the Django repository, I made a couple tweaks: Increased the update frequency from hourly to every 15 minutes Added downloadable gzipped tarballs (about 2.

From PHP to Python

Paul Bissex
A former colleague from my days in print design (and a wonderfully loyal reader of my blog to boot) writes to ask whether he should learn Python. He’s a smart guy with a deep background in typography, publishing, and the Mac. He is not a programmer by trade, but has taught himself enough PHP to build a custom CMS for his newspaper. He writes: I’ve invested so much time in PHP, and am quite proficient now (not bad for it being more of an avocation), but I respect your opinion and for a long time have wondered about switching.