0
我对python完全陌生。 我想读,我已经创建了一个文件,但提示以下错误:Python:无法打开和读取文件
File "C:/Python25/Test scripts/Readfile.py", line 1, in <module>
filename = open('C:\Python25\Test scripts\newfile','r')
IOError: [Errno 2] No such file or directory: 'C:\\Python25\\Test scripts\newfile
我的代码:
filename = open('C:\Python25\Test scripts\newfile','r')
print filename.read()
我也试过
filename = open('C:\\Python25\\Test scripts\\newfile','r')
print filename.read()
但同样的错误我得到。
'newfile'是否有扩展名(如'.txt')? – 2014-11-02 21:25:02
我会添加.txt扩展名,另外我会删除Test与脚本之间的空间,并用下划线替换它(即重命名该目录,如果它确实有空格)。 – 2014-11-02 21:43:41