[英]Python: error IOError: [Errno2] bad interpretation of file or directory
我正在嘗試讀取csv文件,並且解釋器通過復制\\返回錯誤的目錄。
> result = [[urlparse(u).netloc] for u in file ('S:\Dev\Python\BDDtest.csv')]
>>IOError: [Errno 2] No such file or directory: 'S:\\\Dev\\\Python\\\BDDtest.csv'
當我將其放入ufile ='S:\\Dev\\Python\\BDDtest.csv'
並打印時,結果將正確解釋
但是當我嘗試
> result = [[urlparse(u).netloc] for u in file (ufile)]
它返回相同的錯誤...
任何人作為修復或解釋
也許使用os.path.abspath進行黑客入侵會有所幫助?
import os
result = [[urlparse(u).netloc] for u in
file(os.path.abspath('S:\Dev\Python\BDDtest.csv'))]
您也可以嘗試顯式使用ntpath:
import ntpath
result = [[urlparse(u).netloc] for u in
file(ntpath.abspath('S:\Dev\Python\BDDtest.csv'))]
您可以嘗試將\\
替換為/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.