python - 为什么 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')
有没有人遇到过这个问题?请提供任何建议,说明为什么会发生这种情况。
解决方案
推荐阅读
- neo4j - 获取 Neo.ClientError.Statement.SemanticError:无法使用空属性合并节点
- recaptcha - 我如何找到 Google ReCaptcha V2 回调函数名称
- html - 合并 HTML 输入?
- java - 如何在从文件读取的每个字节后添加逗号并将字节和逗号写入另一个文件?
- react-native - 只有 Android 用户在 createuserwithemailandpassword 上收到此错误
- node.js - 无法找到尝试使用 Mongoose 创建数据库的模块
- python - 由于某种原因不显示视频
- python - 为什么张量在 Pytorch 中必须是整数?
- ffmpeg - 需要创建一个大小为 720:-1 的电影,并在前 2 秒有延迟
- mysql - 如何更改 MySQL 8.0 数据文件夹。我可以使用 OneDrive 文件夹吗?