Suppress warnings for a function in python
A decorator to suppress warnings from a function in python
- #python
# Suppress warnings from a function
import warnings
import functools
def suppress_warnings(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
return func(*args, **kwargs)
return wrapper
@suppress_warnings
def foo():
pass