Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with csv
#5
(Mar-18-2021, 10:11 AM)Larz60+ Wrote: you can place the header in a list,
then use csv reader (not DictReader)
an example of using zip would be:
    header = ['col1', 'col2', 'col3', ...] # replace with actual column names
    with open("boardgames.csv", 'r') as csvfile:
        reader = csv.reader(csvfile)
        for xrow in reader:
            row = dict(zip(header, xrow))
            ...
the output looks like a json file would be a better choice than your method.

In my opinion a json file would be our best option here, however my exercise needs a csvs file. I actually fixed the problem thank you for your help. I just added a function that initializes the csv and writes the headers, when the program begins. Thanks!
Reply


Messages In This Thread
Problem with csv - by giorgosmarga - Mar-17-2021, 09:52 PM
RE: Problem with csv - by Larz60+ - Mar-18-2021, 03:02 AM
RE: Problem with csv - by giorgosmarga - Mar-18-2021, 09:34 AM
RE: Problem with csv - by Larz60+ - Mar-18-2021, 10:11 AM
RE: Problem with csv - by giorgosmarga - Mar-18-2021, 11:07 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020