title: python打印提示信息时定义颜色 #标题tags: #标签
date: 2021-12-25
categories: python # 分类
记录下python中用于打印提示信息时定义的函数,可以让提示信息带颜色输出。
import sysansi = {'underline': '\033[4m','bold': '\033[1m','end': '\033[0m','blue': '\033[34m','red': '\033[31m','green': '\033[32m','purple': '\033[35m'}def print_header(msg):print("\n:# {bold}{underline}{msg}{end}\n".format(msg=msg, **ansi))def print_info(msg):print(":: {blue}{msg}{end}".format(msg=msg, **ansi))def print_warn(msg):print(":! {purple}{msg}{end}".format(msg=msg, **ansi))def print_ok(msg):print(":) {green}{msg}{end}".format(msg=msg, **ansi))def print_success(msg):print(":) {green}{msg}{end}".format(msg=msg, **ansi))def print_error(msg):print(":( {red}{msg}{end}".format(msg=msg, **ansi))def print_error_exit(msg, code=1):print_error(msg)sys.exit(code)
