class Search:

    def __init__(self):
        self.conditions = {}

def make_set_condition(option):

    def set_cond(self, value):
        self.conditions[option] = value
return self
return set_cond
for option in ('price', 'name'):
    setattr(Search, option, make_set_condition(option))
Search().name('Nice name').price('$3').conditions
{'price': '$3', 'name': 'Nice name'}
Dynamically add methods to a class in Python 3.0