import warnings
#ignore by messagewarnings.filterwarnings("ignore", message="divide by zero encountered in divide")
##part of the message is also okaywarnings.filterwarnings("ignore", message="divide by zero encountered")warnings.filterwarnings("ignore", message="invalid value encountered")
import logging
for name in logging.Logger.manager.loggerDict.keys():logging.getLogger(name).setLevel(logging.CRITICAL)
#rest of the code starts here...
或者,
如果你只想抑制特定组警告,那么你可以像这样过滤:
import logging
for name in logging.Logger.manager.loggerDict.keys():if ('boto' in name) or ('urllib3' in name) or ('s3transfer' in name) or ('boto3' in name) or ('botocore' in name) or ('nose' in name):logging.getLogger(name).setLevel(logging.CRITICAL)
#rest of the code starts here...