Python报错:AttributeError: module ‘logging’ has no attribute ‘debug’, AttributeError: module ‘logging’ has no attribute ‘basicConfig’

import logging
LOG_FILENAME = 'example.log'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)

logging.debug('This message should go to the log file')

报错:AttributeError: module ‘logging’ has no attribute ‘debug’,

或者报错:AttributeError: module ‘logging’ has no attribute ‘basicConfig’

 

原因:你在python同目录下有一个名为logging的模块,也可能是同一目录中的文件 logging.py。比较一下 print(logging.__file__)

解决:logging.py 更名为 logger.py 再运行一下试试。

 

本文:Python报错:AttributeError: module ‘logging’ has no attribute ‘debug’, AttributeError: module ‘logging’ has no attribute ‘basicConfig’

Loading

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.