From 50d6cc85f88443f85f3c82415a0ded3bc80e48e4 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Wed, 26 Aug 2020 17:24:18 -0400 Subject: [PATCH] Add hasattr check for isatty on sys.stdout (#27) * Add hasattr check for isatty on sys.stdout * fix flake8 error Signed-off-by: Matthew Peveler --- crayons.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crayons.py b/crayons.py index 80b99c5..ccb33cf 100644 --- a/crayons.py +++ b/crayons.py @@ -80,7 +80,9 @@ class ColoredString(object): if self.always_color: return c - elif sys.stdout.isatty() and not DISABLE_COLOR: + elif hasattr(sys.stdout, 'isatty') \ + and sys.stdout.isatty() \ + and not DISABLE_COLOR: return c else: return self.s