Thursday, 30 November 2023

Python Modules

In any language, if the program is getting bigger, you may have to split it into more files for easier maintenance. You may also want to use a function defined in a file without copying the entire logic in each file. To support this, Python has a way to put the definitions in a file and use them in a script wherever required to use those functions you have defined in that file. Such file is called as a module in Python. It always ends with .py extension.

You can call a function / definition defined in a module file using import statement in a script. For instance, I am defining a calc module with some definitions.

File: calc.py