Why Are Both "Import Logging" and "Import Logging. Config" Needed?

Should it not be handled by a single import? i.e. import logging.

If I do not include import logging.config in my script, it gives:

AttributeError: 'module' object has no attribute 'config'

2 Answers

logging is a package. Modules in packages aren't imported until you (or something in your program) imports them. You don't need both import logging and import logging.config though: just import logging.config will make the name logging available already.

3

Just add an addtional explanation for Thomas's answer.

logging is a package, a directory.

enter the logging dir and list what files there is:

config.py handlers.py __init__.py __pycache__

so, There is a config.py file in logging directory, but why it can't import logging.config. That's because there is no config namespace in logging/__init__.py

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest