10. File Handling

Python can use text files to store data in or to read data from. This allows for a huge amount of possibilities in your programming.

The first thing to know about using files in Python that there are two ‘modes’ –

  • Write Mode – Saving data to a file to edit its contents.
  • Read Mode – Opening an existing file and reading its contents.

You must open your file in the right ‘mode’ by using ‘wt’ for write mode and ‘rt’ for read mode.

Also remember that every file must be opened and should be closed to use properly.

Welcome to Section Ten! Click on the links to find out how to use external files with your Python programs:

Open and Write to Files

Read from and Search through Files

When you have read the pages above and tried the practice task(s) on each page then attempt these:

End of Section Practice Tasks