Python for GCSE

8: File input and output

Revision tools
You can print this page for a quick reference guide or you can use the tools below to create printable test sheets
8.1: understand the difference between a text file (.txt) and a Python file (.py)
File input and output
KeywordDefinition
.csv filea file which contains a table of data values separated by commas and newlines
.py filea file which contains a python program which can be run
.txt filea file which can contain any text data but which can't be run as a program
8.2: be able to write code that can read from a text file
File input and output
KeywordDefinition
closerelease resources associated with a file when it doesn't need to be used any more
filenamethe name and location of a file to be read from or written to
openaccess a file so that it can be read from
readload data from a file
8.3: be able to write code that can write to a text file
File input and output
KeywordDefinition
appendmethod used to write to a file where new data is added onto the end of an existing file
createmethod used to write to a file where a new file is created if if it doesn't already exist
modethe method used to open a file for writing (e.g. append, read only or create)
writeoutput data to a file
8.4: understand how to write data structures (one-dimensional and two-dimensional arrays) to file by iteration
File input and output
KeywordDefinition
csvtype of file which is useful for storing data from a 2D array because each line stores multiple values separated by commas
indexa number which identifies the position of data within a list, array or string
iterationusing for or while loops to repeat a set of instructions or go through each value in a data structure such as a list
one dimensional arraya data structure like a list where one index is used to identify the position of a particular stored value
two dimensional arraya data structure like a list of lists where two indices are used to identify the position of a particular stored value