Reputation: 31
I'm trying to print colored code in the python shell with ANSI escape codes. My code looks like this:
print("\033[031m" + "Hello" + "\033[0m")
When I run the code in Visual Studio Code it works perfectly fine but if I open it directly in Python 3.8 my output is:[031mHello[0m
Upvotes: 3
Views: 2271
Reputation: 41
With Windows try clearing the screen before the print command:
import os
os.system("cls")
print("\033[031m" + "Hello" + "\033[0m")
Upvotes: 4
Reputation: 746
try to use colorama:
from colorama import Fore, Back, Style
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')
Upvotes: 2