not necessarily better, but a fun alternative to consider: http://docs.python.org/2/library/contextlib.html#contextlib.closing