简体   繁体   中英

Convert Mysql bool to python True/False

I have the following code:

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

This gives me the following:

<cleared_for_hd_vod>1</cleared_for_hd_vod>
<cleared_for_hd_sale>0</cleared_for_hd_sale>

However, what I need is the following:

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

Is there a way to accomplish this by changing the string formatting I am currently using (at the top of this question) ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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