2017-04-18 41 views
0

我在做數據庫的東西,我有這樣的代碼爲什麼這個'except:'行拋出語法錯誤?

for res_posts in list_of_response_ids: 
    temp_str = res_posts[0] # first element of res_posts tuple is string 
    temp_str += ":" + output 
    try: 
     cursor.execute("INSERT INTO POST (res_post_id) where post_id = '%s';" % (temp_str, res_posts(1)) 
    except: 
     print "life sucks" 
db.close() 

語法錯誤被拋出,像這樣:

$ python post.cgi 
    File "post.cgi", line 85 
    except: 
    ^
SyntaxError: invalid syntax 

這究竟是爲什麼?如果您需要更多信息,我可以發佈更多代碼。

謝謝!

+4

標準過程中,您沒有得到:回去線,檢查你的括號。 – user2357112

+0

這是一個好主意,我會牢記這一點。謝謝! – Azhraam

回答

3

你缺少一個括號中的語法錯誤

cursor.execute("INSERT INTO POST (res_post_id) where post_id = '%s';" % (temp_str, res_posts(1)))###<---Here 
+0

哈哈,我看着那條線,但沒有注意到我的錯誤。非常感謝你! – Azhraam

相關問題