首页IT科技colorama翻译中文(colorama 0.2.4 : Python Package Index)

colorama翻译中文(colorama 0.2.4 : Python Package Index)

时间2025-06-20 03:27:57分类IT科技浏览4545
导读:colorama 0.2.4 Cross-platform colored terminal text....

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/colorama

Dependencies

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 now

or simply by manually printing ANSI sequences from your own code:

print /033[31m + some red text print /033[30m # and reset to default color

or 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_ALL

Style.RESET_ALL resets foreground, background and brightness. Colorama will

perform this reset automatically on program exit.
声明:本站所有文章             ,如无特殊说明或标注                   ,均为本站原创发布             。任何个人或组织      ,在未征得本站同意时             ,禁止复制             、盗用                   、采集      、发布本站内容到任何网站       、书籍等各类媒体平台                   。如若本站内容侵犯了原著者的合法权益                    ,可联系我们进行处理      。

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
电脑管理日志在哪看(win10管理日志怎么导出)