Skip to content

Instantly share code, notes, and snippets.

@bryjbrown
Last active August 29, 2015 13:56
Show Gist options
  • Save bryjbrown/9139072 to your computer and use it in GitHub Desktop.
Save bryjbrown/9139072 to your computer and use it in GitHub Desktop.
An example of using ANSI escape codes to colorize output for Python shell scripts.
def purple(string):
return '\033[95m' + string + '\033[0m'
def blue(string):
return '\033[94m' + string + '\033[0m'
def green(string):
return '\033[92m' + string + '\033[0m'
def yellow(string):
return '\033[93m' + string + '\033[0m'
def red(string):
return '\033[91m' + string + '\033[0m'
print purple("Barney said...")
print blue("I've got the blue text blues.")
print green("Good job, young grasshopper.")
print yellow("WARNING: You are about to do something stupid.")
print red("SNOWCRASH SNOWCRASH SNOWCRASH")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment