【问题标题】:Termcolor "colored" outputting weird charactersTermcolor“彩色”输出奇怪的字符
【发布时间】:2020-04-07 19:05:41
【问题描述】:

我已将 python 安装到我的命令提示符中(cmd)顺便说一句

命令提示符:

C:\Users\*****> python -m pip install termcolor

Collecting termcolor
  Downloading https://files.pythonhosted.org/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
Installing collected packages: termcolor
  Running setup.py install for termcolor ... done
Successfully installed termcolor-1.1.0
You are using pip version 9.0.1, however version 19.3.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:\Users\*****> python
#going into python now

Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from termcolor import colored
>>> print(colored("hi","green"))

这里是奇怪的输出: [32mhi[0m 我已经尝试过python shell,但它不起作用。(见下图)

【问题讨论】:

标签: python cmd termcolor


【解决方案1】:

如果您是 Windows 用户,则需要多做一个步骤。安装名为 colorama 的模块。然后,在代码的顶部包含以下代码:

from colorama import init
init(autoreset = True)

【讨论】:

    猜你喜欢
    • 2014-03-18
    • 2021-04-23
    • 1970-01-01
    • 2019-06-06
    • 2018-07-22
    • 2018-10-29
    • 2019-07-27
    • 1970-01-01
    相关资源
    最近更新 更多