Edexcel 1CP2 6.4.2: Reading and writing CSV files
The free BugBot lesson that teach this point, a robot to try it on, and the past-paper questions that test it.
What it covers
Everything a program stores in variables disappears when it stops. To keep data between runs, a program writes it to a file, and reads it back next time. Robots keep logs this way: every run, what happened, and how it went. In this lesson BugBot reads its run log from a file and adds to it.
- The files on this page
- Reading a file
- Line by line
- Writing a file
- The whole file as a list of records
- When files go wrong
Or do it in the simulator, with tasks that mark themselves
Lessons that teach it
- F7.1 Reading and writing files Files and databases
Open, read, write, append and close: a run log in a CSV file.
Try it on a robot
The task from F7.1 Reading and writing files, running here. Change the program and press Run.
Past paper questions on this
Real exam questions that test this, each worked through with a program you can run.
- OCR J277 June 2025 Paper 2, Question 4: Complete an algorithm that reads numbers from a text file, and casting 6 marks
- OCR J277 June 2023 Paper 2, Question 6(e): A procedure with two parameters that writes to a text file 6 marks
- Edexcel 1CP2 June 2025 Paper 2, Question 4: Write a multiplication square to a file with commas 11 marks
- Edexcel 1CP2 June 2024 Paper 2, Question 6: Read a CSV file of cows into records with a key, and display the table 15 marks
- Edexcel 1CP2 June 2022 Paper 2, Question 5: Write a list to a CSV file, seven values to a line 15 marks
The specification is Edexcel's own document; this page says which of our lessons teach point 6.4.2 and is not endorsed by the board.