colors - 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')
输出
【31msome红色文字
[42mand 有绿色背景
[2mand 在昏暗的文本中
[0米
现在恢复正常
我使用 colorama 库来更改几个单词的字体颜色。不幸的是,它没有返回任何带有各自颜色的行。任何人都可以帮我确定问题吗?提前致谢
解决方案
您的代码可以在我的 Linux 机器上运行,但如果您使用的是 Windows,则必须先调用init()
(根据文档)。代码如下所示:
#!/usr/bin/python3
from colorama import Fore, Back, Style, init
# only required on Windows
init()
# print some example lines
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')
推荐阅读
- html - 如何在 react 中使用 css 拉伸我的背景?(处理溢出)
- javascript - 传入的onClick参数未定义
- r - 如何将 .abs 转换为 .txt,并将其读入 R
- javascript - 如何使用 localstorage 在数组中存储多个随机值
- java - 如何从登录 log4j2 中排除单个类
- javascript - 从 Azure Map 中删除/隐藏/删除一系列功能
- python - 应用程序错误:我的 Flask-web-app 已成功部署在 Heroku 上,但在加载站点时收到应用程序错误
- reactjs - React-native 无限重新渲染
- python - How to merger same column values based on other column values?
- typescript - TS: `unions can't be used in index signatures, use a mapped object type instead` 然后映射对象不作为字符串/数字传递