getopt index out of range

Matthew Sacks ntwrkd at
Wed Feb 11 17:27:13 EST 2009

Keep your threadiquette to yourself.

On Wed, Feb 11, 2009 at 1:48 PM, John Machin <sjmachin at> wrote:
> On Feb 11, 6:16 am, Matthew Sacks <ntw... at> 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???
> --

More information about the Python-list mailing list