Get the App
SLTechnology News&Howtos  ›  Development  › 

How python uses with to ignore exceptions

Shulou Source: shulou.com Published: 2022-06-01 04:08:30 09月22日 Update

This article will explain in detail how python uses with to ignore anomalies. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Ignore exceptions using with (Python 3 only)

# # do not recommend try:os.remove ("somefile.txt") except OSError:pass## recommend from contextlib import ignored # Python 3 onlywith ignored (OSError): os.remove ("somefile.txt") this article on "how to use with to ignore anomalies in python" ends here. I hope the above content will be helpful to you so that you can learn more knowledge. If you think the article is good, please share it for more people to read.

Tags: Articles more recommendations good practical content articles knowledge reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Tech Info MySQL Docker MariaDB