开发者

Python concatenation of variable and string

for i in range (0,len(list4)):
  ws.write(1, 0, datetime.now()开发者_开发技巧, style1)
  ws.write(2, 1, 1)
  ws.write(2, 2, xlwt.Formula("A3+B3"))
  wb.save('example.xls')

how do i generalize (A3+B3) ?

'"A" + i' + '"B" + i'  

Is this correct???


'A%(row)d+B%(row)d' % {'row': 3}

or

'A{0}+B{0}'.format(3)


You need:

ws.write(2, 2, xlwt.Formula("A" + str(i) + "+B" + str(i)))

Or more idiomatically:

ws.write(2, 2, xlwt.Formula("A%d+B%d" % (i,i)))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜