python实现控制台打印的方法

yipeiwu_com5年前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实现控制台打印的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python中的字符串操作和编码Unicode详解

本文主要给大家介绍了关于 Python中的字符串操作和编码Unicode的一些知识,下面话不多说,需要的朋友们下面来一起学习吧。 字符串类型 str:Unicode字符串。采...

python scipy求解非线性方程的方法(fsolve/root)

python scipy求解非线性方程的方法(fsolve/root)

使用scipy.optimize模块的root和fsolve函数进行数值求解线性及非线性方程,下面直接贴上代码,代码很简单 from scipy.integrate import o...

Python中列表与元组的乘法操作示例

本文实例讲述了Python中列表与元组的乘法操作。分享给大家供大家参考,具体如下: 直接上code吧,还可以这么玩儿 列表乘法: li=[1,] li=li*3 print(li)...

Python中的字符串替换操作示例

字符串的替换(interpolation), 可以使用string.Template, 也可以使用标准字符串的拼接. string.Template标示替换的字符, 使用"$"符号, 或...

Anaconda下配置python+opencv+contribx的实例讲解

Anaconda下配置python+opencv+contribx的实例讲解

先吐槽一下opencv 3.1.0的版本cv2.sift和surf就不能用了 看解释是说 什么 "non-free",,必须要到opencv_contrib库中才有,而这个库的编译不是...