First look at the effect:
In the Linux terminal, the ANSI escape sequence controls the color
Basic rules: Front plus \033[, end with \033[0m reset to original color
You can enter the following sentence in the terminal, you can see the output green hello.
>>echo-e ' \033[0;32mhello\033[0m '
where 0;32m controls color.
The simplest, as long as the 0;32m 2 to 0-7, it corresponds to different colors.
Take advantage of this, in Python, you can do this.
#coding =utf-8
fmt = ' \033[0;3{}m{}\033[0m '. Format
class color:
black = 0# Dark
Red = red
GREEN = 2 #绿
yellow = 3# Brown
Blue = 4# Blue
PURPLE = 5# Violet
cyan = 6# Green
Gray = 7# Gray
Print FMT ( Color. Black, ' kzc ')
print fmt (color. RED , ' kzc ')
print fmt (color. GREEN, ' Kzc ')
print fmt (color. Yellow, ' kzc ')
print fmt (color. BLUE , ' kzc ')
print fmt (color. PURPLE, ' Kzc ')
print fmt (color. Cyan , ' kzc ')
print fmt (color. GRAY , ' Kzc ')
Ps:linux gracefully executes the program
under Linux, we execute a python program that is python/path/to/xxx.py.
This is a bit of a hassle if the program is used frequently. The
can chmod +x/path/to/xxx.py, that is, add executable permissions to the file, so you can run it directly/path/to/xxx.py without knocking python on the front.
However, this is not elegant enough for someone with code cleanliness, with a. py suffix behind it.
Remove the. py suffix, as long as you add #!/usr/bin/python to the first line of the file. The
is then directly/path/to/xxx to execute.