According to this, choicebox
returns None
then the cancel button is pressed, and not the string 'None'
. Change your condition to if choice is None:
and it should work.
The problem with your second for
loop is that csvdict
is an iterator which is exhausted after you use it in your first for
loop. You could either create a new iterator, or store the contents of the file in a list, or dictionary, if it is not too much data. You already did this for the country
field, but you seem to need all the fields. The best might be to create a dict
mapping the country
names to lists holding the other fields, so you can quickly access them instead of having to loop over all the contries again.
// instead of your first for loop
choices = dict()
for line in csvdict:
choices[line['Country']] = line
...
// instead of your second for loop
if choice in choices:
line = choices[choice]
...