运行一个python文件,一直报warning的错误,很是郁闷,于是想到可以忽略这些错误。
下面来说一下如何忽略这些警告。
python -W ignore yourscript.py
import <a href="https://www.gaodaima.com/tag/warnings" title="查看更多关于warnings的文章" target="_blank">warnings</a> def fxn(): warnings.warn("deprecated", DeprecationWarning) with warnings.catch_warnings(): warnings.simplefilter("ignore") fxn()
www#gaodaima.com来源gaodai#ma#com搞*!代#%^码网搞代码
如果不想使用以上方法,可以直接在python源代码中的开始添加如下代码:
import warnings warnings.filterwarnings("ignore")
这样就可以忽略python报警告性错误啦
来源:搞代码网:原文地址:https://www.gaodaima.com