warnings.filterwarnings()
warnings.filterwarnings() is a Python function in the Warnings Module category. Adds a warning filter to control which warnings are shown or ignored. The syntax is warnings.filterwarnings(action, message="", category=Warning, module="", lineno=0, append=False). Parameters: action — "default", "error", "ignore", "always", "module", "once". Returns: None. A typical example: warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings("error", category=UserWarning). A close sibling is warnings.warn(), which issues a warning message. Can be controlled with filterwarnings. A close sibling is warnings.resetwarnings(), which removes all warning filters and restores default behavior. A close sibling is warnings.simplefilter(), which a simple filter that applies to all warnings. A close sibling is warnings.catch_warnings(), which a context manager that temporarily controls warnings. More about this category: Warning control — warn, filterwarnings, resetwarnings. Related Warnings Module entries: warnings.warn(), warnings.resetwarnings(), warnings.simplefilter(), warnings.catch_warnings(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.