i = 1
item_add = ''
content = 'test%'
item_add = ('%s' + '.' + content + '<br>') % i
print item_add
执行上面的程序会报错:TypeError: not enough arguments for format string
只要content中含有%的话,python 认为它是转移符,而实际我需要的就是%
我又不能把%进行替换,因为我需要的就是它。。
大家觉得怎么做比较好呢?
源程序是一段django的代码:
def hostcomment_display(self, obj):
item_add = ''
i = 1
for hostcomment_item in h.hostcomment_set.all():
content = hostcomment_item.comment
item_add += ('%s' + '.' + content + '\<br\>') % i
i += 1
return item_add
如果content中包含%,就报错TypeError: not enough arguments for format string
content = 'software备机--老的备份机-根94%'
打两个%符号: