Skip to content

Study Hub

Study Guides

This pupil-friendly study guide includes a unit summary, clear notes, common mistakes, and quick questions with answers.

Year 11 - Computing

Writing to text files

Programming: dictionaries and data files

Unit Summary

This unit introduces pupils to the new data structures of records and dictionaries. They will develop a Caesar cipher encryption program using a dictionary as a cipher wheel. Pupils will explore how data can be read from and written to files and how this data can be used within a program.

Lesson Summary

You will learn to write data to a new file and append data to an existing text file.

Key Notes

  • There are different modes for opening a file, r (read), w (write) and a (append).
  • When you open a file in write mode, it creates a new file. If the file already exists then the file will be overwritten.
  • When you open a file and write to a file in append mode, it will add to the existing contents of the file.
  • It is good practice to close the file once written to. Some IDEs will not write to a file until it is closed.

Vocabulary To Learn

  • write: a file handling mode that allows a program to write data to a file, where, if the file does not exist, a new file is created, and if the file already exists, the content is overwritten
  • append(): a file handling mode that allows a program to write extra data at the end of a file without erasing the existing contents of the file
  • overwrite: to replace information in (a computer file) with new information

Common Mistakes To Avoid

  • You have to create a new write() line for each line you want to add to a file.

3 Quick Questions (With Answers)

1. Describe the system or process from this lesson in clear steps.

There are different modes for opening a file, r (read), w (write) and a (append). When you open a file in write mode, it creates a new file. If the file already exists then the file will be overwritten.

2. Define this computing term and give one practical example. 'write'

a file handling mode that allows a program to write data to a file, where, if the file does not exist, a new file is created, and if the file already exists, the content is overwritten. Add one real device or system example to prove understanding.

3. Correct this common computing misconception.

Mistake: You have to create a new write() line for each line you want to add to a file. Correction: You can write mutiple lines in one write() statement. But if you want the text to appear on separate lines, you must use the new line character.

More Lessons In This Unit

Browse all guides in the Year 11 Computing guide library.