Skip to content

Instantly share code, notes, and snippets.

@rongpenl
Created May 29, 2023 04:25
Show Gist options
  • Save rongpenl/be0ef4a2ec5497d4c84efdb6450b700b to your computer and use it in GitHub Desktop.
Save rongpenl/be0ef4a2ec5497d4c84efdb6450b700b to your computer and use it in GitHub Desktop.
Cracking Intermediate Python Episode 1: Context Manager
from coach import Coach
class ActivityManagedCoach(Coach):
def __enter__(self):
self.warm_up_players()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.host_retro_meeting()
print(f"Exception type: {exc_type}")
print(f"value: {exc_val}")
print(f"traceback: {exc_tb}")
if __name__ == "__main__":
with ActivityManagedCoach() as coach:
coach.coach_game()
raise Exception("Game Finishes Too Late!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment