相关疑难解决方法(0)

Python open()给出IOError:Errno 2没有这样的文件或目录

出于某种原因,我的代码无法打开一个简单的文件:

这是代码:

file1 = open('recentlyUpdated.yaml')
Run Code Online (Sandbox Code Playgroud)

错误是:

IOError: [Errno 2] No such file or directory: 'recentlyUpdated.yaml'
Run Code Online (Sandbox Code Playgroud)
  • 当然,我检查了这是文件的正确名称.
  • 我试过移动文件,给出文件open()的完整路径,似乎没有任何工作.

python file-io file filenotfoundexception file-not-found

56
推荐指数
3
解决办法
30万
查看次数

读取文件python时出错

我正在尝试在目录中读取我的python文件.我收到了一个错误

Traceback (most recent call last):
  File "/home/akallararajappan/codes to handle unicode/read_directory.py", line 42, in <module>
    open_file( filename)
  File "/home/akallararajappan/codes to handle unicode/read_directory.py", line 31, in open_file
    data = open (fil_name, 'r').read()
IOError: [Errno 2] No such file or directory: 'createFile.py' 
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

import os
import codecs
def open_file(fil_name) :
    data = open (fil_name, 'r').read()
    print data 



for dirname, dirnames, filenames in os.walk('/home/akallararajappan/corpus'):
    print()
    #print(dirname + ":")
    for filename in filenames:
        open_file( filename)
Run Code Online (Sandbox Code Playgroud)

这里有什么问题?

python python-2.7

1
推荐指数
1
解决办法
99
查看次数