data_sets = [
['O', ['Sheet C', 'Location 2', 'Upright'],
['Sheet B', 'Location 3', 'Upright'],
['Sheet D', 'Location 1', 'Upright'],
['Sheet A', 'Location 4', 'Upright']]
['X', ['Sheet A', 'Location 1', 'Upright'],
['Sheet B', 'Location 2', 'Upright'],
['Sheet C', 'Location 3', 'Upright'],
['Sheet D', 'Location 4', 'Upright']],
]
我需要能够粘贴正确的表到正确的位置。我当前的代码可以转到正确的位置,但它只能粘贴工作表\u a \u直立(),而不能粘贴我想要的工作表例如,它可以与此列表一起工作,但随后它会粘贴一张额外的工作表:
data_sets = [
['O', ['Sheet A', 'Location 1', 'Upright']]
]
代码可以粘贴到正确的位置,但不能粘贴到正确的页上。如果我让它粘贴我在问题开始的前两个列表中的一个,它将只在所有4个位置粘贴工作表A。 我的代码如下:
def goto_loc(data_sets):
for location in data_sets:
if len(location)>1 and 'Location 1' in location[1]:
goto(-300, 0)
sheet()
elif len(location)>1 and 'Location 2' in location[1]:
goto(-100, 0)
sheet()
elif len(location)>1 and 'Location 3' in location[1]:
goto(100, 0)
sheet()
elif len(location)>1 and 'Location 4' in location[1]:
goto(300, 0)
sheet()
#function for which sheet should be drawn from data_sets
def sheet():
for style in data_sets:
if len(style)>1 and 'Sheet A' in style[1]:
sheet_a_upright()
return True
elif len(style)>1 and 'Sheet B' in style[1]:
sheet_b_upright()
return True
elif len(style)>1 and 'Sheet C' in style[1]:
sheet_c_upright()
return True
elif len(style)>1 and 'Sheet D' in style[1]:
sheet_d_upright()
return True
#define sheet outline and fill
def outline():
pencolor('black')
penup()
forward(100)
pendown()
fillcolor('green')
begin_fill()
left(90)
fd(250)
left(90)
fd(200)
left(90)
fd(500)
left(90)
fd(200)
left(90)
fd(250)
right(90)
penup()
end_fill()
#function for sheet A in upright position
def sheet_a_upright():
outline()
def sheet_b_upright():
outline()
def sheet_c_upright():
outline()
def sheet_c_upright():
outline()
# Paste the sheets onto the billboard as per the provided data set
def paste_up(data_sets):
for each in data_sets:
goto_loc(data_sets)
if sheet():
return
#the number i put into data_sets[] depends on which list i want to paste
paste_up(data_sets[0])
如何让代码将正确的工作表粘贴到正确的位置,然后在结束时停止粘贴?(我没有包括图纸A的代码,因为它太长而且不重要,outline函数只是在位置周围画一个边框)
首先,您似乎输入错误-sheet\u c\u直立()定义了两次。你知道吗
其次,所有的表函数都调用outline()——这是有意的吗?如果不是,这可能就是在所有位置绘制相同图纸的原因。你知道吗
相关问题 更多 >
编程相关推荐