-1

I uploaded a csv file created by excel, and am trying to figure out how to update a new row into the dictionary it created?

I've tried DictionaryName.update, but don't know what the dictionary has been named.

import csv

with open('comics.csv', 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)

for line in csv_reader:
    print(line)

Very new to coding this is for my 1010 class, the csv file contains names of comic books, authors, artists, issue number, and variant cover.

gstarr10
  • 1
  • 3
  • You seem to have some misunderstanding of the terminology here. A csv file contains rows and columns. When you read one in python, you can use an instance of the `csv.DictReader` class to do it for you, and this object will yield a `dict` instance for each row in your csv file. This dict will contain keys specified by the first row (header) in your CSV file, and the values for those keys will be the values in the corresponding columns of the row currently being read. Now that you know this, "update dictionary created by CSV file" makes no sense, does it? What is it you actually want to do? – Pranav Hosangadi Jun 02 '22 at 05:27
  • If you simply wanted to _add a row_ to your csv file, then you should try [looking for an answer to that question](https://stackoverflow.com/a/37654233/843953). If you want to _modify a row_, then [ask _that_ question](https://stackoverflow.com/a/46130947/843953). If it's something else, please read [ask] and provide enough information to clearly define your problem. – Pranav Hosangadi Jun 02 '22 at 05:29

0 Answers0