如题
def log(str, color="red", background="default", effect="default"):
""" 颜色日志
# \ 033[显示方式;字体色;背景色m......[\ 033[0m]
"""
_color = \
{"black": "30", "red": "31", "green": "32", "yellow": "33", "blue": "34", "purple-red": "35",
"cyanine": "36",
"white": "37"}[color]
_background_color = \
{"black": "40;", "red": "41;", "green": "42;", "yellow": "43;", "blue": "44;", "purple-red": "45;",
"cyanine": "46;",
"white": "47;", "default": ""}[background]
_effect = \
{"default": "0", "highlight": "1", "underline": "4", "flash": "5", "backwhite": "7", "unshow": "8"}[
effect]
print('\033[%s;%s%sm %s \033[0m!' % (_effect, _background_color, _color, str))
测试代码
_color = \
{"black": "30", "red": "31", "green": "32", "yellow": "33", "blue": "34", "purple-red": "35",
"cyanine": "36",
"white": "37"}
_background_color = \
{"black": "40;", "red": "41;", "green": "42;", "yellow": "43;", "blue": "44;", "purple-red": "45;",
"cyanine": "46;",
"white": "47;", "default": ""}
_effect = \
{"default": "0", "highlight": "1", "underline": "4", "flash": "5", "backwhite": "7", "unshow": "8"}
for color in _color:
for bk in _background_color:
for effect in _effect:
log("hello world",color=color, background=bk, effect=effect)
效果截图