prog:fichiers
Ceci est une ancienne révision du document !
Les fichiers en Python
Fichiers texte de base
# Fichier texte chemin = "/Users/jbpuel/Nextcloud/Programmation/Python/Testfile.txt" with open(chemin, "r", encoding='utf-8') as f: lignes = f.readlines() # Conserve les \n # lignes = f.read().splitlines() # Ne conserve pas les \n print (lignes) # f.seek(0) repositionne le pointeur en position 0 du fichier chemin = "/Users/jbpuel/Nextcloud/Programmation/Python/Testfile.txt" # Mode "w" write, écrase le fichier, "a" append with open(chemin, "a", encoding='utf-8') as f: f.write("\nRéussi") # Il y a aussi chemin = "/Users/jbpuel/Nextcloud/Programmation/Python/Testfile.txt" f = open(chemin, "r") f.close() # Indispensable si on utilise open comme une fonction
prog/fichiers.1584610230.txt.gz · Dernière modification : de jbpuel