I'm having trouble understanding the meaning of semi-colons in shortops. I have such a longopt ["help", "runNum=","allplots=","sys=","redblue=","signalinj=","ranking="]
and I assign values to parameters with
try:
opts, args = getopt.getopt(sys.argv[1:],"h:", ["help","runNum=","allplots=","sys=","redblue=","signalinj=","ranking="])
except getopt.GetoptError:
print("Bad option. ")
sys.exit(2)
for o, a in opts:
if o=="-h" or o=='--help':
print("Ex: python3 app.py --runNum=55 --allplots=1 --sys=1 --ranking=0 --redblue=0 --signalinj=0")
elif o=="--runNum":
runNum = 'r'+str(a)
elif o=='--allplots':
_allplots=a
elif o=='--sys':
_sysflag=a
elif o=='--ranking':
_ranking=a
elif o=='--redblue':
_redblueflag=a
elif o=='--signalinj':
_signal_inj=a
When I run the app with python3 app.py
without any shotopts, it works fine but running with -
option returns "Bad option"
error instead of "Ex: python3 app.y ..."
and --help
returns UnboundLocalError: local variable 'runNum' referenced before assignment
error. So how can I make it print "Ex: python3 app.y ..."
.
I also tried "h:o"
but no improvement. This semi colon usage is still a mystery to me. i appreciate it if someone can explain this and tell me what to put on shortopts.