Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python SQLAlchemy Basics Working with SQLAlchemy Creating Our Book Database

Andy McDonald
Andy McDonald
5,016 Points

How to turn a query object into a dictionary?

I'm trying to use kwargs in the search function for this project. The difficulty is not necessarily that it is a query object but that im trying to create a single entry with multiple key/value pairs. At one point I was creating a dict that had an entire class object as a value to one key and since then I've tried a lot of different things, iterating through loops within loops, appending empty lists and trying to zip them together, indexing within a loop and now I've tumbled down the rabbit hole so deeply I cannot remember why I needed to use kwargs in the first place. But I'm pretty sure that knowing how to do this will at least be helpful in the future if not immediately after I remember why I wanted to use kwargs in the first place.

Chris Freeman
Chris Freeman
Treehouse Moderator 67,763 Points

Lots of variations on a theme. One of these may be the form you’re looking for in this StackOverflow answer.

Post back which one you choose. Good luck!