以下代码以前对我有效,应该根据文档工作:
$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging.handlers
>>> logging.handlers.WatchedFileHandler("log.log")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'WatchedFileHandler'从医生那里:
class logging.handlers.WatchedFileHandler(filename[, mode[, encoding[, delay]]])这可能是什么原因?
发布于 2015-11-06 09:34:00
日志记录是由pip或easy_install手动安装的,但是pip中的包是旧的,因此我在/usr/local/lib/python2.7/dist-packages中安装了0.4.9.6版本,而最近的版本则安装在usr/lib/python2.7中的python中。似乎在服务器上,dist-package在路径中较早,而在桌面上则不然。无论如何,删除旧包解决了这个问题。
发布于 2018-07-30 07:57:05
如果有人在使用python3时遇到了同样的问题,可以通过像这样分别导入logging.handlers和logging来解决这个问题
import logging.handlers
logging.handlers.WatchedFileHandler('example.log')https://stackoverflow.com/questions/33528384
复制相似问题