0

When I try to print colorful text using print(f"{bcolors.OKGREEN}hello{bcolors.ENDC}") instead of green text, I get "←[92mhello←[0m".

bcolors class:

class bcolors:
    PURP = '\033[95m'
    OKBLUE = '\033[94m'
    OKCYAN = '\033[96m'
    OKGREEN = '\033[92m'
    LIGHTYELLOW = '\033[93m'
    RED = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'

When I run the program via VS Code terminal it prints out green text.

Michael Butscher
  • 10,028
  • 4
  • 24
  • 25
oas333
  • 101
  • 1
  • 1
  • 10
  • 2
    Maybe the codes aren't understood by the terminal. Add information about OS and used terminal emulator. – Michael Butscher Sep 25 '22 at 15:59
  • @MichaelButscher I'm using windows 11 and I just double click the .py file to run it. what do you mean by terminal emulator? (python version: 3.10) – oas333 Sep 25 '22 at 16:03
  • Same problem persists when I use command prompt but when I run the script by vs Code terminal It prints out green text – oas333 Sep 25 '22 at 16:10
  • 2
    A Windows console can behave like a proper terminal emulator (which processes such ANSI sequences correctly) if configured accordingly. See https://stackoverflow.com/questions/36760127/how-to-use-the-new-support-for-ansi-escape-sequences-in-the-windows-10-console how this can be done. – Michael Butscher Sep 25 '22 at 16:30

0 Answers0