Skip to content
Advertisement

Tag: user-experience

Hide traceback unless a debug flag is set

What is the idiomatic python way to hide traceback errors unless a verbose or debug flag is set? Example code: Existing output now, but only desired when called with foo.py –debug: Desired normal output: Here’s a test script: https://gist.github.com/maphew/e3a75c147cca98019cd8 Answer The short way is using the sys module and use this command: Use your flag to determine the behaviour. Example:

Advertisement