Session 04 Python 2025-2026 1º
Modularization and Advanced File Handling
Structuring multi-file projects, code reuse, and robust persistent data management.
Key Concepts
- Modularization using
import - Splitting programs into multiple files
- Variable scope
if __name__ == "__main__"- Advanced file handling
- Project structure
- Clean code organization
Mandatory Part
1. Split the project into modules
Take the student management system from the previous session and divide it into:
main.pystudent_management.py
student_management.py must contain:
Functions for:
- adding a student
- searching for a student
- calculating statistics
- saving data
- loading data
main.py must contain:
- The menu
- The main loop
- Calls to functions from the module
Clearly explain:
if __name__ == "__main__":
main()
Objective: understand how real programs are structured.
2. Add delete and edit features
Extend the system to allow:
- Deleting a student by name
- Editing a student’s grade
Requirements:
- Confirmation before deletion
- Input validation
- Automatically update persistent storage
Extended Part · Introduction to Basic Algorithms
3. Manual sorting
Create a function that sorts students by grade without using sorted().
They may implement:
- A simplified bubble sort
- Manual element swapping
Objective: understand how sorting works internally.
4. Optimized manual search
Implement name search in two versions:
- Version 1: full linear scan
- Version 2: stop when match is found
Briefly explain time complexity in an intuitive way.
Extra Challenge
5. Export to CSV
Create a function that generates a students.csv file in this format:
name,age,grade
Anna,19,8
Luis,20,6
Without external libraries.