Modular Programming Architecture in Python
Modular Programming Architecture in Python
main.py (Main Application)
↓ imports ↓
calc_module.py
Math Functions
Math Functions
student_db.py
Database Logic
Database Logic
report_gen.py
PDF / Output
PDF / Output
Explanation
- Split related operations into modules with clear names.
- The main program imports those modules and calls the functions it needs.
Core Standard Modules in Unit 3
Core Standard Modules in Unit 3
1. math Module
Mathematical functions (square root, trigonometry, logarithms, constants like
pi and e).2. datetime Module
Working with dates, times, timestamps, formatting (
strftime), and date arithmetic.3. os Module
Interacting with the Operating System (folders, file paths, environment variables).
Explanation
- The os module provides operating-system services and datetime works with dates and times.
- The math module supplies numerical functions and constants.
Organizing a Python Project into a Package (college_pkg)
Organizing a Python Project into a Package (college_pkg)
📁 my_project/
├── 📄 main.py # Entry point of the application
└── 📦 college_pkg/ # Python Package
├── 📄 __init__.py # Marks this folder as a Python Package
├── 📄 students.py # Module 1: Student admission & records
├── 📄 faculty.py # Module 2: Teacher details
└── 📄 exams.py # Module 3: Marks & result calculation
├── 📄 main.py # Entry point of the application
└── 📦 college_pkg/ # Python Package
├── 📄 __init__.py # Marks this folder as a Python Package
├── 📄 students.py # Module 1: Student admission & records
├── 📄 faculty.py # Module 2: Teacher details
└── 📄 exams.py # Module 3: Marks & result calculation
Explanation
- A package gives related modules a common import path.
- The directory structure and package initialisation determine how code is organised and found.
3-Step Lifecycle of File Handling in Python
3-Step Lifecycle of File Handling in Python
1. Open File
f = open("data.txt", "r")→
2. Read / Write Data
f.read() or f.write()→
3. Close File
f.close()Explanation
- Open the file in a mode suited to the intended operation and use the returned handle.
- A with block closes it after the read or write, even if an exception interrupts the work.