Python Printing in different colors and also for warning, failure and header

How to print the lines in color in python program?

In python print statement, there is a provisioning to use colors, warning, failure and header indications.

Python program to print lines in colors, warning, failure and header indications

OKGREEN = '\033[92m'                                                            
OKBLUE = '\033[94m'                                                             
ENDC = '\033[0m'                                                                
BOLD = "\033[1m"                                                                
                                                                                
HEADER = '\033[95m'                                                             
WARNING = '\033[93m'                                                            
FAIL = '\033[91m'                                                               
                                                                                
print('\t' + OKGREEN + "Python printing in green color" + ENDC+'\n')            
print('\t' + OKBLUE + "Python printing in blue color" + ENDC +'\n')             
print('\t' + BOLD + "Python printing in bold" + ENDC+'\n')                      
print('\t' + HEADER + "Python printing for header" + ENDC+'\n')                 
                                                                                
print('\t' + WARNING + "Python printing for warning" + ENDC+'\n')               
print('\t' + FAIL + "Python printing for failure" + ENDC+'\n')                              
                                

Output:
$ python color.py 
	Python printing in green color

	Python printing in blue color

	Python printing in bold

	Python printing for header

	Python printing for warning

	Python printing for failure


Python program color continues the same color in next printing statement

Python program printing the lines in color is continue with the same color in next printing statement if ENDC '\033[0m' is not used in current printing statement.

OKBLUE = '\033[94m'                                                             
ENDC = '\033[0m'                                                                
BOLD = "\033[1m"                                                                
                                                                                
print('\t' + OKBLUE + "Python printing in blue color" + '\n')                   
print('\t' + BOLD + "Python printing in blue color and bold" + ENDC+'\n') 

Output:
	Python printing in blue color

	Python printing in blue color and bold


Privacy Policy  |  Copyright@2017 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^