Python Classes in Modules and Packages

The organization of Python classes into modules and / or packages is highly dependent on personal preference, usability, readability, and the application itself. There is always the case when each class is stored in a separate file. It can happen that sometimes keeping related classes in one file can make it quite large, and sometimes &just fine. So it all depends on the scripts, the usability and ease of working with the classes. 

Module &it is a file containing Python definitions and statements. File name &this is the name of the module with the .py suffix appended. Inside the module, the module name (as a string) is available as the value of the global variable __name__.

The module can contain executable statements as well as function definitions. These statements are for initializing the module. They are only executed the first time a module name is encountered in an import statement. They are also run if the file is executed as a script. Modules can import other modules.

A set of related modules that provide one or more functions is called package. So we can summarize and say that classes are organized into modules and packages in Python.

Get Solution for free from DataCamp guru