0

This is how i made my CSV file:

with open('Mail_Txt.csv', 'w', encoding='utf-8', newline='') as csvfile:
    fieldnames= ['Sender', 'Subject', 'Snippet']
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames , delimiter=',')
    for val in final_list:
        writer.writerow(val)

I try many methods to print the Sender column of the CSV file. But I fail all the time. so, help me to print the first or 'Sender' column of the CSV file

GoAmeer030
  • 118
  • 12

2 Answers2

1

Reading from a csv file is symetric from writing. The main difference is that as you have skipped the header line, you will use a simple reader and get sequences instead of mappings:

with open('Mail_Txt.csv', 'r', encoding='utf-8', newline='') as csvfile:
    reader= csv.reader(csvfile, delimiter=',')
    for val in reader:
        print(val[0])
Serge Ballesta
  • 136,215
  • 10
  • 111
  • 230
1

you can use use the DictReader function to accomplish this.

with open('yourFile') as f:
    data = [row["Sender"] for row in DictReader(f)]
    print(data)
      
Jacques
  • 75
  • 1
  • 6