Skip to main content
CodeOath

Backend engineering in Python · Chapter 2

Functions that carry the service

About this chapter

A small ticketing service needs an audit trail, and building one shows four tools that Python backends lean on. This chapter covers functions that accept arguments they do not know in advance, decorators that add timing and permission checks around many functions, generators that stream a large export without loading it all, and context managers that undo a change that fails halfway.

Who it is for: Developers who write Python functions comfortably and want to use the language features that real services rely on, with a reason for each.

You will be able to

  • Write a function that accepts extra positional and keyword arguments and passes them on correctly.
  • Write a decorator that wraps many functions with the same behaviour.
  • Use a generator to process a large file one line at a time.
  • Write a context manager that closes what it opened and undoes a change even when something fails.
  • Combine all four tools in one short audit-trail function.

The key idea: Each of the four tools answers one repeated problem: the same wrapper around many functions, data too large to hold at once, or a failure halfway through a change. Knowing which problem each solves matters more than remembering its syntax.

In this chapter

  1. Four tools, one audit trail
  2. Accepting what you do not know yet
  3. Decorators: the same wrapper on many functions
  4. Generators: an export that never holds the whole file
  5. Context managers: a change that always ends
  6. The four together

Locked: needs a plan

You can read chapter 1 free. Chapter 2 is the next one.

What you can do now, free: re-read chapter 1 and try its problems.

What a plan gives you: all chapters of the track you pick and their checks. Professional, one role is ₹329 a month or ₹2,299 a year. It renews until you cancel, and you can cancel any time. Paid plans open at launch.

Why is this locked?

Chapter 1 of every track is free, so you can see how the track reads. The rest of a track and its checks come with a plan, or open as you pass each chapter's check.

The price is for one period, a month or a year. A plan renews until you cancel.

Back to the track