From cf04024d38cdc7baf880bbb8b5882f5549745381 Mon Sep 17 00:00:00 2001 From: gwen Date: Wed, 3 May 2017 09:21:28 +0200 Subject: [PATCH] suppression des derniers fixme --- algorithmique/cours/programme.txt | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/algorithmique/cours/programme.txt b/algorithmique/cours/programme.txt index 0878939..f212fbb 100644 --- a/algorithmique/cours/programme.txt +++ b/algorithmique/cours/programme.txt @@ -437,4 +437,29 @@ Le prompt OCaml (utop):: Lire et écrire dans un fichier ------------------------------ -FIXME +Les descripteurs de fichiers (file handle) + +Exemple en python + +.. code-block:: python + + >>> fh = file("test.txt", "w") + >>> fh.write("un contenu exemple") + >>> fh.close() + >>> + +.. code-block:: python + + >>> fh.read() + 'un contenu exemple' + >>> fh.close() + >>> + +Linéarisation (serialisation) de données par exemple en json + +.. code-block:: python + + import json + data = dict(a='essai', b='essai2', c=range(3)) + with open('data.txt', 'w') as outfile: + json.dump(data, outfile)