python - 一种不必每次都在 colorama 中重置颜色/样式的方法

好吧,我正在使用 Colorama for Python,我正在制作一个基于文本的角色扮演游戏。我需要使用这些颜色有很多原因,我猜主要是因为元素“稀有”。有没有一种方法可以不必每次打印彩色文本时都重置 Fore/Style?我在 Windows 10 上。

我想举个例子

print(Fore.GREEN + "Welcome to my shop, here are my items...")
print("Generic item 1...")

但我不想让第二条打印线变成绿色,而不是每次都重置它。

最佳答案

来自 colorama 包 website ,

If you find yourself repeatedly sending reset sequences to turn off color changes at the end of every print, then init(autoreset=True) will automate that:

from colorama import init
init(autoreset=True)
print(Fore.RED + 'some red text')
print('automatically back to default color again')

https://stackoverflow.com/questions/43649051/

相关文章:

php - Laravel Eloquent : route model binding not w

vim - 将行合并到 vim 中的段落

linux - 错误 "caution: filename not matched"- 解压缩命令

angular - HTML5 Websql - 如何与 Ionic 3 和 Angular 4 一

perl - 在 Perl 中打印哈希值

sql - 在 SQL Server 中将所有表数据类型从文本更改为 varchar

r - 在 shinyapps.io 中部署 R 应用程序 - "Error:parsing man

c# - Unity Particle Collider 与粒子

arrays - Swagger 的对象数组

php - 从当前日期时间生成唯一的交易 ID