在Python中,遇到異常時,一類是直接拋出異常,exception
;另外一類直接告警warning
.html
對於後者,一般是打印一句話。前者則或中斷程序執行。python
考慮到避免因爲告警致使後續的不可預知的錯誤,能夠對warning進行異常處理。less
import warnings warnings.filterwarnings("ignore")
import warnings warnings.filterwarnings("error") try: ... except: ...
Value | Disposition |
---|---|
"error" | turn matching warnings into exceptions |
"ignore" | never print matching warnings |
"always" | always print matching warnings |
"default" | print the first occurrence of matching warnings for each location where the warning is issued |
"module" | print the first occurrence of matching warnings for each module where the warning is issued |
"once" | print only the first occurrence of matching warnings, regardless of location |
如何處理code