How to check if sys.stderr supports colors?

31 Views Asked by At

Say, if we want to output to the console in color, I'd do:

import sys

red = '\033[31m'
restore = '\033[0m'

sys.stderr.write(f"{red}Error message{restore}")

But how to tell if sys.stderr supports colors?

I need this to know if it doesn't, and in that case avoid printing \033[ parts.

0

There are 0 best solutions below