pythontermcolor

I can not properly output the color text in python


when use this code:

from termcolor2 import colored

print(colored('hello', 'red'), colored('world', 'green'))

my output in terminal is :←[31mhello←[0m ←[32mworld←[0m

whats the problem?


Solution

  • You can use colorama module

    pip install colorama
    

    Code:

    from colorama import init, Fore, Back
    
    init(convert=True)    # Initialize colorama module
    print(Fore.RED + 'Your Text' + Fore.RESET)    # Red colored output
    print(Back.GREEN + 'Your Text' + Back.RESET)  # Green Backgroung Output
    

    More Details - https://pypi.org/project/colorama/