We can make eye-catching effect by setting different colors for useful information, because I usually develop under Linux, and the colors in Linux terminal are controlled by escape sequence, the escape sequence starts with ESC and can do the same work with \033 ( The ASCII code of ESC is expressed in decimal notation is 27, which equals 33 in octal notation.
The writing format, and the related instructions are as follows:
Copy Code The code is as follows:
Format: \033[display mode; foreground color; background colour m
Description
Foreground background color
---------------------------------------
30 40 Black
31 41 Red
32 42 Green
33 43 Yellow
34 44 Blue
35 45 Purplish red
36 46 Cyan Blue
37 47 White
Meaning of display mode
-------------------------
0 Terminal default settings
1 highlighting
4 using underscores
5 Flashing
7 Anti-white display
8 Not visible
Example:
\033[1;31;40m <!--1-highlight 31-foreground color Red 40-background black--
\033[0m <!--Use the terminal default setting, which cancels the color setting--
The Python code is pasted as follows:
#!/usr/bin/env pythonfrom Collections Import ordereddict#red color-->print ' \033[1;31;40m ' print ' \033[1;32;47m ' print ' output dict have ordered ' print ' \033[0m ' d=ordereddict () d[' foo ']=1d[' bar ']=2d[' spam ']=3d[' grok ']=4for key in D : Print Key,d[key]print ' \033[1;32;47m ' print '-------' print ' delete Elemente from list ' print ' \033[0m ' def dedupe (items) : Seen=set () for item in Items:if item not in Seen:yield item Seen.add (item) a=[1,5,2, 1,9,1,5,10]print List (Dedupe (a))
Python with color output text