在python程序中,我从一个文件中读取并将内容存储在一个列表中。我检查了列表的每个索引,所以我知道它存储正确。
然后我将一个特定的索引传递给一个包含蓝色的类。
每当它到达turtle.color
时,我就会得到一个错误错误的颜色字符串:“blue”
例如:
Team = Rainbow(str(sequence[0]),str(sequence[1]), str(sequence[2])) //index 2 (str(sequence[2])) contains "blue"
我要上课
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")
,我不会得到错误。在
我想知道是否有人能帮忙
这可能是因为你的颜色串也包含了不需要的空白。例如,将第三行改为
self.color = Rcolor.strip()
,看看它是否解决了问题。在相关问题 更多 >
编程相关推荐