Skip to content

Instantly share code, notes, and snippets.

@Ceasar
Created August 11, 2012 18:40
Show Gist options
  • Save Ceasar/3326276 to your computer and use it in GitHub Desktop.
Save Ceasar/3326276 to your computer and use it in GitHub Desktop.
Add colors to stdout when printing.
BLACK = 0
RED = 1
GREEN = 2
YELLOW = 3
BLUE = 4
MAGENTA = 5
CYAN = 6
WHITE = 7
def colorize(text, fg=None):
"""Prints some text with color."""
_fg = fg or 0
return "\033[9%sm%s\033[0m" % (_fg, text)
@Ceasar
Copy link
Author

Ceasar commented Jan 3, 2013

Someone already wrote a library for this! http://pypi.python.org/pypi/termcolor

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