为什么彩色模块对我不起作用?

Why is the colored module not working for me?

我正在尝试使用 Python 中的彩色模块来更改打印功能输出的文本的颜色。我没有收到说未检测到模块的错误消息,但我不确定自己做错了什么。我有错误代码,也有实际代码。

11 from colored import fg
...
29 color = input("What is your favorite color?\n")
30 col = fg(color.upper)
31 print(col + "Message")

现在是错误消息:

Traceback (most recent call last): File "[this file's path], line 30 in <module> col = fg(color.upper) File "C:\Python310\lib\site-packages\colored\colored.py", line 431, in fg return colored(color).foreground() File "C:\Python310\lib\site-packages\colored\colored.py", line 333, in foreground elif self.color.startswith("#"): AttributeError: 'builtin_funciton_or_method' object has no attribute 'startswith' PS [Folder holding this file]

抱歉,如果这是一个小问题,我还处于起步阶段。提前致谢。

Code and error message

看来你需要lower()(注意括号):

from colored import fg

color = "Red"
print(fg(color.lower()) + "hello")