【发布时间】:2021-12-12 16:49:26
【问题描述】:
我正在学习 NumPy 库,当我尝试从文件中读取某些内容时,出现以下错误:
Traceback (most recent call last):
File "c:\Users\user\Desktop\folder\Reading_from_file.py", line 3, in <module>
example = genfromtxt("example.txt", delimiter=',')
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\lib\npyio.py", line 1793, in genfromtxt
fid = np.lib._datasource.open(fname, 'rt', encoding=encoding)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\lib\_datasource.py", line 193, in open
return ds.open(path, mode, encoding=encoding, newline=newline)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\lib\_datasource.py", line 533, in open
raise IOError("%s not found." % path)
OSError: example.txt not found.
代码如下:
from numpy import genfromtxt
example = genfromtxt("example.txt", delimiter=',')
Reading_from_file.py 和 example.txt 在同一个文件夹中
我阅读了documentation 并试图在这里找到一些东西但什么也没找到(也许我错过了一些东西)
如果已经有这个话题的帖子,请链接到它
【问题讨论】:
-
您从哪个文件夹运行脚本?
-
我使用了 Visual Studio 代码,我是这样做的:PS C:\Users\user> & C:/Users/user/AppData/Local/Programs/Python/Python39/python.exe c :/Users/user/Desktop/folder/Reading_from_file.py 这是一个问题,谢谢。写为答案,以便我标记为最佳。
-
这就是问题所在。您需要先运行
cd c:/Users/user/Desktop/folder/。看我的回答。
标签: python numpy file-not-found