Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 5 additions & 27 deletions challenges/context_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
'''