Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Colored Print In Python

# the string '33[92m' represents the color green,
# and '33[0m' is used to go back to the standard color of the terminal

GREEN = '33[92m'
END_COLOR = '33[0m'
print(GREEN + "Hello World" + END_COLOR)
Comment

python print green

class bcolors:
    HEADER = '33[95m'
    OKBLUE = '33[94m'
    OKCYAN = '33[96m'
    OKGREEN = '33[92m'
    WARNING = '33[93m'
    FAIL = '33[91m'
    ENDC = '33[0m'
    BOLD = '33[1m'
    UNDERLINE = '33[4m'


print(bcolors.WARNING + "Warning: No active frommets remain. Continue?" + bcolors.ENDC)
# OR
print(f"{bcolors.WARNING}Warning: No active frommets remain. Continue?{bcolors.ENDC}")
Comment

Colored Print In Python

"""
Let’s start by installing the library:

$ pip install colorama

CHANGING COLOR

We can start by changing the color of the text.

Colorama allows you to use eight different colors:
black, red, green, yellow, blue, magenta, cyan, white.
They are implemented as variables in the Fore class.
Their name is the name of the color, written all upper case
"""

from colorama import Fore, init

init()

print('Now is not colored')
print(Fore.RED + 'some red text')
print(Fore.GREEN + 'some green text')
print(Fore.MAGENTA + 'some magenta text')
print(Fore.RESET + 'Back to normal')

"""
CHANGING BACKGROUND

The next class we will see is Back .
This implements the same keyword as the Fore class:
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.

However in this case the color will be used to change the background of the string
(i.e. to highlight the text)
"""

from colorama import Back, init

init()

print('Now is not highlighted')
print(Back.RED + 'some red background')
print(Back.GREEN + 'some green background')
print(Back.MAGENTA + 'some magenta background')
print(Back.RESET + 'Back to normal')

"""
CHAANGING BRIGHTNESS

we can use the Style class to change the brightness of the output.

There are three keywords in this class:

BRIGHT make the text bright;
DIM make the text dim (although it looks the same as normal text);
NORMAL to have the normal brightness.
"""

from colorama import Style, init

init()

print('Normal text')
print(Style.BRIGHT + 'Bright text')
print(Style.NORMAL + 'Normal text')

# this class also implements the RESET_ALL keyword,
# which is used to reset everything (brightness, color, background) to their normal values

from colorama import Fore, Back, Style, init

init()

print(Style.BRIGHT + 'Now the text is bright')
print(Fore.RED + 'Now the text is bright and red')
print(Back.GREEN + 'Now the text is bright, red and with green      background')
print(Style.RESET_ALL + 'Now everything is back to normal')
Comment

PREVIOUS NEXT
Code Example
Python :: how to install python libraries using pip 
Python :: who created python 
Python :: how to bulk update in mongodb using python 
Python :: how to change case of string in python 
Python :: seconds to datetime.time 
Python :: django in conda 
Python :: convert np shape (a,) to (a,1) 
Python :: python pil 
Python :: python sns lable axes 
Python :: selenium save webpage as pdf python 
Python :: how to concat on the basis of particular columns in pandas 
Python :: django migrate model 
Python :: turn list in to word python 
Python :: how to make a nan value in a list 
Python :: picasa 
Python :: python filter data from list 
Python :: generate secret key python 
Python :: jupyter tabnine for jupyter notebook 
Python :: tkinter button 
Python :: class python 
Python :: python make string one line 
Python :: selenium webdriver scroll down python 
Python :: Download video from a direct URL with Python 
Python :: dataframe to dictionary using index as key 
Python :: sorting a list of dictionaries 
Python :: django celery results 
Python :: filter dict 
Python :: pd df rename 
Python :: python use functions from another file 
Python :: add to python list 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =