如何使用 python 更改命令提示符中某个打印行的颜色?

How to change the color of a certain print line in command prompt with python?

有没有办法改变某个打印行的颜色样式在 CMD 中使用 Python?

我想直接在 CMD 中使用 python 命令更改文本颜色

我试过了:

import colorama
from colorama import Fore

print(Fore.RED + 'This text is red in color')

print("3[1;32m This text is Bright Green  \n")


from colored import fg
print ('%s Hello World !!! %s' % (fg(1), attr(0)))

但是 none 它有效。他们只是在短时间内打开一个新的 window。

尝试从 colorama

添加 init() 命令
import colorama
from colorama import Fore, init

init()

print(Fore.RED + 'This text is red in color')

print("3[1;32mThis text is Bright Green  \n")

Colorama Help

然后 运行 来自 CMD 的 python 脚本,类似这样的东西

C:\...>colouredText.py

输出