首页 > 解决方案 > “AttributeError:模块 'logging' 没有属性 'basicConfig'”

问题描述

我正在学习记录

In [11]: !cat  program/codes/debug/logging.py                                                                                                         
import logging
logging.basicConfig(level=logging.DEBUG, format="%(asctime) -%(levelname)s - %(message)s")
logging.debug('Start of program')

def factorial(n):
    logging.debug("Start of factorial(%s%%)" %(n))
    total = 1
    for i in range(n+1):
        total *= i
        logging.debug(f"i is {str(i)}, total is {str(total)}")
    logging.debug("End of factorial(%s%%)" %(n))
    return total

print(factorail(5))
logging.debug("End of program.")

它在运行时报告意外错误:

In [12]: !python program/codes/debug/logging.py                                                                                                       
Traceback (most recent call last):
  File "program/codes/debug/logging.py", line 1, in <module>
    import logging
  File "/Users/gaowei/Desktop/Pubrepo/program/codes/debug/logging.py", line 2, in <module>
    logging.basicConfig(level=logging.DEBUG, format="%(asctime) -%(levelname)s - %(message)s")
AttributeError: module 'logging' has no attribute 'basicConfig'

"AttributeError: 模块 'logging' 没有属性 'basicConfig'",

但它是

In [13]: logging.basicConfig                                                                                                                          
Out[13]: <function logging.basicConfig(**kwargs)>

标签: python

解决方案


推荐阅读