On this page
warnings.warn_explicit
Prev: warnings.warn | Up: warnings
Rel: warnings.catch_warnings, warnings.deprecated, warnings.filterwarnings, warnings.formatwarning
Ref: docs.python.org — warnings.warn_explicit
Tags: #public #python3 #stdlib #warnings
Import
import warnings
from warnings import warn_explicit
Signature & Overview
warnings.warn_explicit(...)
Issue a warning, or maybe ignore it or raise an exception.
Usage
import warnings
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter('always')
warnings.warn_explicit('msg', UserWarning, 'virtual.py', 1)
assert caught[0].filename == 'virtual.py'
Gotchas
- Low-level helper for template engines/compilers that want to attribute warnings to a custom filename and line number.
REPL Inspect
from warnings import warn_explicit
help(warn_explicit)
Linked from
Related notes
- tuts/python3/stdlib_module/warnings/warn Linked here; links to this page; shared tags: #stdlib, #warnings
- tuts/python3/stdlib_module/warnings Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/warnings/catch_warnings Linked here; shared tags: #stdlib, #warnings
- tuts/python3/stdlib_module/warnings/deprecated Linked here; shared tags: #stdlib, #warnings
- tuts/python3/stdlib_module/warnings/filterwarnings Linked here; shared tags: #stdlib, #warnings
- tuts/python3/stdlib_module/warnings/formatwarning Linked here; shared tags: #stdlib, #warnings
- tuts/python3/stdlib_module/warnings/resetwarnings shared tags: #stdlib, #warnings
- tuts/python3/stdlib_module/warnings/showwarning shared tags: #stdlib, #warnings
- tuts/python3/stdlib_module/warnings/simplefilter shared tags: #stdlib, #warnings
- tuts/c/stdlib shared tags: #stdlib