Python 的标准日志模块是 supposed to contain a useful captureWarnings function,它允许在日志和 warnings 模块之间进行集成。但是,我的安装似乎错过了这个功能:
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
>>>
我究竟做错了什么?
最佳答案
不幸的是,在 Python 2.6.5's logging module 中没有这样的方法。你需要 Python 2.7。