我是Python学习的新手,发现了colorama。作为一个测试项目,我想打印出所有可用的colorama颜色。
from colorama import Fore
from colorama import init as colorama_init
colorama_init(autoreset=True)
colors = [x for x in dir(Fore) if x[0] != "_"]
for color in colors:
print(color + f"{color}")
当然,这会输出完全黑色的输出结果,如下所示:
BLACKBLACK
BLUEBLUE
CYANCYAN
...
由于Dir(Fore)
只会给出Fore.BLUE
, Fore.GREEN
等颜色属性的字符串表示形式,所以有没有一种方法可以访问所有的前景色属性,使它们实际起作用:
print(Fore.BLUE + "Blue")
换句话说,这可能更好地表达了我的问题。
我想写下这个:
print(Fore.BLACK + 'BLACK')
print(Fore.BLUE + 'BLUE')
print(Fore.CYAN + 'CYAN')
print(Fore.GREEN + 'GREEN')
print(Fore.LIGHTBLACK_EX + 'LIGHTBLACK_EX')
print(Fore.LIGHTBLUE_EX + 'LIGHTBLUE_EX')
print(Fore.LIGHTCYAN_EX + 'LIGHTCYAN_EX')
print(Fore.LIGHTGREEN_EX + 'LIGHTGREEN_EX')
print(Fore.LIGHTMAGENTA_EX + 'LIGHTMAGENTA_EX')
print(Fore.LIGHTRED_EX + 'LIGHTRED_EX')
print(Fore.LIGHTWHITE_EX + 'LIGHTWHITE_EX')
print(Fore.LIGHTYELLOW_EX + 'LIGHTYELLOW_EX')
print(Fore.MAGENTA + 'MAGENTA')
print(Fore.RED + 'RED')
print(Fore.RESET + 'RESET')
print(Fore.WHITE + 'WHITE')
print(Fore.YELLOW + 'YELLOW')
简而言之:
for color in all_the_colors_that_are_available_in_Fore:
print('the word color in the representing color')
#or something like this?
print(Fore.color + color)