Skip to content

Commit

Permalink
tweaks to the python challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
hjwp committed May 28, 2016
1 parent f551d5b commit d282a63
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions challenges/context_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def release_lock(lock_name):
to use "with open" -- that's actually already a context manager.
Building our own might take away some of the air of mystery from it...
So we want to run "hold_lock" before each function starts, and
"release_lock" at the end.
So you could use a decorator, but what if the function
raises an exception? now you have to have a try/except
and it gets yucky...
Expand Down
20 changes: 12 additions & 8 deletions challenges/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
For bonus points: the little time printout should include the name
of the function
For bonus bonus points:
- make a decorator that will retry a function up to n times, until
it gets a certain value:
@repeat(times=5, until_value=True)
def somebody_set_us_up_the_bomb():
...
"""

from datetime import datetime
Expand All @@ -44,3 +36,15 @@ def take_off_every_zig():
for i in range(1, 10001):
print('Go {}! '.format(i), end='')


"""
For bonus bonus points:
- now make a new decorator that will retry a function up to n times, until
it gets a certain value:
@repeat(times=5, until_value=True)
def somebody_set_us_up_the_bomb():
...
"""

4 changes: 3 additions & 1 deletion challenges/magic_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"""
Challenge: the Pythonic card deck class
The class CardDeck below represents a pack
of cards.
Find out how to use magic methods so that the
following three standard functions work:
Expand All @@ -22,7 +25,6 @@


class CardDeck:

ranks = [str(n) for n in range(2, 11)] + ['J', 'Q', 'K', 'A']
suits = '♠♡♢♣'

Expand Down

0 comments on commit d282a63

Please sign in to comment.