Member-only story
Modules and Packages in Python: Fundamentals for Data Scientists
Understand the basics with a concrete example!
5 min readJun 28, 2020
When your Python code grows in size, most probably it becomes unorganised over time. Keeping your code in the same file as it grows makes your code difficult to maintain. At this point, Python modules and packages help you to organize and group your content by using files and folders.
- Modules are files with “.py” extension containing Python code. They help to organise related functions, classes or any code block in the same file.
- It is considered as a best practice to split the large Python code blocks into modules containing up to 300–400 lines of code.
- Packages group similar modules in a separate directory. They are folders containing related modules and an __init__.py file which is used for optional package-level initialisation.
- Depending on your Python application, you can consider to group your modules in sub-packages such as doc, core, utils, data, examples, test.
Let’s write an example Python3 code to further understand modules and packages:
""" cvs_get_module.py
This module displays the summary of the tabular data contained in a CSV file
"""import pandas as pd