2017-07-28 59 views
0

我在Ubuntu系統上學習python。我嘗試讀取文件時出現錯誤。python [Errno 2]沒有這樣的文件或目錄:

fw = open(outfile,"a") 
outfile = 'sougou/Reduced/C000008_pre.txt' 

IOError: [Errno 2] No such file or directory: 'sougou/Reduced/C000008_pre.txt' 
+0

「sougou」不存在或「sougou/Reduced」不存在 –

+0

你在哪裏調用Python腳本?或者這是在一個交互式終端? –

回答

2

沒有任何額外的信息,我可以在這裏看到兩種可能性。

  1. 您試圖訪問的文件不存在。

  2. 該文件的路徑不正確相對於您要從中調用Python腳本的位置。

嘗試提供的絕對路徑的文件,看看是否能解決您的問題:

outfile = '/some/path/here/sougou/Reduced/C000008_pre.txt' 
0
  1. 也許文件sougou/Reduced/C000008_pre.txt不存在
  2. 腳本不會被放在目錄其中包含sougou目錄
  3. 您應該在打開後關閉文件:fw.close()或使用with open(outfile,"a") as fw:更好
相關問題