Comment créer un fichier HTML avec Python

anwaarber Messages postés 10 Date d'inscription vendredi 17 décembre 2004 Statut Membre Dernière intervention 9 octobre 2005 - 9 oct. 2005 à 13:22
taz_iup Messages postés 179 Date d'inscription mercredi 13 octobre 2004 Statut Membre Dernière intervention 21 mai 2014 - 21 oct. 2005 à 17:59
salut a tous,
j'ai un problème lors de la création d'un fichier HTML avec python
surtout quand je fait passer des variables dans le code :

def informations():
a=input('entrer nom:')
b=input('entrer prénom:')
c=input('entrer date de naissance:')
d=input('entrer sexe:')

if d=='masculin':
texte=['<html>\n'
'<title>informations personnelles</title>\n'
'<head>\n'
'\n'
print'vous etes monsieur :"%s" "%s" ' % (a,b)
'\n'
'</head>\n'
'</html>']
x=open('site.html','w')
for i in texte:
x.write(i)
x.close()
il me donne une erreur de syntaxe ici
qui peut me corriger ce blème
A voir également:

2 réponses

taz_iup Messages postés 179 Date d'inscription mercredi 13 octobre 2004 Statut Membre Dernière intervention 21 mai 2014 3
21 oct. 2005 à 17:59
Pour les grand textes comme celui ci tu peux utiliser la triple quote :

texte = """<html>

<title>informations personnelles</title>

<head>



vous etes monsieur :"%s" "%s"



</head>

</html>""" % (a,b)



x=open('site.html','w')

x.write(texte)

x.close()
1
Rejoignez-nous