Hello I'm new to python programming and wasn't sure how to use getopt. So, since I thought python was a pretty straight forward language, I decided to write my own getopt function. It goes like this:
string = "a b -c -d"
list = string.split()
def get_short_opts(args):
opts = ""
for word in args:
print("Word = " + word)
if word[0] == '-' and word[1] != '-':
opts += word[1:] #to remove the '-'
args.remove(word)
print("Opts = " + opts)
print("Args = " + str(args))
return opts
print(get_short_opts(list))
Basically, this function returns all characters located after a "-" character. It works when I use multiple options at one time and with only one "-" and if I do something like
["-a", "arg", "-b"]
But when I try to pass multiple options immediately after each other, it doesn't work. The main code above is an example of when it does not work. Could you explain why it only works sometimes and not other times? Any help would be appreciated. Thank you!