diff --git a/challenges/context_managers.py b/challenges/context_managers.py index 81509c5..e5811dc 100644 --- a/challenges/context_managers.py +++ b/challenges/context_managers.py @@ -42,31 +42,9 @@ def release_lock(lock_name): For bonus points: make it so that the user can also write to the lock file, for debugging purposes, when they're "inside" the context manager... -''' - - - -from datetime import datetime - -def my_program(): - main_screen_turn_on() - if somebody_set_us_up_the_bomb(): - take_off_every_zig() - -def main_screen_turn_on(): - print('\n'.join(['*' * 80] * 25)) - - - -def somebody_set_us_up_the_bomb(): - if datetime.now().microsecond % 7 == 0: - return True - return False - - -def take_off_every_zig(): - for i in range(1, 10001): - if datetime.now().microsecond % 42 == 0: - raise Exception('all your base!') - print('Go {}! '.format(i), end='') +Try to implement it with a custom class and the appropriate +__magic__ methods. Then checkout contextlib in the standard +library and try to build your context manager with the +contextlib.contextmanager decorator. +'''