2013-04-07 5 views
0

je le code suivant:Convertir Mysql bool à python Vrai/Faux

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

Cela me donne les éléments suivants:

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

Cependant, ce que je besoin est le suivant:

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

Existe-t-il un moyen d'y parvenir en modifiant la mise en forme de chaîne que j'utilise actuellement (en haut de cette question)?

+0

est-ce que 'bool (% (enable_est_hd) s)' ne fonctionne pas? – karthikr

+0

Comment cela serait-il écrit? – David542

+0

quel est le type python de enable_vod_hd? quel connecteur mysql utilisez-vous? – soulcheck

Répondre

1
#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()) 
Questions connexes