Like taking a colored test to a Python console.

  • I need the message to be green. right in the console♪ Writing code:

    def out_red(text):
        print("\033[31m {}" .format(text))
    def out_yellow(text):
        print("\033[33m {}" .format(text))
    def out_blue(text):
        print("\033[34m {}" .format(text))
    out_red("Вывод красным цветом")
    out_yellow("Текст жёлтого цвета")
    out_blue("Синий текст")

    But it's like,

    [31m Вывод красным цветом
    [33m Текст жёлтого цвета
    [34m Синий текст

    Help me, please.

  • Yay, I got the answer! Here.

    Here's the code:

    import sys

    def cprint(text, color):
    shell_stream =
    except AttributeError:
    raise RuntimeError("Use IDLE")
    shell_stream.write(text, color)


    cprint('Hello, world', 'KEYWORD')
    cprint('How are you?', 'STRING')

Log in to reply

Suggested Topics