簡體   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