如何解决为什么 numpy 显示 IOError("%s was not found." %path)?
我正在编写一个 pygame 程序,我从一个文件夹中导入所有 .csv 文件。我能够导入所有文件,因为我打印了文件名并显示了我所有的 .csv
文件。我的问题是它适用于 file_test1.csv 和 file_test2.csv
但它不能适用于其他文件(file_test3.csv
、file_test4.csv
等)。它给出了来自 IOError("%s not found." % path)
的 _datasource.py file of numpy library
错误。这是我的代码片段:
import pygame
import sys
import os
import csv
import numpy
# Folder Path
path = "D:/Python/Pythonprograms/data"
# Reading out the csv files
def read_text_file(file_path):
with open(os.path.join(path,file_path)) as f:
reader = csv.reader(f)
next(reader,None) # Skip the header
row_count,col_count = numpy.genfromtxt(file_path,delimiter = ',').shape # The error is shown at this point which leads to numpy's _datasource.py file.
# To check if the file exists in the current path
def check_file_names(file_name):
for file in os.listdir(path):
print(file) # I have 6 files in the folder and it correctly displays all the 6 files
if file_name in file and file.endswith(".csv"):
read_text_file(file)
我调用这个函数,文件名(例如:test1
,test2
)是文件夹中文件的前缀名
def test1():
check_file_names('test1')
def test2():
check_file_names('test2')
def test3():
check_file_names('test3')
有人遇到过这个问题吗?请提供任何建议,说明发生这种情况的原因。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。