Python 试图使用Colorama时的AttributeError(我知道这不是一个好标题)

Python 试图使用Colorama时的AttributeError(我知道这不是一个好标题),python,python-3.x,colorama,Python,Python 3.x,Colorama,我甚至不知道这个标题是什么,因为我不知道术语。基本上,我有一个我认为是初学者的问题,我找不到答案。下面是我的代码: from colorama import Fore, Back, Style, init init() def colorprint(str1, str2): print(Fore.str2 + str1 + Fore.WHITE) colorprint("words", "GREEN") 但是,正如所料,我不能在“Fore”中使用“str2”,因为它不是它的“选项”(我

我甚至不知道这个标题是什么,因为我不知道术语。基本上,我有一个我认为是初学者的问题,我找不到答案。下面是我的代码:

from colorama import Fore, Back, Style, init
init()
def colorprint(str1, str2):
    print(Fore.str2 + str1 + Fore.WHITE)
colorprint("words", "GREEN")
但是,正如所料,我不能在“Fore”中使用“str2”,因为它不是它的“选项”(我猜)之一

我得到这个错误:
AttributeError:“AnsiFore”对象没有属性“str2”

对不起,不知道如何给东西贴标签。。。我不知道是否调用函数、变量、对象等


我正在使用Python 3。

对象的
Fore
没有
str2
属性,但是您可以使用来获取
Fore。{GREEN}

from colorama import Fore, Back, Style, init
init()
def colorprint(str1, str2):
    print(getattr(Fore, str2) + str1 + Fore.WHITE)
colorprint("words", "GREEN")