2014-11-13 132 views
0

我的代碼在今天早些時候工作得很好,直到我改變了我正在使用的幾個庫。Python 2.7.5變量名稱語法錯誤

File "wimmer.py", line 29 
category = raw_input('Give me a category: ') 
    ^
SyntaxError: invalid syntax 

我不太清楚什麼是錯的:現在,當我嘗試運行代碼,我得到這個錯誤。有什麼建議麼?

代碼:(壓痕稍微偏離)

browser = Browser() 

book = open_workbook(join('googleurls.xls'), formatting_info=True, on_demand=True) 
testcell = book.sheet_by_index(0).cell(0,15).value 
print ('The test link is: %s' % (testcell)) 
raw_input("Press ENTER to continue") 



with book as myfile: 

for i in range(0, 9): 
    line = book.sheet_by_index(0).cell(i,15).value 
    #for line in myfile: 

    browser.visit(line) 
    print ('The link is: %s' % (line)) 
    print ('The search term is: %s' % (myfile.cell(i, 0)) 
    #enter terminal prompts 

    category = raw_input('Give me a category: ') 
    print ('Your category was %s' % (category)) 
    #put this in the excel sheet in the right column 

    fusion = raw_input('Fuse with another? ') 
    print('Term was fused with %s' % (fusion)) 
    #put this in the excel sheet in the right column 

    translate = raw_input('Change translation to -? ') 
    print('Term was translated to %s' % (translate)) 
    #put this in the excel sheet in the right column 

    raw_input("Press ENTER to continue") #moves onto next link 
+8

那條線很好。檢查上面的一個(s)缺少括號/括號/等。 – iCodez

+1

你能展示周圍的線條嗎? –

+0

我對[這個問題]的評論(http://stackoverflow.com/questions/26917678/python-programming-syntax-error-for-game)was soooo true ... – Matthias

回答

0

通常,當python(或其他語言)解析一個文件,並且文件中有錯誤時,它會認爲問題出現在這行之後 - 這是因爲它會將錯誤與第一行相互交織指令的一部分,下一行作爲第二部分。第一部分是可以的(除了不完整),但是當它試圖讀取下一部分時,它沒有任何意義(因爲它應該是一個單獨的指令)。

查看之前的行,確保所有括號中的括號對齊。

+0

太好了,謝謝!這是一個簡單的括號問題。 – Neamah

0

你的錯誤是別的地方在你的程序(可能缺少一個右括號,或類似的東西,上面有幾行)。

爲了將來的參考,當提問「爲什麼X是一個語法錯誤?」時,總是向我們提供確實會導致錯誤的完整文件。

0

你行

print ('The search term is: %s' % (myfile.cell(i, 0)) 

缺少最終)。這是造成語法錯誤。未來,我會推薦在支持自動括號匹配的IDE /文本編輯器中進行編程,因此您不必擔心這種類型的問題。