[英]Getting error: FileNotFoundError: [Errno 2] No such file or directory when using Python open()
I have seen many similar questions to mine, but still I can't resolve the issue.我已经看到了许多与我类似的问题,但我仍然无法解决问题。 I'd be grateful if someone could help.
如果有人可以提供帮助,我将不胜感激。 I have a folder with 3.txt files (Text1.txt, Text2.txt, & Text3.txt) in it, plus some other files.
我有一个包含 3.txt 文件(Text1.txt、Text2.txt 和 Text3.txt)的文件夹,以及其他一些文件。 I want to read these three files and pass them through a function.
我想读取这三个文件并将它们传递给 function。 I wrote a for loop as follows:
我写了一个for循环如下:
file_list = [f for f in listdir("Path_to_my_files") if
isfile(join("Path_to_my_files",f))]
def Read (files):
for f in files:
if f.endswith (".txt"):
data = open(r'Path_to_my_files/f')
text = data.read()
The error message I get is: FileNotFoundError: [Errno 2] No such file or directory: 'Text1.txt'我得到的错误信息是: FileNotFoundError: [Errno 2] No such file or directory: 'Text1.txt'
What am I doing wrong?我究竟做错了什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.