第一种:在终端运行py文件
python -W ignore file.py
不需要import warning就可以执行文章来源:https://www.toymoban.com/news/detail-520369.html
第二种:全文取消警告的输出
import warnings
warnings.filterwarnings("ignore")
第三种:部分代码取消警告
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
a = 1/0.0
这种方法的优点是可以选择特定的语句隐藏警告。文章来源地址https://www.toymoban.com/news/detail-520369.html
到了这里,关于python 忽略警告(warning)的几种方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!