AttributeError:部分的に初期化されたモジュール 'logging' には属性 'basicConfig' がありません。

Python のロギング ライブラリを使用するとエラーが発生する

テストコード

ファイル名は次のとおりです。ロギング.py

import logging

logging.basicConfig()
logging.debug('This is a debug message')
logging.info('This is an info message')
logging.warning('This is a warning message')
logging.error('This is an error message')
logging.critical('This is a critical message')

エラーメッセージ

AttributeError: partially initialized module 'logging' has no attribute 'basicConfig' (most likely due to a circular import)

解決

意思ロギング.pyファイルを別のファイルに置き換えるxx.py

変更後の結果

WARNING:root:This is a warning message
ERROR:root:This is an error message
CRITICAL:root:This is a critical message

おすすめ

転載: blog.csdn.net/qq_42578742/article/details/123027908