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.

Build on this topic