繁体   English   中英

将Mysql bool转换为python True / False

[英]Convert Mysql bool to python True/False

我有以下代码:

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>

有没有办法通过更改我当前使用的字符串格式来实现此目的(在此问题的顶部)?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM