環境:Windows8.1, Python3.6 pycharm community 2017
c盤下有一個配置文件:setup
1 with open('c:\\setup','r') as f: 2 f.read()
提示一直很詭異:FileNotFoundError: [Errno 2] No such file or directory: 'c:\\setup'
網上有大量關於Python編碼錯誤導致無法打開文件的解決方法,utf8 gbk2312,嘗試過一遍全部無效
最后原因很烏龍:setup后綴是*.log
換成
1 filename = 'c:\\setup.log'
所有問題解決
PS:所有Windows下的文件路徑,一律用雙反斜杠