PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 24, 2022

[FIXED] Why is the colored module not working for me?

 August 24, 2022     module, python     No comments   

Issue

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.

Code and error message


Solution

It seems like you need lower() (note the parenthesis):

from colored import fg

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


Answered By - j1-lee
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing