ansi-colors

How to print colored text in terminal in Python?

不羁岁月 提交于 2019-11-25 22:55:12
问题 How can I output colored text to the terminal, in Python? What is the best Unicode symbol to represent a solid block? 回答1: This somewhat depends on what platform you are on. The most common way to do this is by printing ANSI escape sequences. For a simple example, here's some python code from the blender build scripts: class bcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' BOLD = '\033[1m' UNDERLINE = '\033[4m' To