Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

24 - Python Decorators

Python Difficulty: Intermediate Phase

What It Does

A showcase of Python decorators including timing, logging, retry, and memoization decorators with both function and class patterns.

Run It

python examples.py

Core Concepts

  • Function decorators with @ syntax
  • Decorator factories with arguments
  • functools.wraps pattern
  • Timing and logging decorators
  • Retry decorator with configurable attempts

What You Will Learn

You will learn how decorators work, when to use them, and how to build reusable decorators for cross-cutting concerns.

Project Structure

24-decorators/
  README.md
  decorators.py
  examples.py

Example Output

Decorator Showcase
------------------
[TIMER] slow_function took 2.003 seconds
[LOG] add(3, 5) called -> returned 8
[RETRY] Attempt 1 failed: Connection error
[RETRY] Attempt 2 succeeded
[CACHE] fibonacci(10) computed -> 55
[CACHE] fibonacci(10) returned cached -> 55