python 输出彩色终端信息

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

1.直接打印输出

python 输出彩色终端信息_第1张图片

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

下载地址wget https://pypi.python.org/packages/source/c/colorama/colorama-0.2.5.tar.gz#md5=308c6e38917bdbfc4d3b0783c614897d

[email protected]:colorama-0.2.5# ./setup.py build
running build
running build_py
creating build
creating build/lib
creating build/lib/colorama
copying colorama/ansi.py -> build/lib/colorama
copying colorama/winterm.py -> build/lib/colorama
copying colorama/win32.py -> build/lib/colorama
copying colorama/__init__.py -> build/lib/colorama
copying colorama/ansitowin32.py -> build/lib/colorama
copying colorama/initialise.py -> build/lib/colorama
[email protected]:colorama-0.2.5# ./setup.py install
running install
running build
running build_py
running install_lib
creating /usr/lib/python2.5/site-packages/colorama
copying build/lib/colorama/ansi.py -> /usr/lib/python2.5/site-packages/colorama
copying build/lib/colorama/winterm.py -> /usr/lib/python2.5/site-packages/colorama
copying build/lib/colorama/win32.py -> /usr/lib/python2.5/site-packages/colorama
copying build/lib/colorama/__init__.py -> /usr/lib/python2.5/site-packages/colorama
copying build/lib/colorama/ansitowin32.py -> /usr/lib/python2.5/site-packages/colorama
copying build/lib/colorama/initialise.py -> /usr/lib/python2.5/site-packages/colorama
byte-compiling /usr/lib/python2.5/site-packages/colorama/ansi.py to ansi.pyc
byte-compiling /usr/lib/python2.5/site-packages/colorama/winterm.py to winterm.pyc
byte-compiling /usr/lib/python2.5/site-packages/colorama/win32.py to win32.pyc
byte-compiling /usr/lib/python2.5/site-packages/colorama/__init__.py to __init__.pyc
byte-compiling /usr/lib/python2.5/site-packages/colorama/ansitowin32.py to ansitowin32.pyc
byte-compiling /usr/lib/python2.5/site-packages/colorama/initialise.py to initialise.pyc
running install_egg_info
Writing /usr/lib/python2.5/site-packages/colorama-0.2.5.egg-info
[email protected]:~# 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_ALL

from colorama import Fore,Back,Style

print 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)

[email protected]:termcolor-1.1.0# ./setup.py build
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying termcolor.py -> build/lib.linux-x86_64-2.7
[email protected]:termcolor-1.1.0# ./setup.py install
running install
running build
running build_py
running install_lib
copying build/lib.linux-x86_64-2.7/termcolor.py -> /usr/local/lib/python2.7/dist-packages
byte-compiling /usr/local/lib/python2.7/dist-packages/termcolor.py to termcolor.pyc
running install_egg_info
Writing /usr/local/lib/python2.7/dist-packages/termcolor-1.1.0.egg-info

python 输出彩色终端信息_第2张图片



参考:

https://pypi.python.org/pypi/colorama#downloads

https://pypi.python.org/pypi/termcolor/1.1.0


你可能感兴趣的:(python,输出彩色终端信息)