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 Object-Oriented Python Instant Objects Method Arguments

**kwargs seems to be too lax

I am struggling with the idea or reason behind the **kwargs parameter in this class with the setattr loop.

In the Teacher's notes he uses animal as his class and makes a wolf so that makes a little more sense. It just feels REALLY broad for what my object is.

For example I can create two Thief objects: dave = Thief('Dave', True, capacity = 50) george = Thief('George', False, weapon = 'sword')

so now dave.weapon and george.capacity cause errors.

Why wouldn't I want to be more specific with my class attributes?

Is this just lazy programming? (meh, I don't know what a thief needs I'll just declare it later)

2 Answers

Fran ADP
Fran ADP
6,304 Points

create classes to require specific parameters to create an instance.

Steven Parker
Steven Parker
231,268 Points

You can certainly create your own classes to require specific parameters to create an instance. You don't need to make use of "kwargs" at all if it doesn't fit your needs.

I think the examples are just intended to illustrate the features of the language.