Computer ScienceExam code: 0984

File Handling

Programming

CIE pseudocode uses a small set of dedicated keywords for file operations.

OperationPseudocodePython equivalent
Open for a given modeOPENFILE "filename.txt" FOR <mode>file = open("filename.txt", "r") (or "w")
Read one lineREADFILE "filename.txt", LineVariableline = file.readline()
Write one lineWRITEFILE "filename.txt", TextToWritefile.write("text\n")
Close the fileCLOSEFILE "filename.txt"file.close()

The CIE file commands always include the filename so the operation knows which file it is acting on.

Quick check

3 short questions on this note. See what has stuck, and where to look if something hasn't.

About 1 minute

Build on this topic