Python file open() in Enthought Canopy fails with: “IOError No such file or directory”

霸气de小男生 提交于 2019-11-29 04:25:24
punchagan

UPDATE: The following hack is not required in Canopy versions 1.0.3 and greater. Right click inside the Python pane, and select Keep Directory Synced to Editor.

The working directory of the python shell, isn't synchronized with the editor open. So, your python shell's working directory is probably not the same as your python file. To change your shell's directory to your python file's directory:

  1. Open the python file in question.
  2. Right click inside the python pane and select the option "Change to Editor Directory"

Hope that helps.

The solution above is indeed correct. Unfortunately it is necessary even in the current version of Canopy - Version: 1.3.0 (64 bit)

user3890841

It is also possible to open a txt file when giving a complete path in parentheses, to change all \ with /

from:

text=open('C:\Users\Korisnik\Desktop\abeceda.txt')

to:

text=open('C:/Users/Korisnik/Desktop/abeceda.txt')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!