我有一个像这样设置的字典 {'USA': ('123456', '456020832'), ... }
关键显然是国家,另外两个是面积(英里)和人口。我需要帮助尝试将区域和人口转换为 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(',', ''))
#i have tried countries[row[0]] = int((row[1].replace(',', '')), int(row[2].replace(',', '')) ) with no luck
reply = choicebox(msg=msg2, choices= list(countries.keys()) )
writeln(reply + "-\tArea: " + (countries[reply])[0] + "\tPopulation: " + (countries[reply])[1] )
谢谢!我只是不断收到有关转换的错误,所以我正在寻求帮助