Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 术语“颜色”;彩色的;输出奇怪的字符_Python_Cmd_Termcolor - Fatal编程技术网

Python 术语“颜色”;彩色的;输出奇怪的字符

Python 术语“颜色”;彩色的;输出奇怪的字符,python,cmd,termcolor,Python,Cmd,Termcolor,顺便说一句,我已经在命令提示符(cmd)中安装了python 命令提示: C:\Users\*****> python -m pip install termcolor Collecting termcolor Downloading https://files.pythonhosted.org/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar

顺便说一句,我已经在命令提示符(
cmd
)中安装了python

命令提示:

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,但它不起作用。(见下图)

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


基于,它有ANSI颜色格式,这些是ANSI颜色序列,但您的命令提示符不支持它们。您需要彩色文本吗?如果需要,请参阅示例,您可能希望使用Colorama以获得更好的跨平台支持。只有一种方法始终有效。请参阅此处的答案。任何其他技术都取决于系统配置是否有效。@马克,请查看我所做的编辑
from colorama import init
init(autoreset = True)