4 - Modules, File I/O, and Error Handling — Topics & Learning Outcomes

📋 Module Topics🎯 Student Learning Outcomes

Module Topics

Introduction to Python Modules

Explains what modules are, why they are used, and how Python locates and loads them at runtime.

Writing and Using Custom Modules

Covers how to design, write, and import your own Python modules to share reusable engineering functions across projects.

Using Standard Library Modules

Introduces key modules included with Python that are immediately useful for engineering scripting tasks without additional installation.

File I/O with the with Statement

Explains how to open, read, and write text files safely using Python's with-statement context manager to guarantee proper resource cleanup.

Reading and Writing CSV Files

Covers using Python's built-in csv module to read tabular data from CSV files and write structured results, a common task in engineering data workflows.

Working with JSON

Introduces JSON as a human-readable data interchange format and demonstrates how Python's json module serializes and deserializes data for configuration files and APIs.

Error Handling with try-except

Explains Python's exception handling model and demonstrates how to use try-except blocks to build resilient engineering scripts that recover gracefully from runtime errors.

Student Learning Outcomes

By the end of this module, students will be able to:

MO1
Construct a custom Python module containing reusable engineering functions, organized with a __name__ == '__main__' guard and module-level documentation
Level: CreateType: CognitiveCourse mapping: CO2
MO2
Apply the with-statement context manager to read from and write to text and CSV files using Python's built-in open() function and csv module
Level: ApplyType: CognitiveCourse mapping: CO3
MO3
Serialize and deserialize structured engineering data between Python objects and JSON format using the json module's load, loads, dump, and dumps functions
Level: ApplyType: CognitiveCourse mapping: CO1
MO4
Implement try-except blocks with else, finally, and raise clauses to handle runtime exceptions in scripts that perform file I/O and numeric operations
Level: ApplyType: CognitiveCourse mapping: CO3
MO5
Select appropriate standard library modules — including math, os, datetime, and pathlib — to accomplish specified engineering scripting tasks
Level: AnalyzeType: CognitiveCourse mapping: CO3

Course Outcomes (reference)

CO1Use variables, arrays and object structures appropriate to solve engineering problems.
CO2Write computer functions to meet specific calculation needs.
CO3Write computer programs to solve mathematical expressions and engineering problems