Python 海龟图形绘制

Python 海龟图形绘制,python,list,turtle-graphics,Python,List,Turtle Graphics,我试图将一个文件解析为一个列表,然后使用海龟图形绘制列表中的形状。我成功地解析了文件并将其作为列表返回,但是,当我尝试使用turtle graphics在文件中绘制形状时,我遇到了一个错误。代码如下: list_of_shapes = parser.parse(local_file_name) # this will parse the file into a list drawer = Turtle_Draw_Shape_Controller() drawer.draw_shapes(list

我试图将一个文件解析为一个列表,然后使用海龟图形绘制列表中的形状。我成功地解析了文件并将其作为列表返回,但是,当我尝试使用turtle graphics在文件中绘制形状时,我遇到了一个错误。代码如下:

list_of_shapes = parser.parse(local_file_name) # this will parse the file into a list
drawer = Turtle_Draw_Shape_Controller()
drawer.draw_shapes(list_of_shapes)
一旦我尝试使用乌龟图形绘制图片,我会出现以下错误:

Traceback (most recent call last):
  File "/Volumes/shapes.py, line 206, in <module>
    drawer.draw_shapes(list_of_shapes)
  File "/Volumes/shapes.py", line 184, in draw_shapes
    shape_type = shape.get_shape_type()
AttributeError: 'tuple' object has no attribute 'get_shape_type'
回溯(最近一次呼叫最后一次):
文件“/Volumes/shapes.py,第206行,在
抽屉。绘制形状(形状列表)
文件“/Volumes/shapes.py”,第184行,绘制形状
shape\u type=shape.get\u shape\u type()
AttributeError:“tuple”对象没有属性“get\u shape\u type”

您的形状分析器函数正在向
形状列表添加元组,例如:

shapes_list.append(("c",cir))
然后,您将尝试将这些对象直接用作形状。或者将解析器更改为仅附加形状本身:
shapes\u list.append(cir)
,或者在
draw
方法中使用形状对象之前,先从元组中解压缩形状对象:

for shape_type, shape in shapes:

如果每个形状对象已经有一个
get\u shape\u type
方法,我不确定为什么要从外部附加类型。

我将代码更改为shapes\u list.append(cir)用于所有形状,但它给了我这个错误“AttributeError:'list'对象没有属性“get\u shape\u type”“其他所有内容我都没有改变。基本调试提示:尝试
print shape
,在出现错误之前,查看您的错误。它应该是一个形状,而不是一个列表,否则会有其他错误。