Having python to print output to terminals with different colors.
- Place both files side by side and execute
python test_print.pyto see the result
- Target version: 3.5 and above
- Inspired by: https://stackoverflow.com/a/287944
Having python to print output to terminals with different colors.
python test_print.py to see the result| # targeted environment: Python 3.5 | |
| # Inspired by: https://stackoverflow.com/a/287944 | |
| class bcolors: | |
| MAGENTA = '\033[95m' | |
| BLUE = '\033[94m' | |
| GREEN = '\033[92m' | |
| YELLOW = '\033[93m' | |
| RED = '\033[91m' | |
| ENDC = '\033[0m' | |
| BOLD = '\033[1m' | |
| UNDERLINE = '\033[4m' |
| # targeted environment: Python 3.5 | |
| # import module | |
| from terminal_color import bcolors | |
| print(bcolor.RED + "This is a red color message." + bcolor.ENDC) | |
| print(bcolor.GREEN + "This is a green color message." + bcolor.ENDC) | |
| print(bcolor.BLUE + "This is a blue color message." + bcolor.ENDC) | |
| print(bcolor.MAGENTA + "This is a magenta color message." + bcolor.ENDC) | |
| print(bcolor.YELLOW + "This is a yellow color message." + bcolor.ENDC) | |
| print(bcolor.BOLD + "This is a bold message." + bcolor.ENDC) | |
| print(bcolor.UNDERLINE + "This is an underlined message." + bcolor.ENDC) |