i want to use colors in my python terminal output format for print function. I have tried the following codes:
from colorama import Fore, Back, Style
print('\033[1;41mHighlighted Red like Radish\033[1;m')
print('\x1b[6;30;42m' + 'Success!' + '\x1b[0m')
prt = "Hello world!"
print("\033[94m {}\033[00m" .format(prt))
print("\033[1;32;40m Bright Green \n")
print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Style.RESET_ALL)
print('back to normal now')
As you can see I have also tried importing the colorama module but nothing. On the internet, googling there seems to be a lot of information about it, the problem is that it seems a bit outdated because print is no longer an instruction but a function. My python version is 3.4.4 and my IDLE version is 3.4.3
Thank you very much in advance.
On Windows, CMD has traditionally not supported ANSI escape sequences without using some external patch. For colorama to work properly in CMD/PowerShell it is necessary to use the class
init
and force the conversion of ANSI escape sequences to legitimate Win32 api calls. From the official documentation of**colorama**
:Free translation:
The following code is valid and tested on Windows 7, 8, 10, it should work on XP and other Windows distributions as well:
Departure: