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 trialJay Norris
14,824 PointsConversions: Instance into dictionary
I know Kenneth stated that converting an instance to a dictionary was outside the scope of this course, but I would be really curious to see some examples.
1 Answer
Kenneth Love
Treehouse Guest TeacherIt's honestly really simple. instance.__dict__
.
But you'll eventually want to control that conversion (I don't suggest you actually do this, though).
In that case you'll need to override the __dict__
method, make it a @property
, and return whatever dictionary you want to return.
Again, though, don't do this