我的目标是代码中的最后一个打印行,但我真的做不到,因为我一直收到此错误TypeError:
unsupported operand type(s) for +: ' int
' and ' str
'。有没有一种快速的方法来仅更改输出部分以使其成为可能?我仍然需要首先将它们转换为 int,但在这个输出的情况下,我需要在 int 旁边有“Population”和“Area”这两个词!
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]] = int(row[1].replace(',', '')), int(row[2].replace(',', ''))
reply = choicebox(msg=msg2, choices= list(countries.keys()) )
print(reply)
print((countries[reply])[0])
print((countries[reply])[1])
#print(reply + "- \tArea: + " + (countries[reply])[0] + "\tPopulation: " + (countries[reply])[1] )