David542
David542

Reputation: 110143

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

Upvotes: 0

Views: 631

Answers (1)

Janus Troelsen
Janus Troelsen

Reputation: 21280

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

Upvotes: 1

Related Questions