问题描述
我正在编写一个 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 (将#修改为@)