Skip to content

Instantly share code, notes, and snippets.

@rongpenl
Created May 29, 2023 04:22
Show Gist options
  • Save rongpenl/6144c7504ef7222ed759e465fdb0057c to your computer and use it in GitHub Desktop.
Save rongpenl/6144c7504ef7222ed759e465fdb0057c to your computer and use it in GitHub Desktop.
Cracking Intermediate Python Episode 1: Context Manager
from contextlib import contextmanager
from coach import Coach
@contextmanager
def activity_management(coach: Coach):
try:
coach.warm_up_players()
yield coach
finally:
coach.host_retro_meeting()
coach = Coach()
with activity_management(coach) as coach:
coach.coach_game()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment