Python: Suppressing errors from going to commandline?

前端 未结 4 1110
粉色の甜心
粉色の甜心 2021-01-05 16:17

When I try to execute a python program from command line, it gives the following error. These errors do not cause any problem to my ouput. I dont want it to be displayed in

4条回答
  •  爱一瞬间的悲伤
    2021-01-05 16:54

    Here is a more readable, succinct solution for handling errors that are safe to ignore, without having to resort to the typical try/except/pass code block.

    from contextlib import suppress
    
    with suppress(IgnorableErrorA, IgnorableErrorB):
        do_something()
    

提交回复
热议问题