Assignment, Variables, Constants & Sequences
Inputs, Outputs & Type Conversion
Condition controlled Loops
Count Controlled loops
Nested Selection and Iteration
Subroutines 1 - Procedures
Subroutines 2 - Functions
Operators and Operations
Structured Programming
Validation and verification
File operations
To open a file in python we use the open() function. We put the name of the file inside of speach marks "demo.txt" The "r" means open the file for reading only. We then assign the file to the myFile variable, which is an object. We then use the read() method for reading the contents of the file:
To read all of the file we can loop through each line like this:
We open the file "demo.txt" and append, "a", the text to the file using write:
We open the file "demo.txt" and overwrite the content "w" :
1. Before starting the coding task you must click on the Python for Beginners link under the notes and read through.
2. Click on the button below and complete as many exercises as you can
I can copy code to read from or write to a text file.
I can create my own text file and read and write to it.
I can use a text file in my own program to read from and write data to.
AQA Computer Science Tutor