Tuesday, July 28, 2009

PyCon 2010

PyCon 2010 is going to be in Atlanta. I'm psyched about it coming back to the east coast - no flying for me next year, hooray.

It's been several years since I gave a talk at PyCon. I think it's about time I did that again. One problem I have, though, is that most things I think I'm qualified to talk about are pretty boring. Who really cares about how to use Twisted's HTTP client? Or about how to balance load across a cluster? It's just some library calls.

But I'm going to talk about something, and since I won't be the one listening to the talk, I figure I shouldn't be the one to decide if it's interesting or not. What do you, the PyCon going public, want to hear about? And if you're not sure if you want to go to PyCon next year, what talk would help you make up your mind to go?

Monday, July 27, 2009

Comcast engineers are great spellers

I was checking out Comcast's product offerings tonight and unfortunately ran into a problem they seem to be having. Who knows what the cause is, maybe some of their servers are down, or maybe their JavaScript doesn't support Firefox on Linux. But they could at least spell some words right.

Monday, July 20, 2009

How to define a main entry point into a Python program

Here's a common pattern you'll find in many Python programs:


import some.modules

def ineSomeFunctions():
pass

class Whatever:
pass

def main():
ineSomeFunctions(Whatever())


if __name__ == '__main__':
main()


This works because the global __name__ is set to "__main__" when evaluating the code in the file invoked on the command line. This has a problem, though. It also puts all of those functions and classes into a module named "__main__". Sometimes this isn't an issue, but usually it will become one.

So what should you do instead? This:


if __name__ == '__main__':
import mymodule
raise SystemExit(mymodule.main())

import some.modules

def ineSomeFunctions():
pass

class Whatever:
pass

def main():
ineSomeFunctions(Whatever())


It's probably possible to do even better than this, but even this simple change buys a lot - suddenly no more __main__ wackiness. So, do it this way!