一个奇怪的python“if”语法错误

时间:2012-03-28 06:59:46

标签: python syntax if-statement python-3.2

我收到此错误:我的“if”语句中的Invaild语法和rly无法说明原因,你们中的任何人都可以帮助我吗?我正在使用python 3.2 这是我的代码的一部分,错误我的代码:

L = list()
LT = list()
tn = 0
players = 0
newplayer = 0
newplayerip = ""
gt = "start"
demsg = "start"
time = 1
status = 0
day = 1
conclient = 1
print("DONE! The UDP Server is now started and Waiting for client's on port 5000")
while 1:
    try:
        data, address = server_socket.recvfrom(1024)
        if not data: break
        ################### reciving data! ###################
        UPData = pickle.loads(data)
        status = UPData[0][[0][0]
        if status > 998: ##### it is here the error are given####
            try:
                e = len(L)
                ori11 = UPData[0][1][0]
                ori12 = UPData[0][1][1]
                ori13 = UPData[0][1][2]
                ori14 = UPData[0][1][3]
                ori21 = UPData[0][1][4]
                ori22 = UPData[0][1][5]
                ori23 = UPData[0][1][6]
                ori24 = UPData[0][1][7]
                ori31 = UPData[0][2][0]
                ori32 = UPData[0][2][1]
                ori33 = UPData[0][2][2]
                ori34 = UPData[0][2][3]
                ori41 = UPData[0][2][4]
                ori42 = UPData[0][2][5]
                ori43 = UPData[0][2][6]
                ori44 = UPData[0][2][7]
                ori51 = UPData[0][3][0]
                ori52 = UPData[0][3][1]
                ori53 = UPData[0][3][2]
                ori54 = UPData[0][3][3]
                ori61 = UPData[0][3][4]
                ori62 = UPData[0][3][5]
                ori63 = UPData[0][3][6]
                ori64 = UPData[0][3][7]
                ori71 = UPData[0][4][0]
                ori72 = UPData[0][4][1]
                ori73 = UPData[0][4][2]
                ori74 = UPData[0][4][3]
                ori81 = UPData[0][4][4]
                ori82 = UPData[0][4][5]
                ori83 = UPData[0][4][6]
                ori84 = UPData[0][4][7]
                ori91 = UPData[0][5][0]
                ori92 = UPData[0][5][1]
                ori93 = UPData[0][5][2]
                ori94 = UPData[0][5][3]
                ori101 = UPData[0][5][4]
                ori102 = UPData[0][5][5]
                ori103 = UPData[0][5][6]
                ori104 = UPData[0][5][7]
                npcp11 = UPData[0][6][0]
                npcp12 = UPData[0][6][1]
                npcp13 = UPData[0][6][2]
                npcp21 = UPData[0][6][3]
                npcp22 = UPData[0][6][4]
                npcp23 = UPData[0][6][5]
                npcp31 = UPData[0][6][6]
                npcp32 = UPData[0][6][7]
                npcp33 = UPData[0][7][0]
                npcp41 = UPData[0][7][1]
                npcp42 = UPData[0][7][2]
                npcp43 = UPData[0][7][3]
                npcp51 = UPData[0][7][4]
                npcp52 = UPData[0][7][5]
                npcp53 = UPData[0][7][6]
                npcp61 = UPData[0][7][7]
                npcp62 = UPData[0][8][0]
                npcp63 = UPData[0][8][1]
                npcp71 = UPData[0][8][2]
                npcp72 = UPData[0][8][3]
                npcp73 = UPData[0][8][4]
                npcp81 = UPData[0][8][5]
                npcp82 = UPData[0][8][6]
                npcp83 = UPData[0][8][7]
                npcp91 = UPData[1][0][0]
                npcp92 = UPData[1][0][1]
                npcp93 = UPData[1][0][2]
                npcp101 = UPData[1][0][3]
                npcp102 = UPData[1][0][4]
                npcp103 = UPData[1][0][5]
                d0 = (status, )
                d1 = (ori11,ori12,ori13,ori14,ori21,ori22,ori23,ori24)
                d2 = (ori31,ori32,ori33,ori34,ori41,ori42,ori43,ori44)
                d3 = (ori51,ori52,ori53,ori54,ori61,ori62,ori63,ori64)
                d4 = (ori71,ori72,ori73,ori74,ori81,ori82,ori83,ori84)
                d5 = (ori91,ori92,ori93,ori94,ori101,ori102,ori103,ori104)
                d6 = (npcp11,npcp21,npcp31,npcp21,npcp22,npcp23,npcp31,npcp32)
                d7 = (npcp33,npcp41,npcp42,npcp43,npcp51,npcp52,npcp53,npcp61)
                d8 = (npcp62,npcp63,npcp71,npcp72,npcp72,npcp81,npcp82,npcp83)
                d9 = (npcp91,npcp92,npcp93,npcp101,npcp102,npcp103)
                pack1 = (d0,d1,d2,d3,d4,d5,d6,d7,d8)
                pack2 = (d9, )
                dat = pickle.dumps((pack1,pack2))
                while tn < e:
                    server_socket.sendto(dat, (L[tn],3560))
                    tn = tn + 1
            except:
                pass
                print("could not send data to some one or could not run the server at all") 
        else:

控制台告诉我我的错误的部分在这里:

if status > 998:

1 个答案:

答案 0 :(得分:4)

问题在于:

status = UPData[0][[0][0]

第二个打开的括号[未关闭。 Python编译器一直在寻找结束括号,在下一行找到if并感到困惑,因为if不应该在括号内。

根据您的具体需求(UPData的结构)

,您可能需要删除此括号或将其关闭