colorama翻译中文(colorama 0.2.4 : Python Package Index)
colorama 0.2.4
Cross-platform colored terminal text.
Downloads ↓
Download and docs: http://pypi.python.org/pypi/colorama Development: http://code.google.com/p/coloramaDependencies
None, other than Python. Tested on Python 2.5.5, 2.6.5, 2.7, 3.1.2, and 3.2
Usage
Initialisation
Applications should initialise Colorama using:
from colorama import init init()If you are on Windows, the call to init() will start filtering ANSI escape
sequences out of any text sent to stdout or stderr, and will replace them with
equivalent Win32 calls.Calling init() has no effect on other platforms (unless you request other
optional functionality, see keyword args below.) The intention is that
applications can call init() unconditionally on all platforms, after which
ANSI output should just work.To stop using colorama before your program exits, simply call deinit().
This will restore stdout and stderr to their original values, so that Colorama
is disabled. To start using Colorama again, call reinit(), which wraps
stdout and stderr again, but is cheaper to call than doing init() all over
again.Colored Output
Cross-platform printing of colored text can then be done using Coloramas
constant shorthand for ANSI escape sequences: from colorama import Fore, Back, Style print Fore.RED + some red text print Back.GREEN + and with a green background print Style.DIM + and in dim text print + Fore.RESET + Back.RESET + Style.RESET_ALL print back to normal nowor simply by manually printing ANSI sequences from your own code:
print /033[31m + some red text print /033[30m # and reset to default coloror Colorama can be used happily in conjunction with existing ANSI libraries
such as Termcolor: from colorama import init from termcolor import colored # use Colorama to make Termcolor work on Windows too init() # then use Termcolor for all colored text output print colored(Hello, World!, green, on_red)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_ALLStyle.RESET_ALL resets foreground, background and brightness. Colorama will
perform this reset automatically on program exit.创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!