
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
How to organize Python classes in modules and/or packages
Organizing Python classes into modules and/or packages depends a lot on personal preferences, convenience, readability and the application itself. There is always that case that each class is kept in a separate file. It may be that sometimes keeping related classes in one file may make it quite large while sometimes it may be just fine. So it all depends on the scenarios, convenience and ease of working with classes.
A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name (as a string) is available as the value of the global variable __name__.
A module can contain executable statements as well as function definitions. These statements are intended to initialize the module. They are executed only the first time the 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 collection of related modules providing one or more functionalities is called a package. So we can summarize and say that classes are organized into modules and packages in Python.
- Related Articles
- What are the best practices to organize Python modules?
- How will you compare modules, classes and namespaces in Python?
- How many packages and classes are there in Java Standard Edition 8?
- How to create python namespace packages in Python 3?
- Packages in Python
- How to install Python modules in Cygwin?
- How to install python modules and their dependencies easily?
- How to install and import Python modules at runtime?
- How to use remote python modules?
- How to define classes in Python?
- How to develop programs with Python Namespaced Packages?
- How to check version of python modules?
- How to deploy python modules on Heroku?
- Introduction to Classes and Inheritance in Python
- How to use enums in Python classes?
