PYTHON comment sauvegarder un fichier txt

Résolu/Fermé
Lolita - 26 déc. 2021 à 17:53
 Lolita - 27 déc. 2021 à 10:34
Bonjour,
Comment faire pour sauvegarder une str venant d'un programme ?
J'ai : print(("MESSAGE:",str(result)[2:]), end=' ')
Le texte s'affiche bien et je voudrai le sauvegarder en fichier .txt

Merci pour le retour et BONNES FETES A TOUS

python 3.8.10 (64)



Configuration: Linux / Firefox 95.0
A voir également:

2 réponses

yg_be Messages postés 22730 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024 1 477
26 déc. 2021 à 18:07
bonjour,
ceci t'aidera sans doute:
https://python.iutsf.org/lecon-6-les-fichiers/
0
Bonjour yg_be,
Grace à ton info j'y suis arrivé:

output_file = open("MESSAGE",'w')
output_file.write(str(result)[2:]) # , end=' ')
output_file.close()

Et ça fonctionne !!
MERCI
0