python tips:warning消除

python tips:warning消除

两种方法:

1.在代码中

import warnings
warnings.filterwarnings(“ignore”)
2.运行时

python -W ignore script.py
ELSE:

以上两种方法对于库源码中的报错没有作用,比如对于torchtext中的warning.warn,目前是直接注释了源码中的warning.

/home/***/anaconda3/envs/py36/lib/python3.6/site-packages/torchtext/data/field.py:68: UserWarning: Field class will be retired soon and moved to torchtext.legacy. Please see the most recent release notes for further information.
warnings.warn(‘{} class will be retired soon and moved to torchtext.legacy. Please see the most recent release notes for further information.’.format(self.__class__.__name__), UserWarning)
def fromJSON(cls, data, fields):
#warnings.warn(‘Example class will be retired soon and moved to torchtext.legacy. Please see the most recent release notes for further information.’, UserWarning)
“`