How To Suppress DeprecationWarning in Python

27 Apr 2010

If you find deprecation warnings getting annoying or making your log files messy, here is how you can turn them off in python.

For an entire script:

import warnings
warnings.simplefilter('ignore', DeprecationWarning)

Or, temporarily, inside a script:

import warnings

def fxn():
    warnings.warn("deprecated", DeprecationWarning)

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    fxn()

More: Official Python Docs About Issuing / Controlling Warnings