Skip to content

Instantly share code, notes, and snippets.

@j6k4m8
Last active February 4, 2017 15:54
Show Gist options
  • Save j6k4m8/24f028250dc38eb8579e4b9090beeeb6 to your computer and use it in GitHub Desktop.
Save j6k4m8/24f028250dc38eb8579e4b9090beeeb6 to your computer and use it in GitHub Desktop.
Prints in a color, or bolded, or formatted.

Pretty-print in python.

pretty_print([RED, UNDERLINE], "DANGER!")
print(
    pretty_format([YELLOW], "Careful!"),
    "Are you sure you want to do the thing?"
)
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'
def pretty_print(colors, text, cr=True):
if type(colors) == list:
pre = ''.join(colors)
else:
pre = colors
if cr:
print(pre + text + END)
else:
print(pre + text + END, end="")
def pretty_format(colors, text):
if type(colors) == list:
pre = ''.join(colors)
else:
pre = colors
return(pre + text + END)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment