CSci 284 - Homework 0
Due: Tuesday, Jan 27,
2026
This assignment is to be done individually. It is worth 16 points. For full credit:
- submit responses by class time on the due date
- turn a paper document in at the beginning of class on the due date, OR post an electronic copy to BrightSpace
- don't post photos of written work on paper to BrightSpace, just
turn in the paper
Written Problems.
For these problems, you'll need to refer to the code examples from Introduction to CSV we used in Exercise 1.
- (4 points) The code sample in the Writing to a CSV section
calls the
openfunction to create and open the example.csv file. This function takes 4 parameters. Research this function and write out the purpose and meaning of each parameter in this call. So for example what is the purpose of theencodingparameter and the meaning of passing'utf-8'for it?
- (2 points) What would happen if the programmer left off
'Miami, Florida'from the third list (the one that begins with the name'Ted') so that there were only 2 items in the list? Try it and see. - (2 points) What would happen if the same item was left off the list,
but the comma was still there, so that it reads:
['Ted', , 'driver']?Try it and see. - (2 points) What happens if the programmer forgets the last line
csvfile.close()?
We'll spend more time reading CSV (and TSV) files than writing them.
Refer to the code sample in the Reading from a CSV section to
answer these question.
Provide screenshots of both the commands used and the result.
- (2 points) In the
opencall for the writing example, a'w'is passed so the file is opened for writing. In this example, there is no'r'passed to the open call. Why is that?
- (4 points) As it turns out, the
csvmodule can be used to read/write TSV files as well. Find an example of how to do this, then show how to rewrite just lines 5 and 8 so that if we had a TSV file called presidents.tsv instead, we could read it.