The warning system is very flexible and allows you to do many things you might want, e.g.:
-
Ignore all warnings: set the OS env var
PYTHONWARNINGS=ignore -
Only ignore some warnings, e.g the deprecation warnings: set the OS env var
PYTHONWARNINGS=ignore::DeprecationWarning -
Redirect all warnings to the logging module via a call to
logging.captureWarnings(True)and configure this to write them to a file: see logging — Logging facility for Python — Python 3.12.5 documentation for how this can be configured
Where it’s not possible to configure these things via OS env vars, you can create a custom module and import this in the sitecustomize.py module, which is typically run at startup time (unless you use options to prevent this). See site — Site-specific configuration hook — Python 3.12.5 documentation for details.
It is also possible to only apply such settings to interactive REPL sessions by placing the import into PYTHONSTARTUP. See 1. Command line and environment — Python 3.12.5 documentation for details.