How python uses with to ignore exceptions
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.