python - 更改 python 3.3.2 中的 shell 打印颜色

标签 python shell python-3.x colors

在 Linux 和 Windows shell 中,有什么方法可以更改 python 3.3.2 中的 shell 打印颜色吗?我已阅读所有其他主题,但没有一个适用于此版本,否则我应该导入模块。例如,我想用纯 python 模块这样打印:

enter image description here

。我两个都用!我说他们甚至都没有在 python 3.3 上工作: https://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-pytho

请不要说这是一个重复的问题,因为这些答案都不能在 python 3.3.2 中工作,我想使用默认模块来做到这一点,而不是我应该安装在 python 上的 colorama!

最佳答案

这些可以在 Linux 和 Mac 上运行,但不能在 Windows 上运行。每当我需要对输出进行着色时我都会引用它们。

第一个展示了如何更改颜色。

# snippet found at http://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python

class bcolors:
    WARNING = '\033[95m'
    ENDC = '\033[0m'

print(bcolors.WARNING + "Warning: No active frommets remain. Continue?" + bcolors.ENDC)

第二个显示每个值在您的环境中的显示方式。

for i in range(0, 128):
    print("\033[%imThis is text!!\t\t( \\033[%im )\033[0m" % (i, i))

关于python - 更改 python 3.3.2 中的 shell 打印颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19731053/

相关文章:

python - 序列化器 DRF 中数据的非模型字段

python - 使用 python 和 beautifulsoup4 在网络抓取后重复数据

linux - 有没有办法将以下逻辑放入 grep 命令中?

python - 在 python 中而不是在 shell 中使用 os.system 时出错

linux - 如何在shell中输出返回码?

包对象的 Python 前向引用

python - Gensim Doc2Vec 异常 AttributeError : 'str' object has no attribute 'decode'

python - 获取调用方法的类名

python - 我如何从项目的外键中获取标题

java - 使用 or 进行 Python 赋值