Software Development
Intermediate Python and Clean Code Practices
Designed for developers whose Python works but is difficult to change. The course covers dataclasses, generators, decorators, context managers, and type hints, then applies the refactoring moves that turn a nine-hundred-line module into small tested units guarded by black, ruff, and mypy.
Overview
Practical learning for workplace transfer.
The usual symptom is a module that only its author dares to touch: functions with eleven parameters, flags that switch behavior three levels down, copy-pasted blocks that drifted apart, and a review queue where nobody can tell whether a change is safe. This course treats that as a structural problem, not a style preference. Participants learn the language features that remove duplication honestly — dataclasses, generators, decorators, context managers, protocols — and then rehearse extract-function, extract-class, and dependency-inversion refactorings on code with no tests, using automated tooling as the safety net.
Prerequisites
Six months or more of practical Python use. Participants should already write functions, use dictionaries, and read files confidently.
Objectives
- Refactor long procedural modules into cohesive functions, classes, and dataclasses.
- Apply generators and the iterator protocol to process large datasets without exhausting memory.
- Write decorators and context managers that remove repeated cross-cutting logic.
- Annotate an existing codebase with type hints and enforce them incrementally with mypy.
- Configure black, ruff, and pre-commit so style arguments disappear from code review.
- Design exception hierarchies and error contracts that callers can actually act on.
Target audience
- Python developers who ship working code but struggle to maintain it
- Data engineers whose notebooks have grown into production scripts
- Backend developers arriving in Python from Java, C#, or PHP
- Technical leads defining coding standards for a Python codebase
- Automation engineers maintaining shared internal tooling
- Code reviewers who need a shared vocabulary for Python quality
Program outline
A clear structure for the learning journey.
Outline points are grouped in one designed block instead of being treated as separate module cards.
01Pythonic Structure and Idioms4 topics
- Idiomatic iteration and unpacking in place of index-driven loops
- Comprehensions, generator expressions, and when a plain loop is clearer
- EAFP versus LBYL and the cost of defensive over-checking
- Naming, module layout, and the PEP 8 rules that actually affect review
02Classes, Dataclasses, and Data Modeling4 topics
- Deciding when a class earns its place and when a function is sufficient
- dataclasses and named tuples for records instead of loose dictionaries
- Properties, class methods, static methods, and dunder methods in practice
- Composition over inheritance, demonstrated by flattening a deep hierarchy
03Iterators, Generators, and Lazy Pipelines4 topics
- The iterator protocol and writing generator functions with yield
- Streaming a multi-gigabyte file without loading it into memory
- itertools for chunking, grouping, and windowing record streams
- Generator pipelines compared with building intermediate lists
04Decorators, Context Managers, and Reuse4 topics
- Closures, functools.wraps, and decorators that preserve signatures
- Timing, retry, caching, and audit logging written once as decorators
- contextlib for managing resources, temporary state, and cleanup
- Collapsing duplicated try and finally blocks into one managed scope
05Typing, Tooling, and Automated Quality Gates4 topics
- Type hints for functions, containers, Optional, Union, and Protocol
- Introducing mypy to an untyped codebase without stopping delivery
- black, ruff, and import ordering configured once in pyproject.toml
- pre-commit hooks that stop unformatted or unlinted code reaching review
06Refactoring and Review Workshop4 topics
- Reading a legacy module and mapping its real responsibilities
- Extract function, extract class, and replacing behavior flags with polymorphism
- Removing duplication without inventing premature abstractions
- Running a live review against an agreed team quality checklist
Materials provided
- Course workbook, annotated code samples, and reference notes
- Hands-on lab environment and starter repositories
- Exercises, checklists, and reusable code templates
- 4D Certificate of Completion
- Post-course technical guidance
Training Options
Programs can be delivered in-house, online, or in a blended format depending on your team's schedule, location, and learning objectives. When an external certificate or exam is included, certification rules and fees remain under the relevant awarding body's policies, while 4D provides the training and preparation support.
Why choose 4D
4D brings one of your own modules into the room and refactors it live, so the discussion is about your inheritance chains and your duplicated helpers rather than a textbook example. Participants leave with a configured pyproject.toml, a pre-commit setup, and a review checklist their team has already argued through and signed off.
Related courses
Python Programming Fundamentals
A hands-on introduction to Python for engineers and analysts who need working code rather than tutorial fragments. Participants build fluency with data types, collections, functions, files, and error handling, then assemble a small program that reads real data and produces a usable report.
View coursePython Automation and Scripting for Work Tasks
Aimed at teams losing hours every week to repetitive file, spreadsheet, and reporting work. Participants automate those tasks with Python: batch file handling, Excel and CSV processing, REST API calls, email alerts, and scheduled jobs that run unattended and report clearly when something fails.
View courseAdvanced Python: Concurrency and Performance
For engineers whose Python services and pipelines have hit a wall. The course starts with measurement — cProfile, py-spy, tracemalloc — then works through the GIL, threads, process pools, and asyncio, before covering NumPy vectorization, caching, and native acceleration for the paths that remain too slow.
View course