Skip to content

Instantly share code, notes, and snippets.

@rahulrajaram
Last active October 24, 2017 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulrajaram/c8f5668cf1445f01ccb9504480be2d62 to your computer and use it in GitHub Desktop.
Save rahulrajaram/c8f5668cf1445f01ccb9504480be2d62 to your computer and use it in GitHub Desktop.
Python print colored STDOUT
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))
@rahulrajaram
Copy link
Author

Considering the above is not a cross-platform solution, I recommend using colorama.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment