两种方法:
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)
```
本文介绍了两种方法来忽略Python代码中的警告,包括在代码中设置过滤器和通过命令行参数运行。然而,这两种方法对于库源码如torchtext中的警告无效。对于torchtext的特定UserWarning,需要直接在源码中进行注释。文章讨论了torchtext.data.field.py中的警告以及如何处理Example类即将被废弃的提示。
538





