Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Python dictionaries/objects help

I'm trying to use mandrill Python to send bulk emails. In the Api I have to create objects in the following format by copying emails from a database. Could someone please help me on how to create these kind of objects with multiple email addresses? Thanks in advance:

 'to': [{'email': 'recipient.email@example.com',
         'name': 'Recipient Name',
         'type': 'to'}],
Chris Freeman
Chris Freeman
Treehouse Moderator 68,468 Points

This python code snippet looks like a single dict key definition. What larger object would this be part of?

Do you have a description of the data coming from the database, or the model class definition the database table is based on?

3 Answers

Could you explain a bit more?

Do you want only multiple emails for one recipient? Or something else?

Josh - I'm trying to send customized emails through Mandrill. I have figured out how to customize the email content in mandrill but havent been able to figure out how to create a dictionary of all email ids by fetching it from my database

From what I can tell from a cursory look at the Mandrill API docs, this info is passed through in JSON format and not as Python objects. The syntax looks somewhat similar.
https://mandrillapp.com/api/docs/
JSON examples : http://www.json.org/example.html

Hi Everyone, Thanks for your response. Im using Python Mandrill API to send mass emails. The link to the code is here https://mandrillapp.com/api/docs/messages.python.html#method=send-template

What I have figured is that to send multiple emails I have to fetch email addresses and names from my database and create a python dictionary in the code like below:

'to': [{'email': 'recipient1@example.com', 'name': 'Recipient1', 'type': 'to'}, {'email': 'recipient2@example.com', 'name': 'Recipient2', 'type': 'to'}, {'email': 'recipient3@example.com', 'name': 'Recipient3', 'type': 'to'}]

This dictionary contains only 3 emails but I will have to create something similar for the 10000 email address I have in my MYSQL databases.

What I wanted to know was what's an easy way to create a similar dictionary with 10000 emails from the MYSQL database?

Thanks in advance