0

我试图弄清楚为什么在尝试使用该程序时会出现语法错误。当我使用填充列表时,这段代码运行良好,但是,我决定使用数组,因为我可以根据自己的喜好操作数据。

这是代码:

#Frame Creation

frames=[]

for n in range (0, (workingframes*archnodes*3)):
    frames.append( )


frames = array(frames)                                    #generates array
frames = reshape(frames, ((archnodes*3),workingframes)    #reshapes array




#Frame Population

for f in range (0, workingframes):

    if f<=(workingframes/2):

        for x in range (0, (archnodes)):
            frames[(archnodes*3)].insert((archnodes*3), (archstartred[x]))
            frames[(archnodes*3)+1].insert(((archnodes*3)+1),(archstartgrn[x]))
            frames[(archnodes*3)+2].insert(((archnodes*3)+2),(archstartblu[x]))

        for y in range (0, nodesperframe):
            archstartred.pop()
            archstartgrn.pop()
            archstartblu.pop()
            archstartred.insert(0, backred)
            archstartgrn.insert(0, backgrn)
            archstartblu.insert(0, backblu)

    else:
        for y in range (0, nodesperframe):
            archstartred.pop(0)
            archstartgrn.pop(0)
            archstartblu.pop(0)
            archstartred.append(backred)
            archstartgrn.append(backgrn)
            archstartblu.append(backblu)

        for x in range (0, (archnodes)):
            frames[(archnodes*3)].insert((archnodes*3), (archstartred[x]))
            frames[(archnodes*3)+1].insert(((archnodes*3)+1),(archstartgrn[x]))
            frames[(archnodes*3)+2].insert(((archnodes*3)+2),(archstartblu[x]))

我不断收到此错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "backandforth3.py", line 99
    for f in range (0, workingframes):
                                     ^
SyntaxError: invalid syntax

我尝试对“f”使用不同的值。我试过删除冒号(这会导致其他语法错误。)我错过了什么?

4

2 回答 2

4

问题在这里:

frames = reshape(frames, ((archnodes*3),workingframes)    #reshapes array

你有三个(和两个)。Python 认为 reshape() 调用没有在行尾结束,因此它继续向下执行文件,直到遇到forand :,这在函数调用中没有意义。

于 2012-07-24T19:44:13.843 回答
2

缺少括号:

frames = reshape(frames, ((archnodes*3),workingframes)
于 2012-07-24T19:44:06.670 回答