Skip to content

Instantly share code, notes, and snippets.

@LanternD
Last active January 28, 2021 03:36
Show Gist options
  • Save LanternD/624693224b987bc29377a7119415a008 to your computer and use it in GitHub Desktop.
Save LanternD/624693224b987bc29377a7119415a008 to your computer and use it in GitHub Desktop.
Print Colorful Text in Python
# Fastest way:
WARN = '\033[93m[WARN]\033[00m'
INFO = '\033[92m[INFO]\033[00m'
ERR = '\033[91m[ERR]\033[00m'
DBG = '\033[94m[DBG]\033[00m'
print(INFO, "hello") # Usage
print(WARN, ERR, DBG, "your words here")
# Alternative:
def prt_warn(s): print("\033[93m[WARN]\033[00m {0}".format(s))
def prt_info(s): print("\033[92m[INFO]\033[00m {0}".format(s))
def prt_err(s): print("\033[91m[ERR]\033[00m {0}".format(s))
def prt_dbg(s): print("\033[94m[DBG]\033[00m {0}".format(s))
# Logging module
logging.basicConfig(
format="\033[92m[%(levelname)s]\033[00m %(message)s", level=logging.INFO
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment