Created
December 3, 2015 23:32
-
-
Save alistair-broomhead/d841fb05a00fd1313323 to your computer and use it in GitHub Desktop.
An example of using a generator expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
def email_next(seq): | |
for address in seq: | |
try: | |
email(address) | |
except Exception as ex: | |
print('Could not email {}, moving onto the next: {}' | |
.format(address, ex)) | |
else: | |
return | |
print ('Ran out of contactable applicants, there will be unfilled places.') | |
content = csv.DictReader(open('some_long_file.csv')) | |
applicants = ('"{first_name} {last_name} <{email}>"'.format(**row) for row in content) | |
for index in xrange(num_places): | |
email_next(applicants) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment