gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 09:06:53 25 4
gpt4 key购买 nike

有没有办法在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com