如何在python3和sublime3中使用“print”彩色输出

2024-05-13 23:36:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望你们能帮我解决这个问题。 我用的是崇高文本3。一切都很好,但我想打印彩色输出,如打印(“Hello world”,“red”)和带有thr red“Hello world”的输出。不过,我只能在Spyder或Visual Studio代码中执行此操作,在Sublime中,程序总是会给出一个输出:[31mhello[0m[32mworld[0m] 甚至我也试过用colorama或termcolor。也许我的配置有问题。如果可以,请帮帮我

注:我是一个未注册的用户。它们是否仅限于未注册用户?在

非常感谢你的阅读。在

from colorama import Fore, Back, Style
print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Style.RESET_ALL)
print('back to normal now')

或者用termcolor

^{pr2}$

我希望在崇高文本3中有同样的结果。在


Tags: andtext用户文本helloworldstyleback
1条回答
网友
1楼 · 发布于 2024-05-13 23:36:39

我认为您没有在终端中运行python代码。您可以看到输出之间的差异。在

  • 在终端output in terminal window

  • 简单输出enter image description here

As you can see the problem is not with any code editor, but the fact is where you are printing it. If you run the above code using Sublime terminal window you will get the colored output.

Psst…这不是宣传而是我对VS代码的热爱,如果弹出屏幕(试用版),我建议使用VS代码过期时间:-()惹你生气。在

相关问题 更多 >