I would like to create a function which can take either 1 or 2 arguments.
Currently, I have a function which takes exactly 2 arguments through CMD:
if countName == "lowest":
if optionalArg == "furthest:
if __name__ == '__main__':
countName = sys.argv
optionalArg = sys.argv
temp = len(sys.argv)
for i in xrange(1,temp):
I would then run:
python filename.py lowest furthest
Using this means that passing the second arg is a must. If I try to run my script just by passing one arg, it encounters an error (as expected). My question is, how do you create an optional argument, which could either be passed or not, depending on the situation?
python filename.py lowest
In this situation, I expect the program to perform the "#something else" script, as nothing was passed and it is different than "furthest".
Please do not write the code for me, I am here to learn :)