【发布时间】:2021-09-18 12:22:28
【问题描述】:
我正在尝试以不同的颜色打印文本。我已经安装了termcolor,但是当输入:
from termcolor import colored
print(colored("hello","blue"))
它出现了
[34mhello[0m .
【问题讨论】:
我正在尝试以不同的颜色打印文本。我已经安装了termcolor,但是当输入:
from termcolor import colored
print(colored("hello","blue"))
它出现了
[34mhello[0m .
【问题讨论】:
您可以在IPython 中使用此代码,例如Jupyter Notebook 或google colab
!pip install termcolor
from termcolor import colored
print(colored("hello","blue"))
【讨论】:
首先:pip install colorama
还有秒:
from colorama import Fore, Back, Style
print(Fore.GREEN + Back.RED + Style.DIM + "hello world")
(这是一个例子,整个pip包使用*描述click here)
由于某些未知原因,当我打开 CMD 并尝试它不起作用但是当我在 VSCode 中编码并从那里以终端窗口作为 CMD 运行时它工作正常。
【讨论】: