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 Using Databases in Python Our Diary App Doing Data Entry

Robust Tran
Robust Tran
2,802 Points

The purpose of put a class inside another class?

In Python why we put a class inside another class like Meta class inside Diary class? I've tried to figure it out but still don't get it!

Kenneth Love. Can you help me out, thanks :)

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

It's just an organizational thing. You can have classes inside of classes and functions inside of functions, etc. This way you have a class that belongs to a parent class and you can instantiate that class when you create an instance of the parent class, then the attributes for that Meta class belong to it, and are encapsulate in it, instead of cluttering up your parent class.

You can also provide defaults in that Meta class based on the class that your parent class inherits from.

So, short answer, it's just another way of providing some more detail and organization to your classes.

Robust Tran
Robust Tran
2,802 Points

Thanks for you quick response. As you explained I think that means whenever I execute "db.connect() and db.create_tables([Diary])" line, the peewee will check for the database (Sqlite) following by Diary.Meta to get the right one right?