django - Python- Iterating through columns in csv file -
i working on project have iterate through csv file. want see if 4 column(3rd slot) of each row have email address in dictionary has person's name , email address. if want send them attachment. i'm not familiar python, want see if i'm heading in right direction
here sample code:
import csv
with open("file.csv") csv_file: row in csv.reader(csv_file, delimiter=','): if row[3] in data_dict: email = emailmessage('subject', 'body', [address@something.com]) email.attach_file('/folder/name.csv') email.send()
when involved attachments i'd advise yagmail package (full disclose: i'm developer)
obtain running:
pip install yagmail # python 2 pip3 install yagmail # python3
then:
import yagmail yag = yagmail.smtp('myemail', 'mypassword') open("file.csv") csv_file: row in csv.reader(csv_file, delimiter=','): row = row.split(',') if row[3] in data_dict: contents = ['see file attached', '/folder/name.csv'] yag.send(row[3] + '@email.com', 'subject', contents)
note can opened file attached (when passed contents
argument), if /folder/name.csv
valid path in list, sent attachment.
Comments
Post a Comment