Consider a method like the one below:
def find_missing(self, **kwargs):
if save == True:
tmp = find_one_missing(self.data)
tmp.to_csv(path)
else:
return find_one_missing(self.data)
What I am trying to achieve is the variables save and path to be kwargs, whereby the use can specify either
x.find_missing()
which will return the output of the find_one_missing() function, or alternatively the user can insert
x.find_missing(save=True, path=user_string_pathway)
and the output will be automatically saved to a location. How can I do this?
kwargs["save"]to access it (after checking to see if it's present). Similarly forpath.def find_missing(self, save=None, path=None):Then you could access the arguments normally.**kwargsat all? That's something you use if you want your function to accept arbitrary keyword arguments. It looks like you're looking for default values and/or keyword-only argument syntax.save_toargument, or just removing thesaveargument and keepingpath. You don't need two separate arguments, and using one argument avoids problems with people passing inconsistent arguments.