python - warnings.warn() 与 logging.warning()

标签 python logging warnings

warnings.warn() 和有什么区别?和 logging.warn()就它们的作用和应该如何使用而言?

最佳答案

我同意另一个答案——logging 用于记录,warning 用于警告——但我想添加更多细节。

这里是一个教程式的 HOWTO,带您完成使用 logging 模块的步骤。 https://docs.python.org/3/howto/logging.html

它直接回答了你的问题:

warnings.warn() in library code if the issue is avoidable and the client application should be modified to eliminate the warning

logging.warning() if there is nothing the client application can do about the situation, but the event should still be noted

关于python - warnings.warn() 与 logging.warning(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9595009/

相关文章:

c - 禁止 GCC 下的不兼容指针类型特定警告

python - 动态获取模块

Python 串行模块打印空行

logging - 记录和打印到控制台有什么区别

c - 初始化: address of static symbol 'myStruct' is used for symbol 'otherStruct'

Python:禁用 iptcinfo 警告

python - 在python中选择排序算法

python - clickhouse + sqlalchemy : SELECT drops two rows from result

c - OS X asl 日志记录 : how to re-direct messages of multi-threaded project into a single file

c# - 在到达附加程序之前编辑 Log4Net 消息