How to disable python warnings?

前端 未结 8 1128
醉梦人生
醉梦人生 2020-11-22 04:24

I am working with code that throws a lot of (for me at the moment) useless warnings using the warnings library. Reading (/scanning) the documentation I only found a way to d

8条回答
  •  难免孤独
    2020-11-22 04:55

    If you know what are the useless warnings you usually encounter, you can filter them by message.

    import warnings
    
    #ignore by message
    warnings.filterwarnings("ignore", message="divide by zero encountered in divide")
    
    #part of the message is also okay
    warnings.filterwarnings("ignore", message="divide by zero encountered") 
    warnings.filterwarnings("ignore", message="invalid value encountered")
    

提交回复
热议问题