How many Python classes should I put in one file?


Python code is organized in files called "modules" and groups of related modules called “packages".

A module is a distinct unit that may have one or more closely-related classes. Modules need to be imported before they are read, used, maintained and extended if needed. So a module is a unit or reuse.

The rule is this: a module is the unit of reuse. Everything in Python libraries and other Python applications is either a module or a package of modules.

There is no limit on how many classes one can put in a file or a module. It all depends on how big or small the project is and how long or short the classes are. It is a matter of convenience and efficient and productive organization.

Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements