How many Python classes should I put in one file?

PythonServer Side ProgrammingProgramming

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.

Published on 22-Jan-2018 12:41:05