失敗,我把一個文本文件,它包括了Python文件的文件夾外,即在父目錄訪問文本文件在Ubuntu
a.txt
folder
myPython.py
以下是我用
for line in open('../a.txt','rb'):
print line
的代碼我在Windows上運行良好,但說
IOError: [Errno 2] No such file or directory: '../a.txt'
在Ubuntu 12.10中,是否有任何問題的規範的路徑?
更新 它的工作原理,當我使用
fn = os.path.join(os.path.dirname(__file__), '../a.txt')
for line in open(fn,'rb'):
print line
我很好奇,爲什麼這是可能的..
你肯定有文件?它在Ubuntu上爲我工作。 – ChillarAnand 2014-11-02 12:49:33
它也適用於我。 – badc0re 2014-11-02 12:50:27
@ChillarAnand謝謝,我更新了一個工作場景的問題..我在Python 2.7中使用Ubuntu 12.10,是嗎? – william007 2014-11-02 12:52:18