-
-
Save rahulrajaram/c8f5668cf1445f01ccb9504480be2d62 to your computer and use it in GitHub Desktop.
Python print colored STDOUT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COLOR_MAP = { | |
'black': '30', | |
'red': '31', | |
'green': '32', | |
'yellow': '33', | |
'blue': '34', | |
'magenta': '35', | |
'cyan': '36', | |
'white': '37', | |
} | |
def colorize(text, color): | |
return '\033[1;{0}m{1}\033[0m'.format(COLOR_MAP[color], text) | |
for color in COLOR_MAP.keys(): | |
print(colorize(text='Hello, world', color=color)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Considering the above is not a cross-platform solution, I recommend using
colorama
.