python中如何自己实现一个带颜色的打印
import time
def get_time_stamp():
ct = time.time()
local_time = time.localtime(ct)
data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
data_secs = (ct - int(ct)) * 1000
time_stamp = "%s.%03d" % (data_head, data_secs)
return time_stamp
class Logger(object):
def __init__(self,):
return
def info(self, value):
print("\033[34m\033[1m[%s][INFO]\033[0m %s" % (get_time_stamp(), value))
def error(self, value):
print("\033[31m\033[1m[%s][ERROR]\033[0m %s" % (get_time_stamp(), value))
def warning(self, value):
print("\033[33m\033[1m[%s][WARNING]\033[0m %s" % (get_time_stamp(), value))
def ok(self, value):
print("\033[32m\033[1m[%s][OK]\033[0m %s" % (get_time_stamp(), value))
logger = Logger()
注:
- \033[1m*****\033[0m 是将打印出来的字体加粗

浙公网安备 33010602011771号