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 trialfahad lashari
7,693 PointsAny disadvantages or advantages of using multiple classes under one file name? For example:
class Monster:
hit_points = 1
color = 'yellow'
weapon = 'sword'
class Hero:
hit_points = 0.5
color = 'white'
weapon = 'axe'
1 Answer
Chris Howell
Python Web Development Techdegree Graduate 49,702 PointsI would say it is dependent on how complex your code/application is becoming.
Advantages
Code is in one place, easy to import
Disadvantage
No separation of concerns Less organized classes
In frameworks like Django that use models. You do see multiple classes listed within one model.py* file but they are still related concerns. So if the **models.py for particular App called lets say "Movies"
You might have multiple classes structure like so:
class Actor:
pass
class Genre:
pass
class Movie:
pass
But inside this "module" called Movies these are all classes that relate to a Movie. So its perfectly normal to see this.