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

2 Answers2

0

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
  • 143,923
  • 11
  • 122
  • 252
0

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
  • 135
  • 1
  • 1
  • 6