Computer Science GCES OCR
-
Cpu Architecture Performance And Embedded Systems Ocr5 主题
-
Primary And Secondary Storage Ocr6 主题
-
Data Storage And Compression Ocr12 主题
-
Units Of Data Storage Ocr
-
Processing Binary Data Ocr
-
Data Capacity And Calculating Capacity Requirements Ocr
-
Converting Between Denary And Binary Ocr
-
Binary Addition Ocr
-
Converting Between Denary And Hexadecimal Ocr
-
Converting Between Binary And Hexadecimal Ocr
-
Binary Shifts Ocr
-
Representing Characters Ocr
-
Representing Images Ocr
-
Representing Sound Ocr
-
Compression Ocr
-
Units Of Data Storage Ocr
-
Networks And Topologies Ocr6 主题
-
Wired And Wireless Networks Protocols And Layers Ocr6 主题
-
Identifying And Preventing Threats To Computer Systems And Networks Ocr2 主题
-
Operating Systems And Utility Software Ocr2 主题
-
Ethical Legal Cultural And Environmental Impact Ocr2 主题
-
Computational Thinking Searching And Sorting Algorithms Ocr3 主题
-
Designing Creating And Refining Algorithms Ocr5 主题
-
Programming Fundamentals And Data Types Ocr5 主题
-
Additional Programming Techniques Ocr7 主题
-
Defensive Design And Testing Ocr6 主题
-
Boolean Logic Diagrams Ocr2 主题
-
Programming Languages And Integrated Development Environments Ides Ocr3 主题
-
The Exam Papers Ocr2 主题
-
Structuring Your Responses Ocr3 主题
File Handling Ocr
Exam code:J277
File Handling
What is file handling?
-
File handling is the use of programming techniques to work with information stored in text files
-
Examples of file handing techniques are:
-
opening text files
-
reading text files
-
writing text files
-
closing text files
-
|
Concept |
OCR exam reference |
Python |
|---|---|---|
|
Open |
|
|
|
Close |
|
|
|
Read line |
|
|
|
Write line |
|
|
|
End of file |
|
|
|
Create a new file |
|
|
|
Append a file |
|
|
Python example (reading data)
|
Employees |
Text file |
|---|---|
|
|
Greg |
Python example (writing new data)
|
Employees |
|
|
|
Greg |
Examiner Tips and Tricks
When opening files it is really important to make sure you use the correct letter in the open command
-
“r” is for reading from a file only
-
“w” is for writing to a new file, if the file does not exist it will be created. If a file with the same name exists the contents will be overwritten
-
“a” is for writing to the end of an existing file only
Always make a backup of text files you are working with, one mistake and you can lose the contents!
Worked Example
Use pseudocode to write an algorithm that does the following :
-
Inputs the title and year of a book from the user.
-
Permanently stores the book title and year to the existing text file books.txt [4]
How to answer this question
-
Write two input statements (title and year of book)
-
Open the file
-
Write inputs to file
-
Close the file
Example answer
title = input("Enter title")
year = input("Enter year")
file = open("books.txt")
file.writeline(title)
file.writeline(year)
file.close()
Guidance
-
title = input("Enter title")1 mark for bothyear = input("Enter year") -
file = open("books.txt")1 mark
-
file.writeline(title)1 mark for both
file.writeline(year)
-
file.close()1 mark
Responses