Hide traceback unless a debug flag is set

前端 未结 2 546
面向向阳花
面向向阳花 2020-12-02 12:22

What is the idiomatic python way to hide traceback errors unless a verbose or debug flag is set?

Example code:

their_md5 = \'c38f03d2b7160f891fc36ec         


        
2条回答
  •  感动是毒
    2020-12-02 12:53

    try:
        pass # Your code here
    except Exception as e:
        if debug:
            raise # re-raise the exception
                  # traceback gets printed
        else:
            print("{}: {}".format(type(e).__name__, e))
    

提交回复
热议问题