hekevintran hekevintran - 20 days ago 5
Python Question

Python warnings.warn() vs. logging.warning()

What is the difference between warnings.warn() and logging.warn() in terms of what they do and how they should be used?

Answer

One raises an exception which can be caught or ignored as desired, and the other optionally adds an entry to the log based on the current logging level. One should be used when one is warning about various things in code, and the other should be used when logging.