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 trialChris Grazioli
31,225 PointsWhy the difference in setattr() between the Method Arguments video versus the Teachers notes listed?
What is the difference and why? between the setattr() explanation in the video and the teachers notes.
Video: def init(self, **kwargs): for key, value in kwargs.items(): setattr(self,key,value)
Teachers Notes: def init(self, **kwargs): for attribute, value in self.kwargs.items(): setattr(self,attribute,value)
I understand "attribute" is being used in place of "key" and according to my understanding could have been called just about anything else as well. BUT why the self.kwargs.items() only in the teachers notes and not in the video explanation?
2 Answers
Chris Grazioli
31,225 PointsForgot to do the MARKUP in the original question, this should be a bit easier to read hopefully
Video:
def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self,key,value)
Teachers Notes:
def __init__(self, **kwargs):
for attribute, value in self.kwargs.items():
setattr(self,attribute,value)
Kenneth Love
Treehouse Guest TeacherThe self.kwargs
was a typo. Thanks for catching it!