I have a python function that requires several parameters. Something like:
def func(par1=1, par2=2, par3=3):
...
I want to make this callable from command line such as: function.py par1=1 par2=2 par3=3
.
I was thinking of doing it something like this:
import sys
if sys.argv[0][0:4]=="par1":
par1=int(sys.argv[0][5:])
else:
par1=1
but it doesn't look very nice, as the user might pass just some parametrs, or they might pass it as par1 =1
or par1= 1
or par1 = 1
so I would have to hard code with if-else all these possibilities. Is there a nicer, more professional solution? Thank you!