I'm looking for a resource that will help me turn my python function definitions into professional quality functions.
For example, my current python definitions have the following form:
def foo(arg1,arg2,arg3=some_val,arg4=some_other_val):
""" Do something with the args """
# Create data using args
if arg3 == this_val:
return dataset_1, dataset_2
else :
return dataset_1, dataset_2, dataset_3
I would like for a way to return the data I'm interested in based on what return data I ask for.
For example, I could say:
ds_1, ds_2, ds_3 = foo(arg1,arg2)
or
ds_1, ds_2 = foo(arg1,arg2,arg3=only_two_datasets_bool)
How do I make it so the function doesn't need the optional argument to know I only want two datasets?
This is analogous to say matplotlib constructors where one can say:
n = plt.hist(data)
where n is the histogram but one can also do
n, bins = plt.hist(data)
and the hist function knows to return those two values with the same input of data (ie no optional arguments stating it should return bins).