I\'m very new to python and believe me, I\'ve searched endlessly for a solution to this but I just can\'t get it.
I have a csv with a list of monitoring plots. With the
choice = raw_input("Select a monitoring plot from the list: ")
if choice == 'q':
break
plotSelect = int(choice)
selected = dataList[plotSelect+1]
Check if the user entered q
and explicitly break out of the loop if they do (rather than relying on an exception being thrown). Only convert their input an int after this check.
Convert it into an integer after you check that it's not 'q'
:
try:
response = raw_input("Select a monitoring plot from the list: ")
if response == 'q':
break
selected = dataList[int(plotSelect) + 1]
print 'You selected : ', selected[1]
break
except ValueError:
print "Error: Please enter a number between 0 and 9"