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)