【问题标题】:Python TypeError: unsupported operand types for +: 'tag' and 'str' [closed]Python TypeError:+的不支持的操作数类型:'tag'和'str' [关闭]
【发布时间】:2013-07-16 12:27:05
【问题描述】:

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

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

【问题讨论】:

  • 能否指出错误所在的一行?
  • outFile.write(line[column] + '\t')
  • 其实我公司的防火墙是必须的,所以是必须的。

标签: python xml curl


【解决方案1】:

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

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

进入:

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

【讨论】:

    【解决方案2】:

    你就不能这样写吗?

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-20
      • 2018-12-06
      • 1970-01-01
      • 2013-10-29
      • 1970-01-01
      • 1970-01-01
      • 2021-01-03
      相关资源
      最近更新 更多