Python TypeError:+:'tag'和'str'不支持的操作数类型

时间:2013-07-16 12:27:05

标签: python xml curl

我使用excel文档(csv)的特定列中的数字来填充URL,cURL从中提取XML并将其放入outfile的新列(也是excel文档)。对列中的每个id重复此过程。我无法弄清楚为什么我收到此错误,因为输出实际上是一个字符串,我不明白为什么你不能用'tab'缓冲区连接它。我还以为我应该问这个,因为我没有看到任何其他问题将此错误与标签相关联,也许其他人也可以从中受益。无论如何这里有一些代码让我知道如果需要更多信息,我已经标记了错误发生的位置(靠近底部):

outFile = open(tempFileName, 'w')
outFile.write('\t'.join(fancyHeaders) + '\n')
outFile.write('\t'.join(order) + '\n')
lastFN = False
for line in data:
if lastFN!=line['AppStatus'] and lastFN:
    outFile.write('\n')
for column in order:
    outFile.write(line[column] + '\t') #Error occurs here
lastFN = line['AppStatus']
outFile.write('\n')
xlApp.Workbooks.OpenText(tempFileName)

xlApp.Range("A1:Z9999").HorizontalAlignment = -4131
xlApp.Range("A1:Z9999").VerticalAlignment = -4160
xlApp.Range("A1:Z9999").WrapText = True
xlApp.Cells.RowHeight=12.75

xlApp.DisplayAlerts=False
xlApp.ActiveWorkbook.SaveAs(outFileName)


xlApp.Quit()
xlApp.Visible = 0 # see note 2
del xlApp

2 个答案:

答案 0 :(得分:4)

如果行[column]不是字符串,则无法连接它,然后尝试更改:

str(line[column] + '\t')

成:

str(line[column]) + '\t'

答案 1 :(得分:3)

难道你不能这样写吗?

outFile.write(str(line[column]) + '\t')