Created
August 11, 2012 18:40
-
-
Save Ceasar/3326276 to your computer and use it in GitHub Desktop.
Add colors to stdout when printing.
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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Someone already wrote a library for this! http://pypi.python.org/pypi/termcolor