Posts tagged: PYTHON

Bicycle Repair Man bundle for TextMate

Look! For a long time I’ve wanted to try working with Bicycle Repair Man, the Python refactoring tool. Unfortunately, the fact that it had neither documentation nor integration with my favorite editor kept pushing it to the back burner.

About a month ago I was excited to come across a post from a guy named David Coffin who had created a BRM integration script for TextMate. I hooked it up per his instructions, and with a little fiddling I got it working. The first thing I tried was the Extract Method or Function command. I had code something like this (structurally, I mean):

Two new Django-powered sites

One of the neat things about PyCon, even for those of us who aren’t attending, is that people save up goodies to announce and release during the conference. Django is certainly a hot topic at this year’s PyCon, and as of today at least two significant new Django-based sites have launched:

One is CheeseRater (great name!), from Jacob Kaplan-Moss, a quick-rating system for items in the Python community’s official package index, the Cheeseshop. In other words, if you think PyOMFG is the greatest module ever you can vote it up, and if you notice that PyFlockOfSeagulls hasn’t been updated since 1992 you can vote it down. The Cheeseshop is one of several pieces of python.org that I’ve thought could benefit from the application of some crowd wisdom; Jacob gets a prize for taking action. It will be interesting to see how this evolves.

Neat Python hack: infix operators

I came across this neat Python hack on reddit today, a technique for defining arbitrary infix operators. Not overriding + or >> et al., but creating keyword-style pseudo-operators that… well, the code is probably as clear as any description I could come up with:

class infix(object):
    """
    Clever hack (slightly modified) for defining infix operators. 
    Via http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122
    Intended for use as a decorator.
    
    >>> @infix
    ... def removing(str, chars):
    ...     for char in chars:
    ...         str = str.replace(char, '')
    ...     return str
    ...
    >>> print 'Hello, world!' |removing| 'eo'
    Hll, wrld!
    """
    def __init__(self, function):
        self.function = function
    def __ror__(self, other):
        return infix(lambda x: self.function(other, x))
    def __or__(self, other):
        return self.function(other)
    def __call__(self, value1, value2):
        return self.function(value1, value2)

Some people hate this kind of stuff. That’s why we call it a hack, to indicate that we don’t think it’s a great building block for your missile control software. Some of Those People still get their underoos in a bunch regardless. But you have to admit it’s damned clever.

Dreaming In Code: The Interview

Dreaming in Code Over on the Well we’re having a discussion with Salon.com co-founder (and longtime Well member) Scott Rosenberg about his new book, Dreaming in Code. The book follows the Chandler project – conceived as a radical reinvention of the personal information manager – from its inception in 2002 through… well, through multiple stalls and restarts that lead not to a triumphal “Rocky of software” finish but to our embedded journalist moving on after deciding he just can’t wait any longer. Oddly, this a more satisfying ending; more honest, more interesting, and, for most programmers, more painfully familiar. It’s a postmortem on a project that hasn’t actually died.

The whitespace brigade

Syntactically significant whitespace is one of those debating points frequently raised in unproductive language thrashes involving Python. One persistent implication made by SSW-haters is that it’s a freakish mutation unique to Python. Or, if they’re feeling particularly vicious, they’ll bring up Fortran. Cold comfort.

In fact, there are quite a few other languages that have gone down this path. Flipping through a big fat book that I bought because Steve Yegge recommended it, I came across mention of a couple that were new to me. Then I went digging for more. Here’s an incomplete list:

Python 2.5 Library Reference for Plucker

I’ve created an updated Plucker version of the Python Library Reference for Python 2.5. It weighs in at 1.7MB, a bit fatter than the last one mostly because I tweaked the spidering depth to keep deeply nested pages from being skipped. All twelve of you who have an interest in such a thing can find it here: