Python formatted output (color)

Source: Internet
Author: User


Brief introduction:

In Python, if you want to make the output color display, it is very easy to implement, you need to have termcolor knowledge!

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

Open Whole:

Install Termcolor        > Ipython # enters Ipythonin [1]: Import termcolor            # imports the module in [2]: Termcolor.termcolor.ATTRIBUTES Termcolor. Highlights Termcolor. VERSION Termcolor.cprint Termcolor.print_functiontermcolor. COLORS Termcolor. RESET termcolor.colored Termcolor.os

# above is the method of the module, the most commonly used method should be. Colored Bar

Example:

in [1]: From termcolor Import colored # Import this method only, because nothing else is used in the [2]: colored??# See which parameters are supported, and, of course, the following are examples of programs provided here, without signature:colored (text, Color=none, On_color=none, attrs=None) in [3]: Text = colored ('Hello World','Red'# The first argument is the text that will be output, the second parameter is the color in which the text is set in [4]: Print (text) # output red Hello worldhello Worldin [5]: Print (Colored ('Hello World','Green') # More simply, output the green Hello Worldhello Worldin [6]: Code_yellow = lambda x:colored (x,'Yellow'# You can use an anonymous function to make the color abstraction appear, which makes it easier to call in later in [7]: Print (Code_yellow ('Hello World') # output Yellow Hello Worldhello Worldin [8]: Print (Colored ('Hello World','Red','On_yellow') # Output Red Hello World, background color for yellow Hello Worldin [9]: Print (Colored ('Hello, World','Yellow', attrs=['Reverse','Blink']) # Official to say is the code flicker, I do not flash, and set the background color as the effect! Hello, Worldin [Ten]: Print (Colored ('%s'%'Hello World','Red','On_yellow') # In addition, it can be output formatted, that is,%s%text in such a way, is still very convenient! Hello World

Python formatted output (color)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.