Please never use a catch-all `except` clause. Instead, in this case, you don't need a try-except block at all if you just ask `hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()` instead.