warnings

The warnings module provides functions to issue and filter warning messages. Unlike exceptions, warnings are intended to alert the user to potential problems, but without generating an exception or causing execution to stop. One of the primary uses of the warnings module is to inform users about deprecated language features that may not be supported in future versions of Python. For example:

>>> import regex
__main__:1: DeprecationWarning: the regex module is deprecated;  use the re module
>>>

Like exceptions, warnings are organized into a class hierarchy that describes general categories of warnings. The following table lists the currently supported categories:

Column1Column2
WarningBase class of all warning types
UserWarningUser-defined ...

Get Python: Essential Reference, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.