Original Timestamp: 2014-02-18 20:48:13.659576
From: http://stackoverflow.com/questions/7108193/frequently-repeated-try-except-in-python …The best way to abstract exception handling is with a context manager: from contextlib import contextmanager @contextmanager def common_handling(): try: yield finally: # whatever your common handling is then: with common_handling(): os.remove(‘/my/file’) with common_handling(): os.chmod(‘/other/file’, 0700)
%d bloggers like this: