{"id":2147,"date":"2020-04-13T18:20:58","date_gmt":"2020-04-13T16:20:58","guid":{"rendered":"http:\/\/www.ardpylab.fr\/?page_id=2147"},"modified":"2020-05-10T16:54:39","modified_gmt":"2020-05-10T14:54:39","slug":"les-fichiers","status":"publish","type":"page","link":"https:\/\/www.ardpylab.fr\/?page_id=2147","title":{"rendered":"Les fichiers"},"content":{"rendered":"\n<h6>&nbsp;<\/h6>\n<h6><span style=\"color: #999999;\">(<em>Cliquez pour afficher la version PDF)<\/em><\/span><\/h6>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/scriptspython3.pdf\">Les fichiers<\/a><a href=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/scriptspython3.pdf\" class=\"wp-block-file__button\" download>T\u00e9l\u00e9charger<\/a><\/div>\n\n\n\n<p>&nbsp;<\/p>\n<p>Pour sauvegarder des donn\u00e9es, il peut \u00eatre int\u00e9ressant de les stocker dans des fichiers qu\u2019il sera possible de lire ult\u00e9rieurement et \u00e9ventuellement modifier.<\/p>\n<p>En premier, il faut ouvrir ou cr\u00e9er un fichier avec la fonction <strong>open()<\/strong>. Cette fonction prend en premier param\u00e8tre le chemin du fichier et en second param\u00e8tre le type d&rsquo;ouverture&nbsp;:<\/p>\n<p style=\"padding-left: 40px;\"><strong>fichier = open(\u201dchemin\u201d, \u201dtype d&rsquo;ouverture\u201d)<\/strong><\/p>\n<p>On peut \u00e9galement pr\u00e9ciser l\u2019encodage du fichier&nbsp;:<\/p>\n<p style=\"padding-left: 40px;\"><strong>fichier = open(\u201dchemin\u201d, \u201dtype d&rsquo;ouverture\u201d, encoding=\u201dutf-8\u201d)<\/strong><\/p>\n<p>(UTF-8 est un encodage universel qui r\u00e9unit les caract\u00e8res utilis\u00e9s par toutes les langues)<\/p>\n<p>Les types d\u2019ouvertures sont&nbsp;:<\/p>\n<p style=\"padding-left: 40px;\">. <strong>\u201dr\u201d<\/strong>, pour une ouverture en lecture (READ).<\/p>\n<p style=\"padding-left: 40px;\">. <strong>\u201dw\u201d<\/strong>, pour une ouverture en \u00e9criture (WRITE), \u00e0 chaque ouverture le contenu du fichier est \u00e9cras\u00e9. Si le fichier n&rsquo;existe pas python le cr\u00e9e.<\/p>\n<p style=\"padding-left: 40px;\">. <strong>\u201da\u201d<\/strong>, pour une ouverture en mode ajout \u00e0 la fin du fichier (APPEND). Si le fichier n&rsquo;existe pas python le cr\u00e9e.<\/p>\n<p style=\"padding-left: 40px;\">. <strong>\u201db\u201d<\/strong>, pour une ouverture en mode binaire.<\/p>\n<p style=\"padding-left: 40px;\">. <strong>\u201dt\u201d<\/strong>, pour une ouverture en mode texte.<\/p>\n<p style=\"padding-left: 40px;\">. <strong>\u201dx\u201d<\/strong>, cr\u00e9e un nouveau fichier et l&rsquo;ouvre pour \u00e9criture.<\/p>\n<p>&nbsp;<\/p>\n<p>Pour v\u00e9rifier que l\u2019ouverture du fichier se fait correctement, il faut traiter une exception de type <strong>Exception<\/strong> (elle peut fournir une description de l\u2019erreur)&nbsp;:<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.ardpylab.fr\/downloads\/python\/fichiers\/fichier.py\" data-wplink-url-error=\"true\"><img loading=\"lazy\" decoding=\"async\" width=\"684\" height=\"125\" class=\"wp-image-2148 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier1.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier1.png 684w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier1-300x55.png 300w\" sizes=\"auto, (max-width: 684px) 100vw, 684px\" \/><\/a><\/figure>\n<\/div>\n<p><u>R\u00e9sultat dans la fen\u00eatre Python shell<\/u>&nbsp;:<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"686\" height=\"48\" class=\"wp-image-2149 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier2.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier2.png 686w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier2-300x21.png 300w\" sizes=\"auto, (max-width: 686px) 100vw, 686px\" \/><\/figure>\n<\/div>\n<p>&nbsp;<\/p>\n\n\n\n<p>Apr\u00e8s ouverture du fichier et une fois les instructions sur le fichier termin\u00e9es, il faut le fermer. Pour cela, on utilise la m\u00e9thode <strong>close()&nbsp;:<\/strong><\/p>\n<p style=\"padding-left: 40px;\"><strong>fichier.close()<\/strong><\/p>\n<p>&nbsp;<\/p>\n<h4><span style=\"color: #0000ff;\"><strong><a id=\"fich1\"><\/a>. <u>Lecture d\u2019un fichier<\/u><\/strong><\/span><\/h4>\n<p>&#8211; Pour afficher tout le contenu d&rsquo;un fichier, on peut utiliser la m\u00e9thode <strong>read<\/strong> sur l&rsquo;objet <strong>fichier&nbsp;<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.ardpylab.fr\/downloads\/python\/fichiers\/fichier-open.py\" data-wplink-url-error=\"true\"><img loading=\"lazy\" decoding=\"async\" width=\"686\" height=\"108\" class=\"wp-image-2152 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier3.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier3.png 686w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier3-300x47.png 300w\" sizes=\"auto, (max-width: 686px) 100vw, 686px\" \/><\/a><\/figure>\n<\/div>\n<p><u>R\u00e9sultat dans la fen\u00eatre Python Shell<\/u>&nbsp;:<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"687\" height=\"195\" class=\"wp-image-2153 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier4.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier4.png 687w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier4-300x85.png 300w\" sizes=\"auto, (max-width: 687px) 100vw, 687px\" \/><\/figure>\n<\/div>\n\n\n\n<p><br>L\u2019objet de type <strong>file<\/strong> est un objet qui peut se comporter comme une liste, ce qui permet d\u2019utiliser \u00e9galement une boucle <strong>for<\/strong> :<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.ardpylab.fr\/downloads\/python\/fichiers\/fichier-open2.py\" data-wplink-url-error=\"true\"><img loading=\"lazy\" decoding=\"async\" width=\"686\" height=\"156\" class=\"wp-image-2154 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier5.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier5.png 686w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier5-300x68.png 300w\" sizes=\"auto, (max-width: 686px) 100vw, 686px\" \/><\/a><\/figure>\n<\/div>\n<p>Attention, lorsque l\u2019on r\u00e9cup\u00e8re une ligne d\u2019un fichier, c\u2019est une cha\u00eene de caract\u00e8res qui se termine par le caract\u00e8re \u2019<strong>n<\/strong>\u2019 de fin de ligne.<\/p>\n<p>Ou bien simplement, la m\u00e9thode <strong>readline()<\/strong> :<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.ardpylab.fr\/downloads\/python\/fichiers\/fichier-open3.py\" data-wplink-url-error=\"true\"><img loading=\"lazy\" decoding=\"async\" width=\"685\" height=\"206\" class=\"wp-image-2155 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier6.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier6.png 685w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier6-300x90.png 300w\" sizes=\"auto, (max-width: 685px) 100vw, 685px\" \/><\/a><\/figure>\n<\/div>\n\n\n\n<p>Ces deux fa\u00e7ons de lire un fichier donnent cet affichage dans la fen\u00eatre Python Shell :<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"684\" height=\"337\" class=\"wp-image-2156 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier7.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier7.png 684w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier7-300x148.png 300w\" sizes=\"auto, (max-width: 684px) 100vw, 684px\" \/><\/figure>\n<\/div>\n<p>&nbsp;<\/p>\n\n\n\n<h4><strong><span style=\"color: #0000ff;\"><a id=\"fich2\"><\/a>. <u>Ecrire dans un fichier<\/u><\/span><\/strong><\/h4>\n<p>Pour \u00e9crire dans un fichier, il faut au pr\u00e9alable l\u2019ouvrir ou le cr\u00e9er en mode&nbsp;<strong>\u201dw\u201d<\/strong>,<strong> \u201da\u201d&nbsp;<\/strong>ou <strong>\u201dx\u201d<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.ardpylab.fr\/downloads\/python\/fichiers\/fichier-write.py\" data-wplink-url-error=\"true\"><img loading=\"lazy\" decoding=\"async\" width=\"687\" height=\"172\" class=\"wp-image-2161 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier8.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier8.png 687w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier8-300x75.png 300w\" sizes=\"auto, (max-width: 687px) 100vw, 687px\" \/><\/a><\/figure>\n<\/div>\n<p><u>R\u00e9sultat dans la fen\u00eatre Python Shell<\/u>&nbsp;:<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"687\" height=\"39\" class=\"wp-image-2162 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier9.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier9.png 687w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier9-300x17.png 300w\" sizes=\"auto, (max-width: 687px) 100vw, 687px\" \/><\/figure>\n<\/div>\n\n\n\n<p><br>A noter que pour le monde d&rsquo;ouverture <strong>\u201da\u201d<\/strong>, pour \u00e9crire \u00e0 la ligne, on peut utiliser le saut de ligne n :<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.ardpylab.fr\/downloads\/python\/fichiers\/fichier-write2.py\" data-wplink-url-error=\"true\"><img loading=\"lazy\" decoding=\"async\" width=\"684\" height=\"212\" class=\"wp-image-2163 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier10.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier10.png 684w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier10-300x93.png 300w\" sizes=\"auto, (max-width: 684px) 100vw, 684px\" \/><\/a><\/figure>\n<\/div>\n<p><u>R\u00e9sultat dans la fen\u00eatre Python Shell<\/u>&nbsp;:<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"686\" height=\"95\" class=\"wp-image-2164 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier11.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier11.png 686w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier11-300x42.png 300w\" sizes=\"auto, (max-width: 686px) 100vw, 686px\" \/><\/figure>\n<\/div>\n<p>&nbsp;<\/p>\n\n\n\n<h4><span style=\"color: #0000ff;\"><strong><a id=\"fich3\"><\/a>. <u>Autre m\u00e9thode d\u2019ouverture de fichiers<\/u><\/strong><\/span><\/h4>\n<p>Une ouverture de fichiers avec le mot cl\u00e9 <strong>with <\/strong>est \u00e9galement possible et cette m\u00e9thode pr\u00e9sente l\u2019avantage de ne pas \u00eatre oblig\u00e9 de fermer le fichier apr\u00e8s traitement par le programme.<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.ardpylab.fr\/downloads\/python\/fichiers\/fichier-open4.py\" data-wplink-url-error=\"true\"><img loading=\"lazy\" decoding=\"async\" width=\"686\" height=\"89\" class=\"wp-image-2166 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier12.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier12.png 686w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier12-300x39.png 300w\" sizes=\"auto, (max-width: 686px) 100vw, 686px\" \/><\/a><\/figure>\n<\/div>\n<p><u>R\u00e9sultat dans la fen\u00eatre Python Shell<\/u>&nbsp;:<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"686\" height=\"98\" class=\"wp-image-2167 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier13.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier13.png 686w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier13-300x43.png 300w\" sizes=\"auto, (max-width: 686px) 100vw, 686px\" \/><\/figure>\n<\/div>\n<p>&nbsp;<\/p>\n\n\n\n<p><u>Remarque<\/u>&nbsp;:<\/p>\n<p>Si l\u2019on ne pr\u00e9cise pas l\u2019emplacement o\u00f9 l\u2019on veut cr\u00e9er un fichier, celui-ci sera cr\u00e9\u00e9 dans le r\u00e9pertoire courant (en g\u00e9n\u00e9ral, dossier du script python).<\/p>\n\n\n\n<h4>&nbsp;<\/h4>\n<h4><strong><span style=\"color: #0000ff;\"><a id=\"fich4\"><\/a>. <\/span><\/strong><span style=\"color: #0000ff;\"><strong><u>Synth\u00e8se sur la manipulation des fichiers<\/u><\/strong><\/span><\/h4>\n<p>Le script ci-dessous r\u00e9sume les principales manipulations qu\u2019il est possible d\u2019effectuer avec un fichier&nbsp;:<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.ardpylab.fr\/downloads\/python\/fichiers\/lesfichiers.py\" data-wplink-url-error=\"true\"><img loading=\"lazy\" decoding=\"async\" width=\"686\" height=\"815\" class=\"wp-image-2181 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier14-1.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier14-1.png 686w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier14-1-253x300.png 253w\" sizes=\"auto, (max-width: 686px) 100vw, 686px\" \/><\/a><\/figure>\n<\/div>\n<p>Les taches effectu\u00e9es par la fonction <strong>ManipFichier() <\/strong>d\u00e9pendent des&nbsp; arguments de la fonction. <br>En effet, apr\u00e8s avoir v\u00e9rifi\u00e9 que l\u2019ouverture du fichier, dont le chemin est en argument, se fait correctement (structure <strong>try except<\/strong>), le fichier est soit lu, soit cr\u00e9\u00e9 et mis \u00e0 jour, soit ouvert et mis \u00e0 jour, en fonction des valeurs des arguments <strong>mode<\/strong> et <strong>text<\/strong>.<\/p>\n<p><u>R\u00e9sultats dans la fen\u00eatre Python shell<\/u>&nbsp;:<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"687\" height=\"406\" class=\"wp-image-2186 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier15.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier15.png 687w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier15-300x177.png 300w\" sizes=\"auto, (max-width: 687px) 100vw, 687px\" \/><\/figure>\n<\/div>\n<p>&nbsp;<\/p>\n\n\n\n<h4><span style=\"color: #0000ff;\"><strong><a id=\"fich5\"><\/a>. <\/strong><strong><u>Exemple d\u2019application<\/u><\/strong><\/span><\/h4>\n<p>Maintenant que nous savons sauvegarder des donn\u00e9es et d\u00e9finir des fonctions, nous allons pouvoir modifier le programme de cr\u00e9ation d\u2019inventaire de fa\u00e7on \u00e0 pouvoir enregistrer les modifications qui lui sont apport\u00e9es \u00e0 l&rsquo;aide de fonctions d\u00e9finies pour chaque action sur l&rsquo;inventaire.<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/www.ardpylab.fr\/downloads\/python\/fichiers\/inventaire2.py\" data-wplink-url-error=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-2192 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier16-561x1024.png\" alt=\"\" width=\"700\" height=\"1278\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier16-561x1024.png 561w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier16-164x300.png 164w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier16.png 686w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><\/figure>\n<\/div>\n<p><u>R\u00e9sultats dans la fen\u00eatre Python Shell<\/u>&nbsp;:<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"835\" height=\"882\" class=\"wp-image-2231 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier17.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier17.png 835w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier17-284x300.png 284w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier17-768x811.png 768w\" sizes=\"auto, (max-width: 835px) 100vw, 835px\" \/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"836\" height=\"426\" class=\"wp-image-2233 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier18.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier18.png 836w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier18-300x153.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonfichier18-768x391.png 768w\" sizes=\"auto, (max-width: 836px) 100vw, 836px\" \/><\/figure>\n<\/div>\n<p>&nbsp;<\/p>\n\n\n<div  class=\"grids-section grids-is-stretch\" style=\"--_gs-gap-desktop:0px 0px;--_gs-m-desktop:0 0 0 0;--_gs-p-desktop:0 0 0 0;--_gs-bg-desktop:transparent none;--_gs-bg-xp-desktop:0px;--_gs-zi-desktop:auto;--_gs-d-desktop:block;--_gs-mw-desktop:calc(100% - 0 - 0);--_gs-gap-tablet:0px 0px;--_gs-m-tablet:0 0 0 0;--_gs-p-tablet:0 0 0 0;--_gs-bg-tablet:transparent none;--_gs-bg-xp-tablet:0px;--_gs-zi-tablet:auto;--_gs-d-tablet:block;--_gs-mw-tablet:calc(100% - 0 - 0);--_gs-gap-mobile:0px 0px;--_gs-m-mobile:0 0 0 0;--_gs-p-mobile:0 0 0 0;--_gs-bg-mobile:transparent none;--_gs-bg-xp-mobile:0px;--_gs-zi-mobile:auto;--_gs-d-mobile:block;--_gs-mw-mobile:calc(100% - 0 - 0);--_gs-columns:2;--_gs-rows:1\"><div class=\"grids-s-w_i\">\n<div class=\"grids-area\" style=\"--_ga-column:1\/2;--_ga-row:1\/2;--_ga-m-desktop:0 0 0 0;--_ga-p-desktop:0 0 0 0;--_ga-bg-desktop:transparent none;--_ga-zi-desktop:auto;--_ga-d-desktop:flex;--_ga-mw-desktop:calc(100% - 0 - 0);--_ga-m-tablet:0 0 0 0;--_ga-p-tablet:0 0 0 0;--_ga-bg-tablet:transparent none;--_ga-zi-tablet:auto;--_ga-d-tablet:flex;--_ga-mw-tablet:calc(100% - 0 - 0);--_ga-m-mobile:0 0 0 0;--_ga-p-mobile:0 0 0 0;--_ga-bg-mobile:transparent none;--_ga-zi-mobile:auto;--_ga-d-mobile:flex;--_ga-mw-mobile:calc(100% - 0 - 0)\">\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><a href=\"https:\/\/www.ardpylab.fr\/?page_id=2106\"><img loading=\"lazy\" decoding=\"async\" width=\"50\" height=\"28\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/03\/moins.jpg\" alt=\"\" class=\"wp-image-107\"\/><\/a><\/figure><\/div>\n\n<\/div>\n\n<div class=\"grids-area\" style=\"--_ga-column:2\/3;--_ga-row:1\/2;--_ga-m-desktop:0 0 0 0;--_ga-p-desktop:0 0 0 0;--_ga-bg-desktop:transparent none;--_ga-zi-desktop:auto;--_ga-d-desktop:flex;--_ga-mw-desktop:calc(100% - 0 - 0);--_ga-m-tablet:0 0 0 0;--_ga-p-tablet:0 0 0 0;--_ga-bg-tablet:transparent none;--_ga-zi-tablet:auto;--_ga-d-tablet:flex;--_ga-mw-tablet:calc(100% - 0 - 0);--_ga-m-mobile:0 0 0 0;--_ga-p-mobile:0 0 0 0;--_ga-bg-mobile:transparent none;--_ga-zi-mobile:auto;--_ga-d-mobile:flex;--_ga-mw-mobile:calc(100% - 0 - 0)\">\n\n<div class=\"wp-block-image\"><figure class=\"alignright size-large\"><a href=\"https:\/\/www.ardpylab.fr\/?page_id=2201\"><img loading=\"lazy\" decoding=\"async\" width=\"50\" height=\"28\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/03\/plus.jpg\" alt=\"\" class=\"wp-image-106\"\/><\/a><\/figure><\/div>\n\n<\/div>\n<\/div><\/div>\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; (Cliquez pour afficher la version PDF) &nbsp; Pour sauvegarder des donn\u00e9es, il peut \u00eatre int\u00e9ressant de les stocker dans des fichiers qu\u2019il sera possible de lire ult\u00e9rieurement et \u00e9ventuellement modifier. En premier, il faut ouvrir ou cr\u00e9er un fichier avec la fonction open(). Cette fonction prend en premier param\u00e8tre le chemin du fichier et [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2147","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/2147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2147"}],"version-history":[{"count":0,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/2147\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}