python - Ordering multiple functions with enable/disable options -


i sending ajax request "data" field containing string, multiple options user sets. each option either "enabled" or "disabled", , act enable or disable functions in class. wondering if there better way of organizing code doesn't involve calling every function , checking see if enabled or disabled?

class parse(webapp2.requesthandler):     def post(self):         data = self.request.get("data")         func1_option = self.request.get("func1_option")          func2_option = self.request.get("func2_option")          func3_option = self.request.get("func3_option")           newdata = func1(func2(func3(data)))         self.response.write(newdata)          def func1(foo):             if funct1_option = "disabled":                 return foo             else:                 return some.function(foo)          def func2(foo):             if funct2_option = "disabled":                 return foo             else:                 return some.function(foo)          def func3(foo):             if funct3_option = "disabled":                 return foo             else:                 return some.function(foo) 

class parse(webapp2.requesthandler):     def post(self):         data = self.request.get("data")          # note - order reversed         funcs = [             ("func3_option", some.other_other_function),             ("func2_option", some.other_function),             ("func1_option", some.function)         ]         opt_name, func in funcs:             if self.request.get(opt_name) != "disabled":                 data = func(data)          self.response.write(data) 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -