博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 输出彩色终端信息
阅读量:6691 次
发布时间:2019-06-25

本文共 2998 字,大约阅读时间需要 9 分钟。

  hot3.png

python也可以像shell一样终端打印彩色消息.方法有很多.

1.直接打印输出

2.使用python里colorama模块.(debian7自带python-colorama模块)

下载地址wget 

root@10.1.6.200:colorama-0.2.5# ./setup.py buildrunning buildrunning build_pycreating buildcreating build/libcreating build/lib/coloramacopying colorama/ansi.py -> build/lib/coloramacopying colorama/winterm.py -> build/lib/coloramacopying colorama/win32.py -> build/lib/coloramacopying colorama/__init__.py -> build/lib/coloramacopying colorama/ansitowin32.py -> build/lib/coloramacopying colorama/initialise.py -> build/lib/coloramaroot@10.1.6.200:colorama-0.2.5# ./setup.py installrunning installrunning buildrunning build_pyrunning install_libcreating /usr/lib/python2.5/site-packages/coloramacopying build/lib/colorama/ansi.py -> /usr/lib/python2.5/site-packages/coloramacopying build/lib/colorama/winterm.py -> /usr/lib/python2.5/site-packages/coloramacopying build/lib/colorama/win32.py -> /usr/lib/python2.5/site-packages/coloramacopying build/lib/colorama/__init__.py -> /usr/lib/python2.5/site-packages/coloramacopying build/lib/colorama/ansitowin32.py -> /usr/lib/python2.5/site-packages/coloramacopying build/lib/colorama/initialise.py -> /usr/lib/python2.5/site-packages/coloramabyte-compiling /usr/lib/python2.5/site-packages/colorama/ansi.py to ansi.pycbyte-compiling /usr/lib/python2.5/site-packages/colorama/winterm.py to winterm.pycbyte-compiling /usr/lib/python2.5/site-packages/colorama/win32.py to win32.pycbyte-compiling /usr/lib/python2.5/site-packages/colorama/__init__.py to __init__.pycbyte-compiling /usr/lib/python2.5/site-packages/colorama/ansitowin32.py to ansitowin32.pycbyte-compiling /usr/lib/python2.5/site-packages/colorama/initialise.py to initialise.pycrunning install_egg_infoWriting /usr/lib/python2.5/site-packages/colorama-0.2.5.egg-info
root@10.1.6.200:~# cat color.py #!/usr/bin/env python#coding:utf8#Available formatting constants are::  #Fore: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.   #Back: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.  #Style: DIM, NORMAL, BRIGHT, RESET_ALLfrom colorama import Fore,Back,Styleprint Fore.RED + 'some red text'print Back.CYAN + 'and with a cyan background'print Style.DIM + 'and in dim text'print(Fore.RESET + Back.RESET + Style.RESET_ALL)print('back to normal now')

3.使用termcolor模块(下载地址:wget https://pypi.python.org/packages/source/t/termcolor/termcolor-1.1.0.tar.gz)

root@10.1.6.201:termcolor-1.1.0# ./setup.py buildrunning buildrunning build_pycreating buildcreating build/lib.linux-x86_64-2.7copying termcolor.py -> build/lib.linux-x86_64-2.7root@10.1.6.201:termcolor-1.1.0# ./setup.py installrunning installrunning buildrunning build_pyrunning install_libcopying build/lib.linux-x86_64-2.7/termcolor.py -> /usr/local/lib/python2.7/dist-packagesbyte-compiling /usr/local/lib/python2.7/dist-packages/termcolor.py to termcolor.pycrunning install_egg_infoWriting /usr/local/lib/python2.7/dist-packages/termcolor-1.1.0.egg-info

参考:

转载于:https://my.oschina.net/davehe/blog/133648

你可能感兴趣的文章
连接数据库通过配置文件app.config
查看>>
赛星软件---智能视频分析事件检测
查看>>
【二叉树遍历】中序
查看>>
一个完整的类用来读取OpenSSL生成的pem格式的x509证书
查看>>
Delphi调用WebService(通过SoapHeader认证)经验总结
查看>>
2014年最新世界各国面积排名(172个国家)
查看>>
socket编程演示样例(多线程)
查看>>
C++ 初始化与赋值
查看>>
碰到的异常
查看>>
Android对话框-上篇-之系统对话框
查看>>
利用Segue在视图控制器间传值的问题
查看>>
发动机存隐患 现代起亚宣布在美召回16.8万辆车
查看>>
最前线|VIPKID正寻求4-5亿美元新一轮融资,估值达60亿美元
查看>>
文 OR 理?答案都在这里!
查看>>
XML+JSON面试题都在这里
查看>>
教你如何攻克Kotlin中泛型型变的难点(实践篇)
查看>>
2018Android面试经历
查看>>
不受限对抗样本挑战赛介绍
查看>>
浅解前端必须掌握的算法(三):直接插入排序
查看>>
[译] TensorFlow 教程 #06 - CIFAR-10
查看>>