将Mysql bool转换为python True/Fals

2024-05-01 23:42:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码:

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())

这给了我以下信息:

^{pr2}$

但是,我需要的是:

<cleared_for_hd_vod>true</cleared_for_hd_vod>
<cleared_for_hd_sale>false</cleared_for_hd_sale>

有没有办法通过改变我当前使用的字符串格式(在这个问题的顶部)来实现这一点?在


Tags: 代码信息newfordataenableupdatesale
1条回答
网友
1楼 · 发布于 2024-05-01 23:42:43
#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())

相关问题 更多 >