2/21/2023

python ignore warings messages

1. ignore all warnings

.

import warnings

# Ignore all warnings
warnings.filterwarnings("ignore")

..


2. To ignore specific types of warnings, you can use a context manager:

import warnings
# Ignore DeprecationWarning
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
# Code that produces DeprecationWarning



3. You can also use a decorator to ignore specific types of warnings:

.
import warnings

# Ignore DeprecationWarning with a decorator
@warnings.catch_warnings()
@warnings.filterwarnings("ignore", category=DeprecationWarning)
def my_function():
# Code that produces DeprecationWarning
..

Thank you.
๐Ÿ™‡๐Ÿป‍♂️
www.marearts.com

No comments:

Post a Comment