2016-05-17 87 views
1

我正在製作一個程序來演示使用matplotlib的不同類型的圖表,並且我遇到了用戶輸入問題。輸入字符串錯誤EOF

自從我創建它之後,我的程序一直在工作,但是當我在啓動時運行它時,出現錯誤,我無法弄清楚原因。

下面是引發錯誤

if options == 0: 
      fileX = input("Enter the file of x coordinates > ") 
      fileY = input("Enter the file of y coordinates > ") 
      title = input("Enter title for the graph > ") 
      xlabel = input("Enter a name for the x-axis > ") 
      ylabel = input("Enter a name for the y-axis > ") 
      g.linegraph(title, xlabel, ylabel, fileX, fileY) 

這裏的代碼錯誤(我的文件的名稱是10int1和10int2)

Traceback (most recent call last): 
    File "/home/sam/Documents/GraphDemo/src/GraphDemo.py", line 25, in <module> 
    fileX = input("Enter the file of x coordinates > ") 
    File "<string>", line 1 
    10int1 
     ^
SyntaxError: unexpected EOF while parsing 

有人可以幫助解釋爲什麼這個錯誤正在拋出?它一直在努力,直到現在。我嘗試了不同的文件,以及不同的輸入方式,但每次都收到相同的錯誤。

回答

1

你正在運行Python 2.7嗎?

如果是這樣,input會嘗試將輸入評估爲Python表達式。當您輸入10int1作爲輸入時,它會嘗試將其評估爲字符串,而不是 - 沒有開始/結束引號。

相反,你應該使用raw_input,它只是返回一個字符串(不嘗試評估)。然後,您應該將該輸入轉換爲整數或任何您需要的類型。

+0

這個工作,但後來我得到了另一個錯誤,因爲我從'def linegraph(self,title,xlabel,ylabel,fileX,fileY)中刪除'self':'然後當我讀'self'來修復它時再次停止工作錯誤 – sbowde4

+1

不知道上面的評論。我只是清理了代碼,它工作 – sbowde4