How to disable python warnings?

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

    This is an old question but there is some newer guidance in PEP 565 that to turn off all warnings if you're writing a python application you should use:

    import sys
    import warnings
    
    if not sys.warnoptions:
        warnings.simplefilter("ignore")
    

    The reason this is recommended is that it turns off all warnings by default but crucially allows them to be switched back on via python -W on the command line or PYTHONWARNINGS.

提交回复
热议问题