Hi all. Im in this situation: I want to perform several kind of (validating) methods to a given value. Lets say i have a class named Number, and the following methods: is_really_a_number(), is_even(), is_greater_than_zero(), and so on. All of them returning booleans.
I want the collect_validators() method is to execute any of the above methods, and collect their names as items of a list (wich will be the collect_validators() return value). My first approach is: [code] def collect_validators(self): v_dict = { 'is_really_a_number': is_really_a_number, 'is_even': is_even, 'is_greater_than_zero', is_greater_than_zero } for name, meth in v_dict.items(): result = meth() if result: yield name [/code] I wondering if is this a good pattern to apply, i like the way it looks like, at least to me it looks `natural', but...im calling every method twice here? One in v_dict and again on the dict iteration? Any suggestion will be great! Thanks! Gerardo -- http://mail.python.org/mailman/listinfo/python-list