Before you start this course, you must login to Replit

If you have forgotten your Replit account user name or password, ask your Coder Coach.




The ‘investigate’ stage gives students some example code and asks them questions about it to check their understanding. I use the block model to plan my questions. Try it, it’s really useful.

Learning Objectives/Goals

Concept Explanation Code Example
Read Python can only read contents of the file. It cannot modify any information in the file. r my_file = open("test.txt", "r")
Write When python opens the file, it deletes everything inside. Then it can write new information to the file. All old information is lost. w my_file = open("test.txt", "w")
Append Python can add text to the end of the file. This keeps all old information while allowing new information to be added. a my_file = open("test.txt", "a")
Close When done working with a file, the file must be closed. close() my_file.close()

In this unit you will learn about

Files can be opened in either read, write, or append mode.

When working with files, the file is opened and stored in a variable.

my_file = open("test.txt", "r")

Then, once done with the file, it must be closed.


Help!! My code doesen’t work!

  • Not including the file extension (.txt)
  • Consistency between file variable used with open and in the loop.
  • Wrong case in filename. (my_file vs my_File)
  • Not indenting inside loops.
  • Not closing file once task is completed.