Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
This Reasons for using TXT, CSV and XML data sources worksheet is part of the VCE Software Development - U3O1 - Programming journey. Print it as a booklet?
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1scores.csv Ava,88,74 Liam,65,70 | ACSV is flat, with rows and columns only, so it cannot show nested levels. XML is better because its tags can nest inside each other. | |
| 2<student><name>Ava</name></student> | BTXT has no field structure, so a table of records is hard to read back. CSV is a better choice because commas separate the fields. | |
| 3TXT is the simplest choice for plain lines of text, such as a log or notes, with no fields or structure needed. | Clog.txt Started game Score saved | |
| 4Data kept in a file persists between runs, so a program can save its data and load it again next time. | DA CSV file suits a table of records: one record per line, with fields separated by commas, easy to open in a spreadsheet. | |
| 5Use a TXT file to store a table of 500 students with 6 fields each, because TXT is always best | Ewith open('scores.csv', 'w') as f: f.write('Ava,88') | |
| 6Use CSV to store nested data, such as a school with classes that each contain students | FAn XML file suits nested, self-describing data that is shared between different systems, because the tags label every value. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
TXT, CSV, XML — Choose a data source by structure: TXT for simple lines, CSV for tables of records, XML for nested self-describing data shared between systems. All three store data between runs.f = open("notes.txt", "r")
line = f.readline()row = "Ava,7,Red"
fields = row.split(",")<student><name>Ava</name></student>tree = ET.parse("shop.xml")
root = tree.getroot()f = open("log.txt", "a")
f.write("Saved\n")