Posts

Showing posts with the label modularity

How to pass functions as parameters of another function with pre-specified arguments in python? [duplicate]

How to pass functions as parameters of another function with pre-specified arguments in python? [duplicate] This question already has an answer here: Is there a way to pass function with arguments that looks clean? For example, if I want pass function h with particular parameter-values a b from ars so that ars1 runs with these particular a b , what should I do? I want to do h a b a b def h(x, a, b): return x * a * b def ars(fcn): a = 1 b = 2 return ars1(fcn( . , a,b)) def ars1(fcn): return fcn(1)*fcn(1) ars(h) I could do def h(x, a, b): return x * a * b def ars(fcn): a = 1 b = 2 return ars1(fcn, a, b) def ars1(fcn, a, b): return fcn(1, a, b)*fcn(1, a, b) which achieves the purpose but since a b have nothing to do with ars1 , the code looks messy and lacks modularity. a b ars1 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. ...