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 log模块logging记录打印用法解析

这篇文章主要介绍了Python log模块logging记录打印用法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 日志基础教程...

使用Python3 编写简单信用卡管理程序

1、程序执行代码: #Author by Andy #_*_ coding:utf-8 _*_ import os,sys,time Base_dir=os.path.dirname...

Python获取文件ssdeep值的方法

本文实例讲述了Python获取文件ssdeep值的方法,分享给大家供大家参考。具体方法如下: 首先,得到ssdeep值,需要先import ssdeep 在ubuntu上安装pyssde...

Python json模块使用实例

实际上JSON就是Python字典的字符串表示,但是字典作为一个复杂对象是无法直接传递,所以需要将其转换成字符串形式.转换的过程也是一种序列化过程. 用json.dumps序列化为jso...

python求素数示例分享

复制代码 代码如下:# 判断是否是素数def is_sushu(num): res=True for x in range(2,num-1):  ...