Python的logging模块缺少"captureWarnings"函数

4 投票
1 回答
1955 浏览
提问于 2025-04-17 03:32

Python的标准日志模块里有一个叫做captureWarnings的功能,这个功能可以把日志和警告模块结合起来使用。可是,我发现我安装的版本好像没有这个功能:

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.captureWarnings
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'captureWarnings'
>>> import logging.captureWarnings
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named captureWarnings
>>> import warnings
>>> import logging.captureWarnings
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named captureWarnings
>>>

我到底哪里出错了呢?

1 个回答

8

很遗憾,在 Python 2.6.5 的日志模块 中没有这个方法。你需要使用 Python 2.7。

撰写回答