lundi 24 septembre 2018

Python function with many optional arguments

I currently have a function with many optional arguments, something like this:

def many_argument_function(required1, required2, optional1=1, optional2=2,
                           optional3=None, optional4="Test", optional5="g",
                           optional6=2, optional7=(0, 255, 0), optional8=0.5):
                           # Do stuff

But in reality, it has over 20 optional arguments which take five lines even with 120 line limit.

Is there a design pattern to simplify this/make it prettier?

P.S. I have considered making a separate configuration file for this function, but then calling it would be annoying since most of the time only one or two optional arguments are used.

Aucun commentaire:

Enregistrer un commentaire