How to disable python warnings?

前端 未结 8 1008
醉梦人生
醉梦人生 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:53

    There's the -W option.

    python -W ignore foo.py

    0 讨论(0)
  • 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")
    
    0 讨论(0)
提交回复
热议问题