Last active
January 28, 2021 03:36
-
-
Save LanternD/624693224b987bc29377a7119415a008 to your computer and use it in GitHub Desktop.
Print Colorful Text in Python
This file contains hidden or 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
# 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