我有以下代码:
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>
有没有办法通过更改我当前使用的字符串格式来完成此操作(在此问题的顶部)?
答案 0 :(得分:1)
#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())