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

Python Object Orientation

Hi,

when writing object oriented python, is it best to use a new file for every object and then put similar classes into these files? Or is there another approach?

Also, can object also be "action" for example when creating a user database, would create_user be put in a separate file such as create.py, which then has class create_user, class modify_user, etc.?

Thanks!

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Shezan;

I think you have the right idea there, yes. To use your example one would typically create a user.py which would have the User class definition in it. Inside that class would be necessary methods that would impact a "User", like create, update, delete, etc.

Happy coding,
Ken

Thanks Ken!