All,
I have a personal script that I'm trying to write, and I've run into a small problem. The problem is that I want to be able to support a '-s' argument no matter where the argument is. I also want that argument to be allowed more than once. For example:
script.py firstargument secondargument -s thirdargument -s fourth fifth -s sixth
What I've tried isn't working. I've tried the following:
currentArg = 1
foldername = sys.argv[1:]
for folders in foldername:
if "-s" in folders:
newArg = currentArg + 1
setType = str(sys.argv[newArg])
function(setType)
What it's doing is that it's taking the -s as an argument and still passing that to the function. What I'd like it to above is see that the first '-s' is at the fourth position, add 1 to 4, and then setType is set to sys.argv[5]. I'd also like it to continue to loop through the arguments and find any '-s' and then use the next argument as the value. Any ideas?
Thanks!