Tim Hatch

Weblog | Photos | Projects | Panoramas | About

PyCon is coming up 20 Feb, 2009

The Early Bird deadline for PyCon is coming up tomorrow. I’ll be there for the talks and sprint days working on improving the ability to run tests on Trac, hopefully improving some error messages in Python core, and maybe writing a new testing tool.

If you’re going, and you read this, let me know by email so we can meet up.

Santa Barbara Python Users Group 14 Feb, 2009

I’m organizing a Python group here, welcoming programmers of all skill levels. Our next meeting will be the first Wednesday in March — sign up for the Google Group if interested in being notified.

Underscore lambda in Python 14 Feb, 2009

After using Scala for a number of Project Euler problems, Python’s lambda syntax looks way too verbose. Trying to simplify it:

def call(func, *args):
    def wrap(item):
        return getattr(item, func)(*args)
    return wrap

def call_argslater(func):
    def setargs(*args):
        def wrap(item):
            return getattr(item, func)(*args)
        return wrap
    return setargs

inputs = [" abc ", "def "]

print map(lambda x: x.strip(), inputs)
print map(call("strip"), inputs)
print map(call("split", "b"), inputs)

That’s just the first step, those functions (very similar to decorators) can then be wrapped in an object:

class Underscore(object):
    def __getattr__(self, attr):
        return call(attr)

_ = Underscore()

print map(_.strip, inputs)

The downside is that without examining the call stack, it can’t tell if the args are in the initial use or the subsequent calls from within map, so you’d need two different underscore objects (one with args, one without).

Have a way to improve this? Please email me (code@timhatch.com)

My new favorite error message 09 Feb, 2009

I ran across this error trying to run a very short Ruby program earlier. It takes the cake for being informative yet entirely confounding at the same time.

example.rb:11: syntax error, unexpected $end, expecting kEND

Turns out $end means EOF and kEND means the word "end" that you have to count in your head. Turns out I had forgotten to close one, half a dozen lines earlier and had to trace to make sure the indents matched what the code was actually doing. </pythonista-rant>

Extracting Files from boot disk Scripts 09 Feb, 2009

I wrote some quick and dirty code this morning to help with getting PCNTPCI5.SYS extracted. I haven't tried it on any files besides that one... here you go.

Inside of Space Mountain 07 Feb, 2009

When I was riding the Space Mountain roller coaster last year, it stopped with people still in the ride. I was impressed at the braking areas, which are all at areas of high potential so a slight shove gives you enough momentum to make it through the rest of the ride. They let us all have a second run, and I think it was more enjoyable the second time through, knowing how small and twisted it actually is. I have a whole album of photos swiftly taken during the stop.