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/