Skip to content

Latest commit

 

History

History
20 lines (12 loc) · 424 Bytes

warnings.md

File metadata and controls

20 lines (12 loc) · 424 Bytes

Warnings

The warnings module writes warning messages to the sys.stderr stream:

:::python
import warnings

warnings.warn("This is a drill!")

The output warning also contains a line number:

:::bash
warn.py:3: UserWarning: This is a drill!
  warnings.warn("This is a drill!")

Python has an option to stop with an error as soon as a warning occurs:

:::bash
python -W error warnme.py