134k views
4 votes
4.17 LAB: Data File A comma separated value (.csv) file has been included to be used for this program. Each line contains two values, a name and a number separated by a comma (except the first line, which contains the titles for the value types). The name is that of a writer and the number refers to the number of works the writer has written. Ex. Jane Austen,6. Each line is an entry and each entry number can be updated by identifying the associated name. Once complete, the following program opens data file allWorks.csv and asks if the user wants to update entries or add new entries. All entries are stored in an array while being read in and updated. The program then writes the array to the file, overwriting the original contents. The following TODO sections must be completed. Open allWorks.csv for reading/input. Locate an entry to be updated by name (use the Java String indexOf() method) Add a new entry if the name isn't found in the file (give the entry a new number) Open file allWorks.csv for output Write contents of the array to allWorks.csv (original file is overwritten)

1 Answer

3 votes

Answer:

import csv

def Csvreader(filename):

with open("filename", "r") as file:

content = file.csv_reader()

list_content = list(content)

file.close

return list_content

Step-by-step explanation:

This is a python description of the function that reads the csv file and converts it to a list, from the list, each item can accessed with its index and updated directly. Use this to draw the same conclusion for a java program.

User Kian Cross
by
4.9k points