I'm learning the NumPy library and when I try to read something from the file I get this error:
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.
Here's the code:
from numpy import genfromtxt
example = genfromtxt("example.txt", delimiter=',')
Reading_from_file.py
and example.txt
are in the same folder
I read the documentation and I was trying to find something here but found nothing (maybe I missed something)
If there is already a thread on this topic, please link to it
CodePudding user response:
You probably aren't running the script from the same folder that example.txt
is in. example.txt
doesn't need to be in the same directory as the script itself, it needs to be in the same directory as you are when you're running the script.