我有以下代码:
new_file.write(("""
<cleared_for_hd_vod>%(enable_est_hd)s</cleared_for_hd_vod>
<cleared_for_hd_sale>%(enable_vod_hd)s</cleared_for_hd_sale>"""
% update_data).lower())这为我提供了以下内容:
<cleared_for_hd_vod>1</cleared_for_hd_vod>
<cleared_for_hd_sale>0</cleared_for_hd_sale>然而,我需要的是:
<cleared_for_hd_vod>true</cleared_for_hd_vod>
<cleared_for_hd_sale>false</cleared_for_hd_sale>有没有办法通过改变我当前使用的字符串格式(在这个问题的顶部)来实现这一点呢?
发布于 2013-04-08 04:10:41
#update_data={"enable_vod_hd": "1", "enable_est_hd": "1"}
newfile.write((
"""<cleared_for_hd_vod>%(enable_est_hd)s</cleared_for_hd_vod>
<cleared_for_hd_sale>%(enable_vod_hd)s</cleared_for_hd_sale>
""" %
({
'enable_est_hd': bool(update_data["enable_est_hd"]),
'enable_vod_hd': bool(update_data["enable_vod_hd"])
})
).lower())https://stackoverflow.com/questions/15867070
复制相似问题