getopt index out of range

Matthew Sacks ntwrkd at gmail.com
Wed Feb 11 17:20:36 EST 2009


Perhaps you can give me a call privately and I will explain it to you.
Regards,
Matthew

On Wed, Feb 11, 2009 at 1:48 PM, John Machin <sjmachin at lexicon.net> wrote:
> On Feb 11, 6:16 am, Matthew Sacks <ntw... at gmail.com> wrote:
>> Hi List,
>> I am getting an index out of range error when trying to parse with getopt.
>> Probably something simple. Any suggestions are appreciated
>>
>> optlist, args = getopt.getopt(sys.argv[1:], 'h', ['connectPassword=',
>> 'adminServerURL=', 'action=', 'targets=', 'appDir='])
>>
>> #Assign Opts
>> connectPassword = optlist[0][1]
>> adminServerURL = optlist[1][1]
>> action = optlist[2][1]
>> targets = optlist[3][1]
>> appDir = optlist[4][1]
>
> As you have been told, it is blowing up on index 0. That is because
> optlist is empty (in this case). optlist can contain anything from 0
> items to as many as your user cares to type in. It is NOT limited to
> the number of different options specified in the getopt call; consider
> the case where the arg string is "--action add --action del". Further,
> the contents of optlist are presented in the order they are typed in
> by the user.
>
> Consequently any attempt to give meaningful names to option values
> using constant subscripting of optlist is prima facie an utter
> nonsense.
>
> It is a mind-bogglingly astonishing utter nonsense given the lengthy
> conversation about getopt that we had in another thread yesterday.
> What on earth are you doing???
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list