Lets say I've a list of ScriptMetadata object
class ScriptMetadata:
id = 1
script_name = "test"
script_run_start_time = 1
script_run_end_time = 3
..
..
I want to provide an API like below
class ScriptInfoParser:
def get_filtered_data(filter_func):
[I've logic here to obtain a uber list of ScriptMetadata]
# apply the user supplied filter func on this uber list and return result
result = filter(filter_func, all_metadata_list)
return list(result)
If I want to provide a filter func such that give me the ScriptMetadata objects for which script_name is "foo" I can have
def get_foo_runs(script_metadata):
if script_metadata.script_name == "foo":
return script_metadata
print(ScriptInfoParser.get_filtered_data(get_foo_runs))
Question is how can I parameterize the filter func so that I can have one function that can take parameters dynamically and apply filtering
get_script_runs(script_name):
<?? magic filter func>
return ScriptInfoParser.get_filtered_data(magic_filter_func) # returns scriptmetadata list that matches script_name
Also I wanna go complicated i.e more than one param e.g give me scriptmetadata items for script_name="foo" and script_run_end_time < 2 etc etc
Any help appreciated
None. You then set the values you want to match and call afind_matchingfunction that compares the fields that aren'tNone.selfparameter, unless they're static methods.