{"id":398,"date":"2022-01-11T09:37:37","date_gmt":"2022-01-11T08:37:37","guid":{"rendered":"http:\/\/yb-isn.fr\/2021\/nsi\/?p=398"},"modified":"2022-01-16T09:12:31","modified_gmt":"2022-01-16T08:12:31","slug":"representation-dun-texte-en-machine","status":"publish","type":"post","link":"http:\/\/yb-isn.fr\/2021\/nsi\/?p=398","title":{"rendered":"Repr\u00e9sentation d&rsquo;un texte en machine"},"content":{"rendered":"<p><!--more--><\/p>\n\n\n<figure><iframe loading=\"lazy\" src=\"https:\/\/player.vimeo.com\/video\/48858289?color=ffffff&amp;portrait=0\" width=\"640\" height=\"360\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/figure>\n\n\n\n<p class=\"has-very-light-gray-background-color has-background has-medium-font-size\"><strong>1) Code ASCII<\/strong><\/p>\n\n\n<p><em><strong>A<\/strong>m\u00e9ricain <strong>S<\/strong>tandard <strong>C<\/strong>ode for <strong>I<\/strong>nformation <strong>I<\/strong>nterchange<\/em>&nbsp; ou ASCII est un encodage cr\u00e9e en 1961.<\/p>\n<p>Il s&rsquo;agit d&rsquo;un jeu de 128 caract\u00e8re&nbsp; cod\u00e9s sur 7 bits.<\/p>\n<p><\/p>\n<p>on peut cr\u00e9er une liste en python contenant tout les caract\u00e8res cod\u00e9s en ascii.Les caract\u00e8res sp\u00e9ciaux sont pr\u00e9sent\u00e9s dans leur forme hexad\u00e9cimale<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-728 size-full\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/ascii.png\" alt=\"\" width=\"1008\" height=\"167\"><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-761\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/activit\u00e9.png\" alt=\"\" width=\"51\" height=\"38\">A vous de tester.<\/p>\n<p><a href=\"http:\/\/www.unicode.org\/charts\/\">&nbsp;<\/a><\/p>\n\n\n<p><\/p>\n\n\n\n<p class=\"has-very-light-gray-background-color has-background has-medium-font-size\"><strong>2) ISO-8859-1<\/strong><\/p>\n\n\n<p>Cet encodage sur 8 bit reprend l&rsquo;ascii pour les caract\u00e8res imprimables et ajoute les caract\u00e8res utiles \u00e0 l&rsquo;alphabet latin.La premi\u00e8re version date de 1986.<\/p>\n<p><\/p>\n<p>Les valeurs de 128 \u00e0 159 ne sont pas utilis\u00e9es.<\/p>\n\n\n<p class=\"has-very-light-gray-background-color has-background has-medium-font-size\"><strong>3) Unicode<\/strong><\/p>\n\n\n<p>en 2004 on adopte la norme Unicode&nbsp; qui va permettre des \u00e9changes de textes dans diff\u00e9rentes langues au niveau mondial.<\/p>\n<p>Le format UTF-8 est l&rsquo;encodage correspondant le plus r\u00e9pandu.Les textes cod\u00e9s en ascii et en iso-8859-1 restent compatibles avec l&rsquo;utf-8.<\/p>\n<p>UTF-8 continue apr\u00e8s 256 pour obtenir plus de 100 000 caract\u00e8res diff\u00e9rents en limitant l&rsquo;espace utilis\u00e9.<\/p>\n<p>Une table internationale fait correspondre un unique entier appel\u00e9 point de code \u00e0 chaque caract\u00e8re.<\/p>\n<p><a href=\"http:\/\/www.unicode.org\/charts\/\">http:\/\/www.unicode.org\/charts\/<\/a><\/p>\n<p>Deux exemples grace au lien ci-dessus<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-774 size-full\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/miscellanous.png\" alt=\"\" width=\"1009\" height=\"245\"><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-773 size-full\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/arabic.png\" alt=\"\" width=\"1012\" height=\"237\"><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-739 size-full\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/utf8.jpg\" alt=\"\" width=\"750\" height=\"217\"><\/p>\n<p><\/p>\n<p><strong>exemple en html<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n  &lt;\/head&gt;\n&lt;body&gt;\n&lt;p&gt;&amp;#9749 Un caf\u00e9  co\u00fbte 5 \u20ac&lt;\/p&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-731 \" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/caf\u00e9.png\" alt=\"\" width=\"239\" height=\"69\"><\/p>\n<p><strong>exemples dans jupyter notebook<\/strong><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-733 size-full\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/jupyter.png\" alt=\"\" width=\"304\" height=\"469\"><\/p>\n\n\n<p class=\"has-very-light-gray-background-color has-background has-medium-font-size\"><strong>4) Fichiers textes en python<\/strong><\/p>\n\n\n<p><strong>4.1) <span style=\"text-decoration: underline;\">Lecture<\/span><\/strong><\/p>\n<p>4.1.1) <span style=\"text-decoration: underline;\">Lecture en bloc avec read()<\/span><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-761\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/activit\u00e9.png\" alt=\"\" width=\"51\" height=\"38\"><a href=\"http:\/\/yb-isn.fr\/fondant.txt\">T\u00e9l\u00e9charger le fichier fondant.txt<\/a><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-761\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/activit\u00e9.png\" alt=\"\" width=\"51\" height=\"38\">ou cr\u00e9ez le fichiez en copiant le texte ci-dessous.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Etape 1 :Pr\u00e9chauffez votre four \u00e0 180\u00b0C (thermostat 6).Dans une casserole, faites fondre le chocolat et le beurre coup\u00e9 en morceaux \u00e0 feu tr\u00e8s doux.\nEtape 2 :Dans un saladier, ajoutez le sucre, les oeufs, la farine. M\u00e9langez.\nEtape 3 :Ajoutez le m\u00e9lange chocolat\/beurre. M\u00e9langez bien.\nEtape 4 :Beurrez et farinez votre moule puis y versez la p\u00e2te \u00e0 g\u00e2teau.\nEtape 5\t:Faites cuire au four environ 20 minutes.\nEtape 6\t:A la sortie du four le g\u00e2teau ne para\u00eet pas assez cuit. C'est normal, laissez-le refroidir puis d\u00e9moulez le.<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-761\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/activit\u00e9.png\" alt=\"\" width=\"51\" height=\"38\">Ouvrez le fichier txt et affichez son contenu dans une console python ou dans jupyter notebook<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">Fichier = open('fondant.txt','r')\ntexte=Fichier.read()\nFichier.close()\nprint(texte)<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-761\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/activit\u00e9.png\" alt=\"\" width=\"51\" height=\"38\">A vous de tester<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-761\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/activit\u00e9.png\" alt=\"\" width=\"51\" height=\"38\">Quel est le type de la variable texte ?<\/p>\n<p>4.1.2) <span style=\"text-decoration: underline;\">Lecture en bloc avec readlines<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">Fichier = open('fondant.txt','r')\nlines=Fichier.readlines()\nFichier.close()\nprint(lines)<\/pre>\n<p><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-761\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/activit\u00e9.png\" alt=\"\" width=\"51\" height=\"38\">A vous de tester .<\/p>\n<p>Quel est le type de la variable lines ?<\/p>\n<p>Affichez la troisi\u00e8me ligne.<\/p>\n<p>4.1.3) <span style=\"text-decoration: underline;\">Lecture ligne par ligne avec readline<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">Fichier = open('fondant.txt','r') \nwhile True: \n  line=Fichier.readline()\n  if line !=\"\": \n    print(line) \n  else: \n    break; \nFichier.close()<\/pre>\n<p><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-761\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/activit\u00e9.png\" alt=\"\" width=\"51\" height=\"38\">&nbsp;A vous de tester<\/p>\n<p>4.1.4) <span style=\"text-decoration: underline;\">Lecture ligne par ligne en it\u00e9rant sur l\u2019objet fichier<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">Fichier=open('fondant.txt','r')\nfor ligne in Fichier:\n    print(ligne)<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-761\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/activit\u00e9.png\" alt=\"\" width=\"51\" height=\"38\">&nbsp;A vous de tester<\/p>\n<p><strong>4.2) <span style=\"text-decoration: underline;\">Ecriture<\/span><\/strong><\/p>\n<p>4.2.1) <span style=\"text-decoration: underline;\">Ecriture d\u2019un fichier texte avec write()<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">Fichier = open('fondant.txt','w')\nFichier.write(\"Le Fondant au chocolat\\n\")\nFichier.close()\nFichier = open('fondant.txt','r')\ntexte=Fichier.read()\nFichier.close()\nprint(texte)<br><br><\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-761\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/activit\u00e9.png\" alt=\"\" width=\"51\" height=\"38\"><\/p>\n<p>4.2.2) <span style=\"text-decoration: underline;\">Ecriture d\u2019un fichier texte avec writelines()<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">Fichier = open('fondant.txt','r')\nlines=Fichier.readlines()\nFichier.close()\nFichier = open('fondant3.txt','w')\nFichier.write('LE FONDANT AU CHOCOLAT \\n\\n')\nFichier.writelines(lines)\nFichier.close()\nFichier = open('fondant3.txt','r')\ntexte=Fichier.read()\nFichier.close()\nprint(texte)<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-761\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/activit\u00e9.png\" alt=\"\" width=\"51\" height=\"38\"><\/p>\n<p><strong>4.3) Ajout dans un fichier texte<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">Fichier=open(\"fondant3.txt\",\"a\")\nFichier.write(\"\\n\\n\")\nFichier.write(\"Recette facile\")\nFichier.close()\nFichier = open('fondant3.txt','r')\ntexte=Fichier.read()\nFichier.close()\nprint(texte)<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-761\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/activit\u00e9.png\" alt=\"\" width=\"51\" height=\"38\"><\/p>\n\n\n<figure class=\"wp-block-image size-large\"><img src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2020\/01\/fhiertxt.png\" alt=\"\" class=\"wp-image-750\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/yb-isn.fr\/fondant.txt\"><img src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/12\/activit\u00e9.png\" alt=\"\" class=\"wp-image-761\"\/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":408,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/posts\/398"}],"collection":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=398"}],"version-history":[{"count":6,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/posts\/398\/revisions"}],"predecessor-version":[{"id":410,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/posts\/398\/revisions\/410"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/media\/408"}],"wp:attachment":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}