【问题标题】:How to print text in color without the termcolor module in python如何在没有python中的termcolor模块的情况下以彩色打印文本
【发布时间】:2011-12-28 08:34:57
【问题描述】:

我想知道如何在没有 termcolor 模块的情况下打印彩色文本。 我不想要 termcolor,因为如果有人使用我的脚本并且他没有安装 termcolor 模块,它将无法工作! :( 我在某处读到我可以在这里使用代码:http://www.tux-planet.fr/les-codes-de-couleurs-en-bash/

带打印。 但我就是不能让它工作。

【问题讨论】:

标签: python


【解决方案1】:

您需要打印转义序列。例如,要将 'foo' 打印成红色,试试这个:

print '\x1b[31mfoo\x1b[0m'

要发现转义序列,您可以使用termcolor.colored 函数。

但是,“正常”的方式是简单地依赖termcolor.. 你可以在给他们脚本的同时给他们模块!

【讨论】:

    猜你喜欢
    • 2021-05-28
    • 2023-04-06
    • 2021-12-22
    • 2023-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-16
    • 2019-03-22
    相关资源
    最近更新 更多