4D Training & Consultancy

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.

4 daysIn-house, online, or customized deliveryCorporate teams and professional groupsLevel: Intermediate

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.

Program outline

Outline points are grouped in one designed block instead of being treated as separate module cards.

Module 1: Pythonic Structure and Idioms

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

Module 2: Classes, Dataclasses, and Data Modeling

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

Module 3: Iterators, Generators, and Lazy Pipelines

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

Module 4: Decorators, Context Managers, and Reuse

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

Module 5: Typing, Tooling, and Automated Quality Gates

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

Module 6: Refactoring and Review Workshop

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.

Speak to 4D

Plan the right training or consultancy path for your team.

Share a few details and 4D will help route your inquiry toward corporate training, consultancy, assessment, Phoenix-enabled support, or a tailored program.