warnings.warn()与logging.warning() [英] warnings.warn() vs. logging.warning()

查看:33
本文介绍了warnings.warn()与logging.warning()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

warnings.warn() logging.warn() 关于它们的用途以及应如何使用?

What is the difference between warnings.warn() and logging.warn() in terms of what they do and how they should be used?

推荐答案

一个引发异常,可以根据需要捕获或忽略该异常,另一个根据当前日志记录级别将一个条目添加到日志中.当一个警告有关代码中的各种内容时,应使用一种,而在登录时应使用另一种.

One raises an exception which can be caught or ignored as desired, and the other optionally adds an entry to the log based on the current logging level. One should be used when one is warning about various things in code, and the other should be used when logging.

这篇关于warnings.warn()与logging.warning()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆