2. TEXT FILES
• A text file is a sequential file which stores text.
• Reading from a file sequentially means starting at the beginning, and
reading all of the information right up to the end of the file.
• Normally this information would be stored in a variable.
3. READ TEXT FILE
Pseudocode:
OPEN “about_python.txt”
RECEIVE text FROM “about_python.txt”
SEND text TO DISPLAY
CLOSE “about_python.txt”
6. WRITE TEXT FILE
Pseudocode:
CREATE “computing_companies.txt”
OPEN “computing_companies.txt”
SEND “Microsoft were formed in 1975.” TO “computing_companies.txt”
SEND “Apple were formed in 1976.” TO “computing_companies.txt”
CLOSE “computing_companies.txt”
9. CSV FILES
• A CSV file is a sequential file.
• CSV stands for Comma Separated Values.
• Data is read (or written) starting at the beginning of the file.
• Files are structured as columns and rows.
10. READ CSV FILE
Pseudocode:
OPEN “olympics.csv”
RECEIVE reader FROM “olympics.csv”
FOR EACH row IN reader
SEND “ Games ” & row[0] & “ held in ” & row[1] & “, ” & row[2]
TO DISPLAY
END FOR
CLOSE “olympics.csv”
13. WRITE CSV FILE
Pseudocode:
INITIALISE games array
INITIALISE cities array
INITIALISE years array
OPEN “olympics.csv”
REPEAT WITH counter 5 TIMES
SEND games[counter] & cities[counter] & years[counter]
TO “olympics.csv”
END FOR
CLOSE “olympics.csv”