Creating helper functions
Let’s add reusable helper functions to yoursales-analysis project. In the sales-analysis/ folder, create a new file called helpers.py:
Using your functions in the main script
Updateanalyzer.py in the same folder to import and use your new helpers:
How imports work
When you writefrom helpers import calculate_total:
- Python looks for
helpers.pyin the same folder asanalyzer.py - It runs
helpers.pyand makes the functions available in your current scope - You can call
calculate_total()directly, as if you’d defined it in the same file
This simple import works because both files are in the same directory. If your helper was in a subfolder, you’d use the dotted import syntax covered in the Python paths page.
What you’ve accomplished
Take a moment to appreciate how far you’ve come. Starting from a single Python file, you now have:- An organized project with separate folders for code, data, and output
- A clear understanding of how Python locates files and modules
- A script that reads real CSV data and produces formatted results
- Reusable helper functions in a dedicated module
What’s next?
Now that you can structure and organize local Python projects, let’s build a complete end-to-end weather data analysis project using a real API.Weather data analysis project
Build a weather analysis project with APIs and visualization