python把字典转换为html,Python字典转换为烧瓶中的HTML

不是最有效的,但能够完成任务,如果你想只通过已经呈现为HTML作为表变量的视图。更好的方法是只传递数据,然后让模板使用模板逻辑循环并在所需位置输出变量。

data = {'sentiment_analysis_result': [{'article_title': u'These Digital Locks Help Keep Tabs on Tenants', 'score': u'0.139613', 'type': u'positive'}, {'article_title': u'You Can Get a $50 Phone From Amazon, If You Don\u2019t Mind the Ads', 'score': u'0.239663', 'type': u'positive'}]}

table_string = '

for key, value in data.iteritems():

table_string += ''

table_string += '

' + key + ''

table_string += '

'

table_string += '

'

for i, d in enumerate(value):

if i == 0:

table_string += '

'

for k in d.iterkeys():

table_string += '

' + k + ''

table_string += '

'

table_string += '

'

for v in d.itervalues():

table_string += '

' + v + ''

table_string += '

'

table_string += '

'

table_string += '

'

print(table_string)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值