【发布时间】:2013-02-12 19:45:42
【问题描述】:
我的目标是代码中的最后一个打印行,但我真的不能,因为我一直收到此错误TypeError: unsupported operand type(s) for +: 'int' 和 '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] )
【问题讨论】:
标签: python int type-conversion output