I seem to be having some issues with my if/else statements and EasyGUI choice box. I know that if the user presses "Cancel", it returns "None". My code always enters the "Else" statement. Also, my second For loop doesn't seem to be iterating. Is there a better way to select the object (country name) that I want? Here's my code so far, with debugging output.
UPDATE: The issue was the fact that I was using a Mac for some reason. I used my PC, and it worked as expected.
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]
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.