
Built-in Attributes
|
83
the warnings framework to issue warnings by calling the
warnings.warn function:
warnings.warn("feature X no longer supported")
In addition, you can add filters to disable certain warnings.
You can apply a regular expression pattern to a message or
module name to suppress warnings with varying degrees of
generality. For example, you can suppress a warning about
the use of the deprecated
regex module by calling:
import warnings
warnings.filterwarnings(action = 'ignore',
message='.*regex module*',
category=DeprecationWarning,
module = '__main__')
This adds a filter that affects only warnings of the class
DeprecationWarning triggered in the __main__ module,
applies a regular expression to match only the message that
names the
regex module being deprecated, and causes such
warnings to be ignored. Warnings can be printed only once,
printed every time the offending code is executed, or turned
into exceptions that will cause the program to stop (unless
the exceptions are caught). See the
warnings module docu-
mentation in Version 2.1 and later for more information. See
also the
-W argument in the section “Command-Line
Options,” earlier in this book.
Built-in Attributes
Some objects export special attributes that are predefined by
Python.
*
The following is a partial list because many types
have unique attributes all their own; see the entries for spe-
cific types in the Python Library Reference. ...