python实现控制台打印的方法
时间:2021-02-26 10:51:10|栏目:Python代码|点击: 次
如下所示:
#!/usr/bin/env python
import os
import sys
class CConsole:
M_MAP_COLOR = {\
'COLOR_BLACK' : "\033[0;30m",
'COLOR_RED' : "\033[0;31m",
'COLOR_GREEN' : "\033[0;32m",
'COLOR_YELLOW' : "\033[0;33m",
'COLOR_BLUE' : "\033[0;34m",
'COLOR_PUPPLE' : "\033[0;35m",
'COLOR_CYAN' : "\033[0;36m",
'COLOR_WHITE' : "\033[0;37m",
'COLOR_RESTORE' : "\033[0m",
}
@staticmethod
def ColorPrint(strPrint, strColor = None):
strPrint = str(strPrint)
if strColor in CConsole.M_MAP_COLOR.keys():
strMsg = CConsole.M_MAP_COLOR[strColor] + strPrint + CConsole.M_MAP_COLOR['COLOR_RESTORE']
else:
strMsg = strPrint
print(strMsg)
sys.stdout.flush()
上一篇:基于Python Shell获取hostname和fqdn释疑
栏 目:Python代码
下一篇:浅谈Python 命令行参数argparse写入图片路径操作
本文标题:python实现控制台打印的方法
本文地址:http://www.codeinn.net/misctech/70127.html






