Reading Files
In this page I describe how to access a file for reading in Python. There are various ways we could address this, but in conversation with the staff, we concluded the following would be simplest for everyone, while also teaching a bit about the important cd command in the terminal.
Also available: Krithika Venkatasubramanian made a video explanation of the steps below.
- ALWAYS open your
EECS_183folder in VS Code - not some subfolder likelab_4, etc. If you’re unsure what I’m talking about, please reread this section of tutorial 3. This is very important. If you open a different folder in VS Code then various things will go subtly, and sometimes not-so-subtly, wrong, and it will affect you repeatedly throughout the semester. - When you’re ready to run your code, click the triangle button as usual.
-
You may receive a
FileNotFoundError, looking something like this:Traceback (most recent call last): File "c:\Users\Steve\Documents\EECS_183\labs\lab_4\public_tests.py", line 174, in <module> run_all_tests() ~~~~~~~~~~~~~^^ File "c:\Users\Steve\Documents\EECS_183\labs\lab_4\public_tests.py", line 168, in run_all_tests test_build_game_dictionary() ~~~~~~~~~~~~~~~~~~~~~~~~~~^^ File "c:\Users\Steve\Documents\EECS_183\labs\lab_4\public_tests.py", line 82, in test_build_game_dictionary full = games.build_game_dictionary('games.csv') File "c:\Users\Steve\Documents\EECS_183\labs\lab_4\games.py", line 41, in build_game_dictionary with open(csv_file_name, 'r', encoding='utf-8') as csv_file: ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # primer-spec-highlight-start FileNotFoundError: [Errno 2] No such file or directory: 'games.csv' # primer-spec-highlight-end -
If you get such an error, then next look at the prompt in the terminal, just below the error message. My terminal prompt is shown below; yours may look different in a few ways, but it should show an indication that you are in your
EECS_183folder (not a subfolder).(.venv) Steve@DESKTOP-CDBBVD0:~/Documents/EECS_183 $- If you don’t see an
EECS_183folder indication, please reread this section to make sure that you’re opening yourEECS_183folder in VS Code. - If you need a reminder about terminals, please check this section of tutorial 2.
- If you don’t see an
- We need to figure out what path describes the location of the file you want to read. Find it in the
EXPLORERarea in the left tab of VS Code.- For example, for lab 4, for the file
games.csv, we need the pathlabs/lab_4. - That is,
games.csvis in theEECS_183folder, in thelabssub-folder, in thelab_4sub-sub-folder. - So the final format of the path we need is basically
sub_folder/sub_sub_folder- with a forward slash in between.
- For example, for lab 4, for the file
- Click in the terminal area so you can type at the prompt.
-
Type
cdfollowed by a space, followed by thesub_folder/sub_sub_folderpath to the file you want to read.- For example, for lab 4, you would type
cd labs/lab_4
- For example, for lab 4, you would type
-
Then hit enter. This will change your current directory to the desired sub-sub-folder (e.g.,
lab_4), where the file you want to read (e.g.,games.csv) is located. You should see some indication that you’re in the correct sub-sub-folder in your prompt. Again, your prompt may look a bit different from mine, but here’s mine as an example, for lab 4. Compare / contrast to the terminal prompt from before.(.venv) Steve@DESKTOP-CDBBVD0:~/Documents/EECS_183/labs/lab_4 $cdstands for “change directory”.
- Now, when you hit the arrow to run your code, the Python interpreter will be able to find the file (e.g.,
games.csv) and you should not get aFileNotFoundErroranymore.
Copyright and Academic Integrity
© 2026 Steven Bogaerts.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
All materials provided for this course, including but not limited to labs, projects, notes, and starter code, are the copyrighted intellectual property of the author(s) listed in the copyright notice above. While these materials are licensed for public non-commercial use, this license does not grant you permission to post or republish your solutions to these assignments.
It is strictly prohibited to post, share, or otherwise distribute solution code (in part or in full) in any manner or on any platform, public or private, where it may be accessed by anyone other than the course staff. This includes, but is not limited to:
- Public-facing websites (like a personal blog or public GitHub repo).
- Solution-sharing websites (like Chegg or Course Hero).
- Private collections, archives, or repositories (such as student group “test banks,” club wikis, or shared Google Drives).
- Group messaging platforms (like Discord or Slack).
To do so is a violation of the university’s academic integrity policy and will be treated as such.
Asking questions by posting small code snippets to our private course discussion forum is not a violation of this policy.