Created
May 29, 2023 04:25
-
-
Save rongpenl/be0ef4a2ec5497d4c84efdb6450b700b to your computer and use it in GitHub Desktop.
Cracking Intermediate Python Episode 1: Context Manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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