So the problem is that whenever I run file_reader.py (from Eric Matthes’s Python Crash Course) it tells me:
File "C:\Users\My Name\AppData\Local\Programs\Python\Python314\Lib\pathlib\__init__.py", line 792, in read_text
with self.open(mode='r', encoding=encoding, errors=errors, newline=newline) as f:
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\My Name\AppData\Local\Programs\Python\Python314\Lib\pathlib\__init__.py", line 776, in open
return io.open(self, mode, buffering, encoding, errors, newline)
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
And just so you know “my name” is just a place holder for… well my name.
For reference, the file_reader.py is supposed to read pi_digits.txt. Here’s both of their codes:
from pathlib import Path
path = Path("pi_digits.txt")
contents = path.read_text().
print(contents)
3.1415926535
8979323846
2643383279
My best guess is that it has to do with the username of the user. Before it was “My Name” and I think the space was interfering with it, so I changed it to “Me” which did appear in some spaces but not, of course, the command prompt or Visual Studios.
However, I notice that there are some exceptions to this problem:
- So whenever I run it from the command prompt it… works just fine.
- If I do the
ctrl + k + othing that changes which files are shown and I change it tochapterten(where bothfile_reader.pyandpi_digits.txtare) it also works just fine, which is probably because it doesn’t have the space in it there because it’s just that one folder.
I probably should note I’m very new to coding, so I don’t know much about this.
Thanks in advance to anyone who helps!