Python colorama Color memo (Cmder environment)

Introduction

Make a note of the colors when using Python's text color specification library colorama on Windows7 Cmder.

How to use

Initialization

import colorama
from colorama import Fore, Back, Style

colorama.init(autoreset=True)

Text color specification

Specify when outputting characters to color the subsequent characters.

print("foo," + Fore.BLUE + "bar," + Back.RED + "baz")

image

It's colored!

Attribute group that can be specified

You can use the following: 16 colors except RESET.

Fore.BLACK           Fore.LIGHTBLACK_EX   Fore.LIGHTMAGENTA_EX Fore.MAGENTA         Fore.YELLOW
Fore.BLUE            Fore.LIGHTBLUE_EX    Fore.LIGHTRED_EX     Fore.RED
Fore.CYAN            Fore.LIGHTCYAN_EX    Fore.LIGHTWHITE_EX   Fore.RESET
Fore.GREEN           Fore.LIGHTGREEN_EX   Fore.LIGHTYELLOW_EX  Fore.WHITE

Back.BLACK           Back.LIGHTBLACK_EX   Back.LIGHTMAGENTA_EX Back.MAGENTA         Back.YELLOW
Back.BLUE            Back.LIGHTBLUE_EX    Back.LIGHTRED_EX     Back.RED
Back.CYAN            Back.LIGHTCYAN_EX    Back.LIGHTWHITE_EX   Back.RESET
Back.GREEN           Back.LIGHTGREEN_EX   Back.LIGHTYELLOW_EX  Back.WHITE

Style.BRIGHT    Style.DIM       Style.NORMAL    Style.RESET_ALL

sample

colorful! image

The style is sober. DIM and NORMAL were no different. image

bonus

Snippets to line up the above color samples.

#color
for attr in dir(Fore):
    if attr[0] != '_':
        print(getattr(Fore, attr) + "### Fore.{:<15}".format(attr) + Back.WHITE + "### Fore.{:<15}".format(attr))
        print(getattr(Back, attr) + "### Back.{:<15}".format(attr) + Fore.BLACK + "### Back.{:<15}".format(attr))

#style
for attr in dir(Style):
    if attr[0] != '_':
        print(getattr(Style, attr) + "### Style.{:<10} ###".format(attr))

Recommended Posts

Python colorama Color memo (Cmder environment)
My python environment memo
[MEMO] [Development environment construction] Python
Python environment construction memo on Windows 10
Python memo
python memo
[Personal memo] Python virtual environment command memo
Python environment construction memo on Mac
python memo
Vim + Python development environment setting memo
Python memo
Emacs Python development environment construction memo
Python memo
Python memo
Python & Machine Learning Study Memo: Environment Preparation
Free Python runtime environment Google Colaboratory memo
[Python] Memo dictionary
python beginner memo (9.2-10)
Python environment construction
python windows environment
Environment construction (python)
★ Memo ★ Python Iroha
python environment construction
[Python] EDA memo
Python 3 operator memo
Python --Environment construction
Python environment construction
[My memo] python
Python3 metaclass memo
[Python] Basemap memo
python environment construction
Python beginner memo (2)
[Python] Numpy memo
A memo when creating a python environment with miniconda
A memo for creating a python environment by a beginner
[Python] Get environment variables
Python module (Python learning memo ④)
Visualization memo by Python
Unification of Python environment
python windows environment construction
ConoHa environment construction memo
homebrew python environment construction
Python test package memo
[Python] Memo about functions
Python development environment construction
python virtual environment Pipenv
python regular expression memo
Binary search (python2.7) memo
[My memo] python -v / python -V
Python3 List / dictionary memo
[Memo] Python3 list sort
Python Tips (my memo)
[Python] Memo about errors
About Python development environment
DynamoDB Script Memo (Python)
virtual environment in python
Python basic memo --Part 2
python recipe book Memo
Python environment with docker-compose
Basic Python command memo
python2.7 development environment construction