cookbook's not an easy grep but: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303060 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303279 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347689