Python中logging.warn和logging.warning有什么区别?

2024-05-28 19:14:00 发布

您现在位置:Python中文网/ 问答频道 /正文

2条回答

自从Python 3.3以来,logging.warn已被弃用,您应该使用logging.warning

在Python 3.3之前,logging.warnlogging.warning是相同的函数,但是logging.warn没有文档记录,如Python bug trackerhttp://bugs.python.org/issue13235中的一个封闭问题所述:

That's deliberate. The original code (before incorporation into Python) had warn(), which was kept for backward compatibility. The docs refer to warning() because that's what everyone is supposed to use. The method names map to the lower case of the appropriate logging level name.

保留logging.warn()是为了向后兼容,但是a deprecation warning was addedlogging.warning()是每个人都应该使用的。

在Python 3.3之前,它们是相同的,但是warn被弃用:

>>> import logging
>>> logging.warn is logging.warning
True

相关问题 更多 >

    热门问题