Python 使用 Turtle 时出现错误的颜色字符串错误
Bad Color String Error in Python Using Turtle
在我的 python 程序中,我正在读取文件并将内容存储在列表中。我检查了列表的每个索引,所以我知道它存储正确。
然后我将特定索引传递给包含蓝色的 class 。
每当它到达 turtle.color
我得到一个错误 错误的颜色字符串: "blue"
例如:
Team = Rainbow(str(sequence[0]),str(sequence[1]), str(sequence[2])) //index 2 (str(sequence[2])) contains "blue"
我有一个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
我确保所有内容都正确导入并对这个错误进行了一些研究,只遇到了错误序列的问题。另外,如果我通过 Team = Rainbow("Jay","Blue Jays","blue")
我不会收到错误消息。
我想知道是否有人能够提供帮助
这可能是因为您的颜色字符串还包含不需要的空格。例如,将第 3 行更改为 self.color = Rcolor.strip()
以查看它是否解决了问题。
在我的 python 程序中,我正在读取文件并将内容存储在列表中。我检查了列表的每个索引,所以我知道它存储正确。
然后我将特定索引传递给包含蓝色的 class 。
每当它到达 turtle.color
我得到一个错误 错误的颜色字符串: "blue"
例如:
Team = Rainbow(str(sequence[0]),str(sequence[1]), str(sequence[2])) //index 2 (str(sequence[2])) contains "blue"
我有一个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
我确保所有内容都正确导入并对这个错误进行了一些研究,只遇到了错误序列的问题。另外,如果我通过 Team = Rainbow("Jay","Blue Jays","blue")
我不会收到错误消息。
我想知道是否有人能够提供帮助
这可能是因为您的颜色字符串还包含不需要的空格。例如,将第 3 行更改为 self.color = Rcolor.strip()
以查看它是否解决了问题。