Search code examples
pythonpython-3.xpython-2.7colorstermcolor

instead of getting a color i get this [31mHello World !!![0m using termcolor and colored


I tried using different methods, the results are the same in cmd and poweshell however i couldnt get it to show the color. The code i used:

from termcolor import *
print(colored('Hello World !!!', "red"))

Output:

"[31mHello World !!![0m"

I get this weird charachters around "Hello World !!!" and it doesn't appear colored.


Solution

  • If you run your code in linux it would give you your desired output not in windows. Powershell does support coloring of output, you need to specify -ForegroundColor parameter like

    Write-Host "PREREQUISITIES" -ForegroundColor Cyan