File handling

Reading and writing a csv or txt file can be achieved using the same code, just change the file extension.

Note: Anything read from a file is a string. If the value represents another data type then it must be cast to that data type.

Example data

The data used in the examples can be represented in a table:

Name Age Height
Alan 24 1.78
Beth 23 1.63
Carl 22 1.89
Dina 21 1.59

It can also be represented as a text file, e.g. people.csv or people.txt.

Alan,24,1.78
Beth,23,1.63
Carl,22,1.89
Dina,21,1.59