better python error handling