What Does Module Mean?

Archita Joshi
2 min readMay 13, 2021

A module is a software component or part of a program that contains one or more routines. One or more independently developed modules make up a program. An enterprise-level software application may contain several different modules, and each module serves unique and separate business operations.

Modules make a programmer’s job easy by allowing the programmer to focus on only one area of the functionality of the software application. Modules are typically incorporated into the program (software) through interfaces.

The introduction of modularity allowed programmers to reuse prewritten code with new applications. Modules were created and bundled with compilers, in which each module performed a business or routine operation within the program.

What is a module in Python?

Simply, a module is a file consisting of Python code. A module can define functions, classes and variables. A module can also include runnable code.

The Python code for a module named mymodule normally resides in a file named mymodule.py. Here’s an example of a simple module, hello.py

def hello_func( par ):
print "Hello : ", par
return

The import Statement

You can use any Python source file as a module by executing an import statement in some other Python source file. The import has the following syntax −

import module1[, module2[,... moduleN]

When the interpreter encounters an import statement, it imports the module if the module is present in the search path. A search path is a list of directories that the interpreter searches before importing a module. For example, to import the module hello.py, you need to put the following command at the top of the script −

# Import module support
import hello
# Now you can call defined function that module as follows
support.print_func("John")

When the above code is executed, it produces the following result −

Hello : John

A module is loaded only once, regardless of the number of times it is imported. This prevents the module execution from happening over and over again if multiple imports occur.

--

--