Skip to content

Instantly share code, notes, and snippets.

@alistair-broomhead
Created December 3, 2015 23:32
Show Gist options
  • Save alistair-broomhead/d841fb05a00fd1313323 to your computer and use it in GitHub Desktop.
Save alistair-broomhead/d841fb05a00fd1313323 to your computer and use it in GitHub Desktop.
An example of using a generator expression
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