定制输出

import sys
import platform

def printf(*objects, color="GREEN" ,sep=' ', end='\n', file=sys.stdout, flush=False):
    if(platform.system()=='Windows'):
        print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
    else:
        if color=="red":
            color_value = 31
        elif color=="yellow":
            color_value = 33
        elif color=="blue":
            color_value = 34
        else:
            color_value = 32
        print(f"\033[0;{color_value}m", end="")
        print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
        print("\033[0m", end="")  #关闭所有属性

my_print(11)
my_print(11, color="red")
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页