2014-11-13 105 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 /文本编辑器中进行编程,因此您不必担心这种类型的问题。