Repository with sources and generator of https://larlet.fr/david/ https://larlet.fr/david/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.html 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <!doctype html>
  2. <html lang=fr>
  3. <head>
  4. <!-- Always define the charset before the title -->
  5. <meta charset=utf-8>
  6. <title>Principales nouveautés dans Python 2.5 — Biologeek — David Larlet</title>
  7. <!-- Define a viewport to mobile devices to use - telling the browser to assume that the page is as wide as the device (width=device-width) and setting the initial page zoom level to be 1 (initial-scale=1.0) -->
  8. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  9. <!-- Fake favicon, to avoid extra request to the server -->
  10. <link rel="icon" href="data:;base64,iVBORw0KGgo=">
  11. <link type="application/atom+xml" rel="alternate" title="Feed" href="/david/log/" />
  12. <link rel="manifest" href="/manifest.json">
  13. <link rel="stylesheet" href="/static/david/css/larlet-david-_J6Rv.css" data-instant-track />
  14. <noscript>
  15. <style type="text/css">
  16. /* Otherwise fonts are loaded by JS for faster initial rendering. See scripts at the bottom. */
  17. body {
  18. font-family: 'EquityTextB', serif;
  19. }
  20. h1, h2, h3, h4, h5, h6, time, nav a, nav a:link, nav a:visited {
  21. font-family: 'EquityCapsB', sans-serif;
  22. font-variant: normal;
  23. }
  24. </style>
  25. </noscript>
  26. <!-- Canonical URL for SEO purposes -->
  27. <link rel="canonical" href="https://larlet.fr/david/biologeek/archives/20060304-principales-nouveautes-dans-python-25">
  28. </head>
  29. <body>
  30. <div>
  31. <header>
  32. <nav>
  33. <p>
  34. <small>
  35. Je suis <a href="/david/" title="Profil public">David Larlet</a>, <a href="/david/pro/" title="Activité professionnelle">artisan</a> du web qui vous <a href="/david/pro/accompagnement/" title="Activité d’accompagnement">accompagne</a><span class="more-infos"> dans l’acquisition de savoirs pour concevoir des <a href="/david/pro/produits-essentiels/" title="Qu’est-ce qu’un produit essentiel ?">produits essentiels</a></span>. <span class="more-more-infos">Discutons ensemble d’une <a href="/david/pro/devis/" title="En savoir plus">non-demande de devis</a>.</span> Je partage ici mes <a href="/david/blog/" title="Expériences bienveillantes">réflexions</a> et <a href="/david/correspondances/2017/" title="Lettres hebdomadaires">correspondances</a>.
  36. </small>
  37. </p>
  38. </nav>
  39. </header>
  40. <section>
  41. <h1 property="schema:name">Principales nouveautés dans Python 2.5</h1>
  42. <article typeof="schema:BlogPosting">
  43. <div property="schema:articleBody">
  44. <img src="/static/david/biologeek/images/logos/python.png" alt="vignette" style="float:left; margin: 0.5em 1em;" property="schema:thumbnailUrl" />
  45. <p>Je m'y prend un peu à l'avance (la sortie est prévue pour septembre 2006) mais Guido a apparement fait <a href="http://agiletesting.blogspot.com/2006/02/pycon-notes-part-2-guidos-keynote.html">quelques annonces lors de Pycon</a> qui viennent s'ajouter aux <a href="http://www.python.org/dev/doc/devel/whatsnew/whatsnew25.html"><abbr title="Python Enhancement Proposals">PEP</abbr>s approuvés sur la page officielle</a>. J'essayerais de mettre à jour ce billet lors de l'annonce de nouvelles nouveautés histoire qu'il ne soit pas obsolète dans 6 mois, n'hésitez pas à m'en informer.</p>
  46. <p>Voici la liste des <abbr title="Python Enhancement Proposals">PEP</abbr>s acceptés par ordre de soumission&nbsp;:</p>
  47. <h2><abbr title="Python Enhancement Proposals">PEP</abbr> <a href="http://www.python.org/doc/peps/pep-0308/">308</a>&nbsp;: Ajout des expressions conditionnelles</h2>
  48. <p>Probablement pour remédier au difficilement compréhensible «&nbsp;<a href="http://diveintopython.adrahon.org/power_of_introspection/and_or.html#d0e10029">and-or trick</a> », même si <a href="http://mail.python.org/pipermail/python-dev/2005-September/056846.html">Guido a jugé bon de laisser une syntaxe assez difficile</a> pour des utilisations trop complexes intentionnellement (c'est vrai que le code devient vite illisible sinon).</p>
  49. <p>Syntaxe&nbsp;: expression1 <strong>if</strong> condition <strong>else</strong> expression2</p>
  50. <p>Exemples lisibles&nbsp;:</p>
  51. <pre>x = A if C else B
  52. x = lambda: A if C else B
  53. x = A if C else B if D else E</pre>
  54. <p>Exemples peu lisibles mais corrects&nbsp;:</p>
  55. <pre>if (A if C else B):
  56. [x for x in seq if (A if C else B)]
  57. A if (X if C else Y) else B
  58. (A if C else B) if D else E</pre>
  59. <p>Je sens que ça va faire fureur lors du «&nbsp;Annual Obfuscated Python Contest »&nbsp;!</p>
  60. <h2><abbr title="Python Enhancement Proposals">PEP</abbr> <a href="http://www.python.org/doc/peps/pep-0309/">309</a>&nbsp;: L'application de fonctions partielles</h2>
  61. <p>Là je dois avouer que j'ai pas trop compris en quoi ça consistait mais c'est la <a href="http://www.python.org/dev/doc/devel/whatsnew/node2.html">première amélioration citée</a> dans What's New in Python 2.5 donc j'imagine que c'est assez important, j'attend vos explications ;-).</p>
  62. <h2><abbr title="Python Enhancement Proposals">PEP</abbr> <a href="http://www.python.org/doc/peps/pep-0314/">314</a>&nbsp;: Méta-données pour les paquets Python</h2>
  63. <p>Bon le titre est assez explicite, un exemple&nbsp;:</p>
  64. <pre>Metadata-Version: 1.1
  65. Version: 1.0
  66. Platform: Linux2
  67. Supported-Platform: Ubuntu 5.10
  68. Summary: Mon premier paquet
  69. ...</pre>
  70. <p>Voila qui devrait ravir les concepteurs de paquets.</p>
  71. <h2><abbr title="Python Enhancement Proposals">PEP</abbr> <a href="http://www.python.org/doc/peps/pep-0328/">328</a>&nbsp;: Imports absolus/relatifs</h2>
  72. <p><del>Outre le fait de permettre un import sur plusieurs lignes :</del></p>
  73. <pre>from Tkinter import Tk, Frame, Button, Entry, \
  74. LEFT, DISABLED, NORMAL, RIDGE, END</pre>
  75. <p>Pourra maintenant être déclaré ainsi&nbsp;:</p>
  76. <pre>from Tkinter import (Tk, Frame, Button, Entry,
  77. LEFT, DISABLED, NORMAL, RIDGE, END)</pre>
  78. <p><strong>[Edit du 06.03.06]</strong>&nbsp;: comme le souligne tarek dans les commentaires, cette fonctionnalité est déjà implémentée dans python 2.4.</p>
  79. <p>Cette amélioration permet aussi d'importer des modules relativement&nbsp;:</p>
  80. <pre>from ..subpackage1 import moduleY</pre>
  81. <p>Par exemple pour importer le <strong>moduleY</strong> qui serait un dossier parent <strong>subpackage1</strong>.</p>
  82. <h2><abbr title="Python Enhancement Proposals">PEP</abbr> <a href="http://www.python.org/doc/peps/pep-0341/">341</a>&nbsp;: Unification de try-except et try-finally</h2>
  83. <p>C'est exactement ce dont j'ai besoin en ce moment, en effet j'utilise <strong>finally</strong> pour fermer les fichiers ouverts dans tous les cas et du coup j'ai quelque chose qui ressemble à&nbsp;:</p>
  84. <pre>f = None
  85. try:
  86. try:
  87. f = open(filename)
  88. text = f.read()
  89. except IOError:
  90. print 'An error occured'
  91. finally:
  92. if f:
  93. f.close()</pre>
  94. <p>Et c'est vraiment lourd, simplement car try-except-finally n'est pas possible actuellement, c'est ce que propose ce <abbr title="Python Enhancement Proposals">PEP</abbr> et ce sera donc réglé avec Python 2.5, ouf&nbsp;!</p>
  95. <h2><abbr title="Python Enhancement Proposals">PEP</abbr> <a href="http://www.python.org/doc/peps/pep-0342/">342</a>&nbsp;: Coroutines par générateurs améliorés</h2>
  96. <p>Énormément d'améliorations relatives aux générateurs, ce serait trop long de tout décrire ici. En plus je n'en ai pas compris la moitié...</p>
  97. <h2><abbr title="Python Enhancement Proposals">PEP</abbr> <a href="http://www.python.org/doc/peps/pep-0343/">343</a>&nbsp;: Le mot-clé «&nbsp;with »</h2>
  98. <p><strong>with</strong> permet d'effectuer une opération sur un objet, par exeple dans le cas d'un fichier il permettra de le lire sans avoir à le fermer à la fin&nbsp;:</p>
  99. <pre>with open(filename) as f:
  100. f.read()</pre>
  101. <p>Cette syntaxe permettra de simplifier les ouvertures fermetures de fichiers sans avoir à gérer ça avec des exceptions. Elle sera aussi très utile en cas de vérrou à placer&nbsp;:</p>
  102. <pre>def locked(lock):
  103. lock.acquire()
  104. try:
  105. # mon opération
  106. finally:
  107. lock.release()</pre>
  108. <p>Deviendra&nbsp;:</p>
  109. <pre>with locked(myLock):
  110. # mon opération</pre>
  111. <p>C'est aussi une amélioration qui me servirait bien en ce moment ça...</p>
  112. <h2>Conclusion</h2>
  113. <p>Toutes ces améliorations sont très frustrantes car c'est exactement ce dont j'ai besoin <strong>maintenant</strong>&nbsp;! Vivement septembre.</p>
  114. <p>Et pour fini <strong>lambda</strong> est <a href="http://mail.python.org/pipermail/python-dev/2006-February/060415.html">conservé, au grand regret de Guido...</a> et cElementTree est inséré dans la bibliothèque standard.</p>
  115. <p><strong>[Bonus]</strong>&nbsp;: une vidéo à voir absolument qui s'intitule <a href="http://oodt.jpl.nasa.gov/better-web-app.mov">Better Web App</a> (378.5mo, 36 minutes, anglais) et qui compare différent Web Frameworks (<abbr title="Ruby on Rails">RoR</abbr>, Zope/Plone, TurboGears et Django) et fourni en conclusion un tableau récapitulatif intéressant&nbsp;:</p>
  116. <p><img src="/static/david/biologeek/images/better_web_app.jpg" alt="Tableau comparatif entre les Web Frameworks" style="display:block; margin:0 auto;" /></p>
  117. <p><strong>[Edit du 06.03.06]</strong>&nbsp;: La home de <a href="http://www.python.org/">Python.org</a> est en pleine mue \o/ (en passant un <a href="http://linuxgazette.net/124/orr.html">lien intéressant</a> au sujet des nouveautés de Python 2.5).</p>
  118. <p><strong>[Edit du 11.03.06]</strong>&nbsp;: Le <abbr title="Python Enhancement Proposals">PEP</abbr> <a href="http://www.python.org/doc/peps/pep-0356/">356</a> résume tout ça et comprend le calendrier de développement (encore un bonus, l'<a href="http://www.eweek.com/article2/0,1895,1934746,00.asp">interview de <abbr title="Guido van Rossum">GvR</abbr> sur eweek</a>).</p>
  119. <p><strong>[Edit du 22.06.06]</strong>&nbsp;: L'annonce de <a href="http://linuxfr.org/~linuxcode/21967.html">Python 2.5 beta 1</a> sur dlfp qui est complétée de nombreux exemples (cette fois en bonus <a href="http://doxdesk.com/img/software/py/icons2.png">de beaux icônes</a> :-)).</p>
  120. </div>
  121. </article>
  122. <footer>
  123. <h6 property="schema:datePublished">— 04/03/2006</h6>
  124. </footer>
  125. </section>
  126. <section>
  127. <div>
  128. <h3>Articles peut-être en rapport</h3>
  129. <ul>
  130. <li><a href="/david/biologeek/archives/20080511-bonnes-pratiques-et-astuces-python/" title="Accès à Bonnes pratiques et astuces Python">Bonnes pratiques et astuces Python</a></li>
  131. <li><a href="/david/biologeek/archives/20061025-benchmarks-map-filter-vs-list-comprehensions/" title="Accès à Benchmarks map, filter vs. list-comprehensions">Benchmarks map, filter vs. list-comprehensions</a></li>
  132. <li><a href="/david/biologeek/archives/20060425-python-et-underscore/" title="Accès à Python : lisibilité vs simplicité">Python : lisibilité vs simplicité</a></li>
  133. </ul>
  134. </div>
  135. </section>
  136. <section>
  137. <div id="comments">
  138. <h3>Commentaires</h3>
  139. <div class="comment" typeof="schema:UserComments">
  140. <p class="comment-meta">
  141. <span class="comment-author" property="schema:creator">tarek</span> le <span class="comment-date" property="schema:commentTime">05/03/2006</span> :
  142. </p>
  143. <div class="comment-content" property="schema:commentText">
  144. <p>Pour le PEP 328, l'import multiligne a déjà été implémenté dans Python 2.4</p>
  145. </div>
  146. </div>
  147. <div class="comment" typeof="schema:UserComments">
  148. <p class="comment-meta">
  149. <span class="comment-author" property="schema:creator">S.F.</span> le <span class="comment-date" property="schema:commentTime">12/03/2006</span> :
  150. </p>
  151. <div class="comment-content" property="schema:commentText">
  152. <p>Si j'ai bien compris, les fonctions partielles permettent de donner une valeur à un argument d'une fonction. Ainsi,<br />
  153. <br />
  154. g = functional.partial(f, arg1 = 1')<br />
  155. <br />
  156. serait équivalent à<br />
  157. <br />
  158. g = lambda x, y: f(1, x, y)</p>
  159. </div>
  160. </div>
  161. <div class="comment" typeof="schema:UserComments">
  162. <p class="comment-meta">
  163. <span class="comment-author" property="schema:creator">David, biologeek</span> le <span class="comment-date" property="schema:commentTime">19/03/2006</span> :
  164. </p>
  165. <div class="comment-content" property="schema:commentText">
  166. <p>Merci pour ces précisions nud, c'était donc bien pour remplacer lambda.</p>
  167. </div>
  168. </div>
  169. <div class="comment" typeof="schema:UserComments">
  170. <p class="comment-meta">
  171. <span class="comment-author" property="schema:creator">David</span> le <span class="comment-date" property="schema:commentTime">31/07/2006</span> :
  172. </p>
  173. <div class="comment-content" property="schema:commentText">
  174. <p>sympa le &quot;with locked&quot;, j'en aurai besoin NOW !</p>
  175. </div>
  176. </div>
  177. </div>
  178. </section>
  179. <footer>
  180. <nav>
  181. <p>
  182. <small>
  183. Je réponds quasiment toujours aux <a href="m&#x61;ilto:d&#x61;vid%40l&#x61;rlet&#46;fr" title="Envoyer un email">emails</a> (<a href="/david/signature/" title="Ma signature actuelle avec possibilité de chiffrement">signés</a>) et vous pouvez me rencontrer à Montréal. <span class="more-infos">N’hésitez pas à <a href="/david/log/" title="Être tenu informé des mises à jour">vous abonner</a> pour être tenu informé des publications récentes.</span>
  184. </small>
  185. </p>
  186. </nav>
  187. </footer>
  188. </div>
  189. <script src="/static/david/js/larlet-david-3ee43f.js" data-no-instant></script>
  190. <script data-no-instant>InstantClick.init()</script>
  191. </body>
  192. </html>