小编May*_*dar的帖子

Python错误:FileNotFoundError:[Errno 2]没有这样的文件或目录

我正在尝试从文件夹中打开文件并读取它,但是找不到它。我正在使用Python3

这是我的代码:

import os
import glob

prefix_path = "C:/Users/mpotd/Documents/GitHub/Python-Sample-                
codes/Mayur_Python_code/Question/wx_data/"
target_path = open('MissingPrcpData.txt', 'w')
file_array = [os.path.abspath(f) for f in os.listdir(prefix_path) if 
f.endswith('.txt')]
file_array.sort() # file is sorted list

for f_obj in range(len(file_array)):
     file = os.path.abspath(file_array[f_obj])
     join_file = os.path.join(prefix_path, file) #whole file path

for filename in file_array:
     log = open(filename, 'r')#<---- Error is here
Run Code Online (Sandbox Code Playgroud)

Error: FileNotFoundError: [Errno 2] No such file or directory: 'USC00110072.txt'

python file python-3.x

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

标签 统计

file ×1

python ×1

python-3.x ×1