为什么彩色模块对我不起作用?
我正在尝试使用python中的彩色模块来更改打印功能发出的文本的颜色。我没有收到错误说未检测到该模块的错误,但是我不确定我在做什么错。我有错误代码以及实际代码。
11 from colored import fg
...
29 color = input("What is your favorite color?\n")
30 col = fg(color.upper)
31 print(col + "Message")
现在输入错误消息:
trackback(最近的呼叫最新电话):文件“ [此文件的路径],第30行 in<模块> col = fg(color.upper)文件“ c:\ python310 \ lib \ site-packages \ colored \ colored \ colored.py”,第431行,在FG中 返回彩色(颜色).foreground()文件 “ c:\ python310 \ lib \ site-packages \ colored \ colored.py”,第333行,in 前景 elif self.color.startswith(“#”):attributeError:'hindin_funciton_or_method'对象没有属性'startswith'ps [持有此文件的文件夹]
对不起,如果这是一个微不足道的问题,我仍然刚开始。提前致谢。
I'm trying to use the colored module in Python to change the color of the text put out by the print function. I'm not receiving an error saying that the module isn't detected, but I'm not sure what I'm doing wrong. I have the error code, as well as the actual code.
11 from colored import fg
...
29 color = input("What is your favorite color?\n")
30 col = fg(color.upper)
31 print(col + "Message")
and now for the error 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]
Sorry if this is a trivial problem, I'm still starting out. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎您需要
lower()
(请注意括号):It seems like you need
lower()
(note the parenthesis):