辞書内のタプルにある 2 つの要素を int 値に変換するのに少し問題があります。辞書のキーは国名で、情報のタプルは (地域、人口) です。これは私がこれまでに持っているものです:
def _demo_fileopenbox():
msg = "Pick A File!"
msg2 = "Select a country to learn more about!"
title = "Open files"
default="*.py"
f = fileopenbox(msg,title,default=default)
writeln("You chose to open file: %s" % f)
countries = {}
with open(f,'r') as handle:
reader = csv.reader(handle, delimiter = '\t')
for row in reader:
countries[row[0]] = (row[1].replace(',', ''), row[2].replace(',', ''))
for i in countries:
int((countries[i])[0])
int((countries[i])[1])
#while 1:
# reply = choicebox(msg=msg2, choices= list(countries.keys()) )
# writeln(reply + "-\tArea: " + (countries[reply])[0] + "\tPopulation: " + (countries[reply])[1] )
しかし、私はこのエラーが発生し続けます:
int((countries[i])[0])
ValueError: invalid literal for int() with base 10: ''
これを修正する方法またはこれを行うためのより良い方法: