1

In my python program I am reading from a file and storing the contents in a list. I checked each index of the list so I know it was stored correctly. I am then passing a specific index to a class which contains the color blue. Whenever it gets to the turtle.colorI get an error bad color string: "blue"

For example: Team = Rainbow(str(sequence[0]),str(sequence[1]), str(sequence[2])) //index 2 (str(sequence[2])) contains "blue"

The I have a class

class Rainbow:
    def __init__(self, Rname, Rteam, Rcolor):
       self.name = Rname
       self.team = Rteam
       self.color = Rcolor

       self.Rturtle = turtle.Turtle()

       self.Rturtle.color(self.color)//here is where I get the error

I made sure everything is imported correctly and did some research on the this error and only got issues with bad sequence. Also, if I pass Team = Rainbow("Jay","Blue Jays","blue")I do not get the error.

I was wondering if someone would be able to help

0

1 Answer 1

2

It might be because your colour string also contains unwanted white spaces. Change the 3rd line to self.color = Rcolor.strip() for example to see if it fixes the problem.

Sign up to request clarification or add additional context in comments.

2 Comments

there happened to be a white space issue but I had to fix the text file because .strip() didn't work
I get the same error in Python 2 for e.g. pencolor('red'). Works in Python 3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.