Python 忽略warning警告错误 + 跳过报错继续执行程序
如何主动产生warning错误:
import
warnings
def
fxn():
warnings.warn(
"deprecated"
, DeprecationWarning)
with warnings.catch_warnings():
warnings.simplefilter(
"ignore"
)
fxn()
那么如何来控制警告错误的输出呢?
import
warnings
warnings.filterwarnings(
"ignore"
)
如何忽略命令行下警告错误的输出呢?
python -W ignore yourscript.py
那么如何忽略全部的异常呢?下面是一个事例
import pandas as pd
dates=range(20161010,20161114)
pieces=[]
for date in dates:
try:
data=pd.read_csv(‘A_stock/overview-push-%d/stock overview.csv‘ %date, encoding=‘gbk‘)
pieces.append(data)
except Exception as e:
pass
continue
data=pd.concat(pieces)
参考:
https://www.cnblogs.com/blueel/p/3529517.html
https://blog.csdn.net/weixin_43307577/article/details/87710251
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16