getopt index out of range

M

Matthew Sacks

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]

#this statement never gets executed
print "Args: " + connectPassword + " " + adminServerURL + " " + action
+ " " + targets + " " + appDir

File "/home/msacks/untitled4.py", line 23, in ?
IndexError: index out of range: 0

TIA
 
J

John Machin

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???
 
M

Matthew Sacks

Keep your threadiquette to yourself.

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???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top