1. 程式人生 > >關於使用python的open函數出現No Such file or dir的錯誤

關於使用python的open函數出現No Such file or dir的錯誤

我寫的程式碼如下:

1 2 3 4 5 6 7 def createFileWithFileName(localPathParam,fileName):  totalPath=local_url+'\\'+fileName  if not os.path.exists(totalPath): print totalPath  file=open(totalPath,'w+' file.close()  return totalPath 

起初時local_url使用的是絕對路徑:F:程式名/imgs

但是了程式一直報No such file or dir的錯,後來發現只要換為相對路徑即可,

../imgs,程式執行成功