Python partial function - ghdrako/doc_snipets GitHub Wiki

partial function

from functools import partial 
def run_stats_model(dataset, model, output_path):
  # process the dataset  
  # apply the model  # save the stats to the output path  
  calculated_stats = 123  
  return calculated_stats 
run_stats_model_a = partial(run_stats_model, model="model_a", output_path="project_a/stats/") 
run_stats_model_a("dataset_a") # output: 123

HINT A partial function has extra attributes compared with a regular function. You can check its attributes by calling dir(partial_function_created). We can find out which function a partial function is created from