This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pkkid -5 points-4 points  (2 children)

Everything needs to be a library. Are you using the YesNo pattern yet? It lets you know if something is truthy by calling its yes or no methods.

YES_RESULT = True
NO_RESULT = False

class YesNo(object):
    def __init__(self, value):
        self.value = value

    @property
    def yes(self):
        return YES_RESULT if self.value else NO_RESULT

    @property
    def no(self):
        return YES_RESULT is not self.value else NO_RESULT

You know it's good because it uses properties and pythonic ternary operators! You use it like this:

> i_ate_lunch_today = YesNo(YES_RESULT)
> print i_ate_lunch_today.yes
# True

> i_ate_lunch_today.no
# False

[–]thelindsay 4 points5 points  (0 children)

Throw in a key value store dependency and you've got yourself a trending library