I'm tasked with getting emails from a .csv file and using them to submit a form. I am using the csv and mechanize Python libraries to achieve this. This is my code:
import re
import mechanize
import csv
def auto_email(email):
br = mechanize.Browser()
br.open("URL")
br.select_form(name="vote_session")
br['email_add'] = '%s' % (email) #email address
br.submit()
def csv_emails():
ifile = open('emails.csv', "rb")
reader = csv.reader(ifile)
rownum = 1
for row in reader:
auto_email(row[0])
print "%d - %s processed" %(rownum, row[0])
rownum += 1
print 'List processed. You are done.'
ifile.close()
print csv_emails()
The code works. But I am very much a beginner in Python.
I was wondering whether I have any inefficiencies that you can help me get rid of and optimize the script?
Thanks.
(I used this site heavily in getting to the point of writing the above code so I've had plenty of help from you users of stackoverflow already, thanks).