1
0
Fork 0
python-docs-fr/faq/programming.po

3477 lines
150 KiB
Plaintext
Raw Normal View History

2018-07-04 09:06:45 +00:00
# Copyright (C) 2001-2018, Python Software Foundation
2018-07-04 09:08:42 +00:00
# For licence information, see README file.
2016-10-30 09:46:26 +00:00
#
msgid ""
msgstr ""
2019-12-05 22:15:54 +00:00
"Project-Id-Version: Python 3\n"
2016-10-30 09:46:26 +00:00
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-01-15 22:33+0100\n"
"PO-Revision-Date: 2022-11-20 22:12+0100\n"
"Last-Translator: Jean Abou Samra <jean@abou-samra.fr>\n"
2018-07-04 09:14:25 +00:00
"Language-Team: FRENCH <traductions@lists.afpy.org>\n"
2017-05-23 22:40:56 +00:00
"Language: fr\n"
2016-10-30 09:46:26 +00:00
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.4.2\n"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:5
2016-10-30 09:46:26 +00:00
msgid "Programming FAQ"
2019-06-12 12:29:00 +00:00
msgstr "FAQ de programmation"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:8
2018-06-10 09:32:30 +00:00
msgid "Contents"
msgstr "Sommaire"
2018-06-10 09:32:30 +00:00
#: faq/programming.rst:12
2016-10-30 09:46:26 +00:00
msgid "General Questions"
2019-06-12 12:29:00 +00:00
msgstr "Questions générales"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:15
2016-10-30 09:46:26 +00:00
msgid ""
"Is there a source code level debugger with breakpoints, single-stepping, "
"etc.?"
msgstr ""
"Existe-t-il un débogueur de code source avec points d'arrêts, exécution pas-"
2021-10-27 17:49:12 +00:00
"à-pas, etc. ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:58
2016-10-30 09:46:26 +00:00
msgid "Yes."
2017-05-24 20:55:30 +00:00
msgstr "Oui."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:19
2016-10-30 09:46:26 +00:00
msgid ""
"Several debuggers for Python are described below, and the built-in function :"
"func:`breakpoint` allows you to drop into any of them."
msgstr ""
2019-12-12 10:59:24 +00:00
"Plusieurs débogueurs sont décrits ci-dessous et la fonction native :func:"
"`breakpoint` permet d'utiliser n'importe lequel d'entre eux."
#: faq/programming.rst:22
msgid ""
2016-10-30 09:46:26 +00:00
"The pdb module is a simple but adequate console-mode debugger for Python. It "
"is part of the standard Python library, and is :mod:`documented in the "
"Library Reference Manual <pdb>`. You can also write your own debugger by "
"using the code for pdb as an example."
msgstr ""
2019-12-12 10:59:24 +00:00
"Le module ``pdb`` est un débogueur console simple, mais parfaitement adapté "
"à Python. Il fait partie de la bibliothèque standard de Python, sa "
2019-06-12 12:29:00 +00:00
"documentation se trouve dans le :mod:`manuel de référence <pdb>`. Vous "
2019-12-12 10:59:24 +00:00
"pouvez vous inspirer du code de ``pdb`` pour écrire votre propre débogueur."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:27
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"The IDLE interactive development environment, which is part of the standard "
"Python distribution (normally available as `Tools/scripts/idle3 <https://"
"github.com/python/cpython/blob/main/Tools/scripts/idle3>`_), includes a "
2016-10-30 09:46:26 +00:00
"graphical debugger."
msgstr ""
2019-06-12 12:29:00 +00:00
"L'environnement de développement interactif IDLE, qui est fourni avec la "
"distribution standard de Python (normalement disponible dans ``Tools/scripts/"
"idle``) contient un débogueur graphique."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:32
2016-10-30 09:46:26 +00:00
msgid ""
"PythonWin is a Python IDE that includes a GUI debugger based on pdb. The "
"PythonWin debugger colors breakpoints and has quite a few cool features such "
"as debugging non-PythonWin programs. PythonWin is available as part of "
"`pywin32 <https://github.com/mhammond/pywin32>`_ project and as a part of "
"the `ActivePython <https://www.activestate.com/products/python/>`_ "
"distribution."
2016-10-30 09:46:26 +00:00
msgstr ""
"*PythonWin* est un environnement de développement intégré (EDI) Python qui "
"embarque un débogueur graphique basé sur ``pdb``. Le débogueur *PythonWin* "
2019-12-12 10:59:24 +00:00
"colore les points d'arrêts et possède quelques fonctionnalités sympathiques, "
"comme la possibilité de déboguer des programmes développés sans "
"*PythonWin*. *PythonWin* est disponible dans le projet `pywin32 <https://"
"github.com/mhammond/pywin32>`_ et fait partie de la distribution "
"`ActivePython <https://www.activestate.com/products/python/>`_."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:39
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"`Eric <https://eric-ide.python-projects.org/>`_ is an IDE built on PyQt and "
2016-10-30 09:46:26 +00:00
"the Scintilla editing component."
msgstr ""
2019-06-12 12:29:00 +00:00
"`Eric <http://eric-ide.python-projects.org/>`_ est un EDI basé sur PyQt et "
"l'outil d'édition Scintilla."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:42
2016-10-30 09:46:26 +00:00
msgid ""
"`trepan3k <https://github.com/rocky/python3-trepan/>`_ is a gdb-like "
"debugger."
msgstr ""
"`trepan3k <https://github.com/rocky/python3-trepan/>`_ est un débogueur "
"semblable à GDB."
#: faq/programming.rst:44
msgid ""
"`Visual Studio Code <https://code.visualstudio.com/>`_ is an IDE with "
"debugging tools that integrates with version-control software."
2016-10-30 09:46:26 +00:00
msgstr ""
"`Visual Studio Code <https://code.visualstudio.com/>`_ est un EDI qui "
"contient des outils de débogage. Il sait interagir avec les outils de "
2021-10-27 17:49:12 +00:00
"gestion de versions."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:47
2016-10-30 09:46:26 +00:00
msgid ""
"There are a number of commercial Python IDEs that include graphical "
"debuggers. They include:"
msgstr ""
2019-06-12 12:29:00 +00:00
"Il existe de nombreux EDI Python propriétaires qui embarquent un débogueur "
"graphique, notamment :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:50
msgid "`Wing IDE <https://wingware.com/>`_"
msgstr "`Wing IDE <https://wingware.com/>`_ ;"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:51
msgid "`Komodo IDE <https://www.activestate.com/products/komodo-ide/>`_"
msgstr "`Komodo IDE <https://www.activestate.com/products/komodo-ide/>`_ ;"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:52
msgid "`PyCharm <https://www.jetbrains.com/pycharm/>`_"
msgstr "`PyCharm <https://www.jetbrains.com/pycharm/>`_ ;"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:56
2020-10-02 08:55:01 +00:00
msgid "Are there tools to help find bugs or perform static analysis?"
2016-10-30 09:46:26 +00:00
msgstr ""
"Existe-t-il des outils pour aider à trouver des bogues ou faire de l'analyse "
"statique de code ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:60
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"`Pylint <https://pylint.pycqa.org/en/latest/index.html>`_ and `Pyflakes "
"<https://github.com/PyCQA/pyflakes>`_ do basic checking that will help you "
"catch bugs sooner."
2016-10-30 09:46:26 +00:00
msgstr ""
"`Pylint <https://www.pylint.org/>`_ et `Pyflakes <https://github.com/PyCQA/"
"pyflakes>`_ font des vérifications de base et vous aideront à trouver des "
"bogues plus tôt."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:64
2018-09-15 20:37:31 +00:00
msgid ""
"Static type checkers such as `Mypy <http://mypy-lang.org/>`_, `Pyre <https://"
"pyre-check.org/>`_, and `Pytype <https://github.com/google/pytype>`_ can "
"check type hints in Python source code."
msgstr ""
2019-06-12 12:29:00 +00:00
"Les vérificateurs statiques de typage comme `Mypy <http://mypy-lang.org/>`_, "
"`Pyre <https://pyre-check.org/>`_, et `Pytype <https://github.com/google/"
"pytype>`_ peuvent vérifier les indications de type dans du code source "
"Python."
2018-09-15 20:37:31 +00:00
#: faq/programming.rst:73
2016-10-30 09:46:26 +00:00
msgid "How can I create a stand-alone binary from a Python script?"
2021-10-27 17:49:12 +00:00
msgstr "Comment créer un binaire autonome à partir d'un script Python ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:75
2016-10-30 09:46:26 +00:00
msgid ""
"You don't need the ability to compile Python to C code if all you want is a "
"stand-alone program that users can download and run without having to "
"install the Python distribution first. There are a number of tools that "
"determine the set of modules required by a program and bind these modules "
"together with a Python binary to produce a single executable."
msgstr ""
2019-06-12 12:29:00 +00:00
"Pour créer un programme autonome, c'est-à-dire un programme que n'importe "
"qui peut télécharger et exécuter sans avoir à installer une distribution "
"Python au préalable, il n'est pas nécessaire de compiler du code Python en "
"code C. Il existe en effet plusieurs outils qui déterminent les modules "
"requis par un programme et lient ces modules avec un binaire Python pour "
"produire un seul exécutable."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:81
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"One is to use the freeze tool, which is included in the Python source tree "
"as `Tools/freeze <https://github.com/python/cpython/tree/main/Tools/"
"freeze>`_. It converts Python byte code to C arrays; with a C compiler you "
"can embed all your modules into a new program, which is then linked with the "
"standard Python modules."
2016-10-30 09:46:26 +00:00
msgstr ""
2021-05-19 16:06:14 +00:00
"Un de ces outils est *freeze*, qui se trouve dans ``Tools/freeze`` de "
2019-06-12 12:29:00 +00:00
"l'arborescence des sources de Python. Il convertit le code intermédiaire "
"(*bytecode*) Python en tableaux C ; avec un compilateur C, vous pouvez "
"intégrer tous vos modules dans un nouveau programme, qui est ensuite lié aux "
"modules standards Python."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:87
2016-10-30 09:46:26 +00:00
msgid ""
"It works by scanning your source recursively for import statements (in both "
"forms) and looking for the modules in the standard Python path as well as in "
"the source directory (for built-in modules). It then turns the bytecode for "
"modules written in Python into C code (array initializers that can be turned "
"into code objects using the marshal module) and creates a custom-made config "
"file that only contains those built-in modules which are actually used in "
"the program. It then compiles the generated C code and links it with the "
"rest of the Python interpreter to form a self-contained binary which acts "
"exactly like your script."
msgstr ""
2021-10-27 17:49:12 +00:00
"Il fonctionne en cherchant de manière récursive les instructions "
"d'importation (sous les deux formes) dans le code source et en recherchant "
"ces modules dans le chemin Python standard ainsi que dans le répertoire "
"source (pour les modules natifs). Il transforme ensuite le code "
"intermédiaire des modules écrits en Python en code C (des tableaux pré-"
"remplis qui peuvent être transformés en objets code à l'aide du module "
"*marshal*) et crée un fichier de configuration personnalisé qui contient "
"uniquement les modules natifs qui sont réellement utilisés dans le "
"programme. Il compile ensuite le code C généré et le lie au reste de "
"l'interpréteur Python pour former un binaire autonome qui fait exactement la "
"même chose que le script."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:96
2016-10-30 09:46:26 +00:00
msgid ""
2021-06-04 11:47:25 +00:00
"The following packages can help with the creation of console and GUI "
"executables:"
msgstr ""
"Voici quelques paquets qui permettent de créer des exécutables en ligne de "
"commande comme graphiques :"
2021-06-04 11:47:25 +00:00
#: faq/programming.rst:99
2021-06-04 11:47:25 +00:00
msgid "`Nuitka <https://nuitka.net/>`_ (Cross-platform)"
msgstr "`Nuitka <https://nuitka.net/>`_ (multiplateformes) ;"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:100
#, fuzzy
msgid "`PyInstaller <https://pyinstaller.org/>`_ (Cross-platform)"
msgstr "`PyInstaller <http://www.pyinstaller.org/>`_ (multiplateformes) ;"
#: faq/programming.rst:101
msgid ""
2021-06-04 11:47:25 +00:00
"`PyOxidizer <https://pyoxidizer.readthedocs.io/en/stable/>`_ (Cross-platform)"
msgstr ""
"`PyOxidizer <https://pyoxidizer.readthedocs.io/en/stable/>`_ (multi-"
"plateforme) ;"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:102
2016-10-30 09:46:26 +00:00
msgid ""
2021-06-04 11:47:25 +00:00
"`cx_Freeze <https://marcelotduarte.github.io/cx_Freeze/>`_ (Cross-platform)"
msgstr ""
"`cx_Freeze <https://marcelotduarte.github.io/cx_Freeze/>`_ (multi-"
"plateforme) ;"
2021-06-04 11:47:25 +00:00
#: faq/programming.rst:103
2021-06-04 11:47:25 +00:00
msgid "`py2app <https://github.com/ronaldoussoren/py2app>`_ (macOS only)"
2016-10-30 09:46:26 +00:00
msgstr ""
"`py2app <https://github.com/ronaldoussoren/py2app>`_ (uniquement pour "
"macOS) ;"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:104
#, fuzzy
msgid "`py2exe <https://www.py2exe.org/>`_ (Windows only)"
msgstr "`py2exe <http://www.py2exe.org/>`_ (uniquement pour Windows)."
2021-06-04 11:47:25 +00:00
#: faq/programming.rst:107
2016-10-30 09:46:26 +00:00
msgid "Are there coding standards or a style guide for Python programs?"
msgstr ""
"Existe-t-il des normes de développement ou un guide de style pour écrire des "
2021-10-27 17:49:12 +00:00
"programmes Python ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:109
2016-10-30 09:46:26 +00:00
msgid ""
"Yes. The coding style required for standard library modules is documented "
"as :pep:`8`."
msgstr ""
2019-06-12 12:29:00 +00:00
"Oui. Le style de développement que les modules de la bibliothèque standard "
"doivent obligatoirement respecter est documenté dans la :pep:`8`."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:114
2016-10-30 09:46:26 +00:00
msgid "Core Language"
2019-06-12 12:29:00 +00:00
msgstr "Fondamentaux"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:119
2016-10-30 09:46:26 +00:00
msgid "Why am I getting an UnboundLocalError when the variable has a value?"
msgstr ""
2021-10-27 17:49:12 +00:00
"Pourquoi une UnboundLocalError est levée alors qu'une variable a une valeur ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:121
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"It can be a surprise to get the :exc:`UnboundLocalError` in previously "
"working code when it is modified by adding an assignment statement somewhere "
"in the body of a function."
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"Il est parfois surprenant d'obtenir une UnboundLocalError dans du code "
"jusqu'à présent correct, quand celui-ci est modifié en ajoutant une "
"instruction d'affectation quelque part dans le corps d'une fonction."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:125
2016-10-30 09:46:26 +00:00
msgid "This code:"
2021-10-27 17:49:12 +00:00
msgstr "Le code suivant :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:134
2016-10-30 09:46:26 +00:00
msgid "works, but this code:"
2021-10-27 17:49:12 +00:00
msgstr "fonctionne, mais le suivant :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:141
#, fuzzy
msgid "results in an :exc:`!UnboundLocalError`:"
2021-10-27 17:49:12 +00:00
msgstr "lève une UnboundLocalError :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:148
2016-10-30 09:46:26 +00:00
msgid ""
"This is because when you make an assignment to a variable in a scope, that "
"variable becomes local to that scope and shadows any similarly named "
"variable in the outer scope. Since the last statement in foo assigns a new "
"value to ``x``, the compiler recognizes it as a local variable. "
"Consequently when the earlier ``print(x)`` attempts to print the "
"uninitialized local variable and an error results."
msgstr ""
2019-06-12 12:29:00 +00:00
"Cela est dû au fait que, quand une variable est affectée dans un contexte, "
"cette variable devient locale à ce contexte et remplace toute variable du "
"même nom du contexte appelant. Vu que la dernière instruction dans *foo* "
"affecte une nouvelle valeur à ``x``, le compilateur la traite comme une "
"nouvelle variable. Par conséquent, quand le ``print(x)`` essaye d'afficher "
"la variable non initialisée, une erreur se produit."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:155
2016-10-30 09:46:26 +00:00
msgid ""
"In the example above you can access the outer scope variable by declaring it "
"global:"
msgstr ""
2019-06-12 12:29:00 +00:00
"Dans l'exemple ci-dessus, la variable du contexte appelant reste accessible "
2021-10-27 17:49:12 +00:00
"en la déclarant globale :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:167
2016-10-30 09:46:26 +00:00
msgid ""
"This explicit declaration is required in order to remind you that (unlike "
"the superficially analogous situation with class and instance variables) you "
"are actually modifying the value of the variable in the outer scope:"
msgstr ""
2019-06-12 12:29:00 +00:00
"Cette déclaration explicite est obligatoire pour se rappeler que "
"(contrairement au cas à peu près similaire avec des variables de classe et "
"d'instance), c'est la valeur de la variable du contexte appelant qui est "
2021-10-27 17:49:12 +00:00
"modifiée :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:174
2016-10-30 09:46:26 +00:00
msgid ""
"You can do a similar thing in a nested scope using the :keyword:`nonlocal` "
"keyword:"
msgstr ""
2019-06-12 12:29:00 +00:00
"Une alternative dans un contexte imbriqué consiste à utiliser le mot-clé :"
2021-10-27 17:49:12 +00:00
"keyword:`nonlocal` :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:192
2016-10-30 09:46:26 +00:00
msgid "What are the rules for local and global variables in Python?"
msgstr ""
2021-10-27 17:49:12 +00:00
"Quelles sont les règles pour les variables locales et globales en Python ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:194
2016-10-30 09:46:26 +00:00
msgid ""
"In Python, variables that are only referenced inside a function are "
"implicitly global. If a variable is assigned a value anywhere within the "
"function's body, it's assumed to be a local unless explicitly declared as "
"global."
msgstr ""
2019-06-12 12:29:00 +00:00
"En Python, si une variable n'est pas modifiée dans une fonction mais "
"seulement lue, elle est implicitement considérée comme globale. Si une "
"valeur lui est affectée, elle est considérée locale (sauf si elle est "
"explicitement déclarée globale)."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:198
2016-10-30 09:46:26 +00:00
msgid ""
"Though a bit surprising at first, a moment's consideration explains this. "
"On one hand, requiring :keyword:`global` for assigned variables provides a "
"bar against unintended side-effects. On the other hand, if ``global`` was "
"required for all global references, you'd be using ``global`` all the time. "
"You'd have to declare as global every reference to a built-in function or to "
"a component of an imported module. This clutter would defeat the usefulness "
"of the ``global`` declaration for identifying side-effects."
msgstr ""
2019-06-12 12:29:00 +00:00
"Bien que surprenant au premier abord, ce choix s'explique facilement. D'une "
"part, exiger :keyword:`global` pour des variables affectées est une "
"protection contre des effets de bord inattendus. D'autre part, si ``global`` "
"était obligatoire pour toutes les références à des objets globaux, il "
"faudrait mettre ``global`` partout, car il faudrait dans ce cas déclarer "
"globale chaque référence à une fonction native ou à un composant d'un module "
"importé. Le codé serait alors truffé de déclarations ``global``, ce qui "
2021-10-27 17:49:12 +00:00
"nuirait à leur raison d'être : identifier les effets de bords."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:208
2016-10-30 09:46:26 +00:00
msgid ""
"Why do lambdas defined in a loop with different values all return the same "
"result?"
msgstr ""
2019-06-12 12:29:00 +00:00
"Pourquoi des expressions lambda définies dans une boucle avec des valeurs "
2021-10-27 17:49:12 +00:00
"différentes retournent-elles le même résultat ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:210
2016-10-30 09:46:26 +00:00
msgid ""
"Assume you use a for loop to define a few different lambdas (or even plain "
"functions), e.g.::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Supposons que l'on utilise une boucle itérative pour définir des expressions "
2021-10-27 17:49:12 +00:00
"lambda (voire des fonctions) différentes, par exemple ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:217
2016-10-30 09:46:26 +00:00
msgid ""
"This gives you a list that contains 5 lambdas that calculate ``x**2``. You "
"might expect that, when called, they would return, respectively, ``0``, "
"``1``, ``4``, ``9``, and ``16``. However, when you actually try you will "
"see that they all return ``16``::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Le code précédent crée une liste de 5 expressions lambda qui calculent "
"chacune ``x**2``. En les exécutant, on pourrait s'attendre à obtenir ``0``, "
"``1``, ``4``, ``9`` et ``16``. Elles renvoient en réalité toutes ``16`` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:227
2016-10-30 09:46:26 +00:00
msgid ""
"This happens because ``x`` is not local to the lambdas, but is defined in "
"the outer scope, and it is accessed when the lambda is called --- not when "
"it is defined. At the end of the loop, the value of ``x`` is ``4``, so all "
"the functions now return ``4**2``, i.e. ``16``. You can also verify this by "
"changing the value of ``x`` and see how the results of the lambdas change::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Ceci s'explique par le fait que ``x`` n'est pas une variable locale aux "
"expressions, mais est définie dans le contexte appelant. Elle est lue à "
"l'appel de l'expression lambda et non au moment où cette expression est "
2019-06-12 12:29:00 +00:00
"définie. À la fin de la boucle, ``x`` vaut ``4``, donc toutes les fonctions "
"renvoient ``4*2``, c.-à-d. ``16``. Ceci se vérifie également en changeant la "
"valeur de ``x`` et en constatant que les résultats sont modifiés ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:237
2016-10-30 09:46:26 +00:00
msgid ""
"In order to avoid this, you need to save the values in variables local to "
"the lambdas, so that they don't rely on the value of the global ``x``::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Pour éviter ce phénomène, les valeurs doivent être stockées dans des "
"variables locales aux expressions lambda pour que celles-ci ne se basent "
"plus sur la variable globale ``x`` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:244
2016-10-30 09:46:26 +00:00
msgid ""
"Here, ``n=x`` creates a new variable ``n`` local to the lambda and computed "
"when the lambda is defined so that it has the same value that ``x`` had at "
"that point in the loop. This means that the value of ``n`` will be ``0`` in "
"the first lambda, ``1`` in the second, ``2`` in the third, and so on. "
"Therefore each lambda will now return the correct result::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Dans ce code, ``n=x`` crée une nouvelle variable ``n``, locale à "
"l'expression. Cette variable est évaluée quand l'expression est définie donc "
"``n`` a la même valeur que ``x`` à ce moment. La valeur de ``n`` est donc "
"``0`` dans la première lambda, ``1`` dans la deuxième, ``2`` dans la "
"troisième et ainsi de suite. Chaque expression lambda renvoie donc le "
"résultat correct ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:255
2016-10-30 09:46:26 +00:00
msgid ""
"Note that this behaviour is not peculiar to lambdas, but applies to regular "
"functions too."
msgstr ""
2019-06-12 12:29:00 +00:00
"Ce comportement n'est pas propre aux expressions lambda, mais s'applique "
"aussi aux fonctions normales."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:260
2016-10-30 09:46:26 +00:00
msgid "How do I share global variables across modules?"
2021-10-27 17:49:12 +00:00
msgstr "Comment partager des variables globales entre modules ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:262
2016-10-30 09:46:26 +00:00
msgid ""
"The canonical way to share information across modules within a single "
"program is to create a special module (often called config or cfg). Just "
"import the config module in all modules of your application; the module then "
"becomes available as a global name. Because there is only one instance of "
"each module, any changes made to the module object get reflected "
"everywhere. For example:"
msgstr ""
2019-06-12 12:29:00 +00:00
"La manière standard de partager des informations entre modules d'un même "
"programme est de créer un module spécial (souvent appelé *config* ou *cfg*) "
2021-10-27 17:49:12 +00:00
"et de l'importer dans tous les modules de l'application ; le module devient "
2019-06-12 12:29:00 +00:00
"accessible depuis l'espace de nommage global. Vu qu'il n'y a qu'une instance "
"de chaque module, tout changement dans l'instance est propagé partout. Par "
2021-10-27 17:49:12 +00:00
"exemple :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:268
2016-10-30 09:46:26 +00:00
msgid "config.py::"
msgstr "*config.py* ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:272
2016-10-30 09:46:26 +00:00
msgid "mod.py::"
msgstr "*mod.py* ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:277
2016-10-30 09:46:26 +00:00
msgid "main.py::"
msgstr "*main.py* ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:283
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"Note that using a module is also the basis for implementing the singleton "
2016-10-30 09:46:26 +00:00
"design pattern, for the same reason."
msgstr ""
2019-06-12 12:29:00 +00:00
"Pour les mêmes raisons, l'utilisation d'un module est aussi à la base de "
"l'implémentation du patron de conception singleton."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:288
2016-10-30 09:46:26 +00:00
msgid "What are the \"best practices\" for using import in a module?"
msgstr ""
2021-10-27 17:49:12 +00:00
"Quelles sont les « bonnes pratiques » pour utiliser import dans un module ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:290
2016-10-30 09:46:26 +00:00
msgid ""
"In general, don't use ``from modulename import *``. Doing so clutters the "
"importer's namespace, and makes it much harder for linters to detect "
"undefined names."
msgstr ""
2019-06-12 12:29:00 +00:00
"De manière générale, il ne faut pas faire ``from modulename import *``. Ceci "
"encombre l'espace de nommage de l'importateur et rend la détection de noms "
"non-définis beaucoup plus ardue pour les analyseurs de code."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:294
2016-10-30 09:46:26 +00:00
msgid ""
"Import modules at the top of a file. Doing so makes it clear what other "
"modules your code requires and avoids questions of whether the module name "
"is in scope. Using one import per line makes it easy to add and delete "
"module imports, but using multiple imports per line uses less screen space."
msgstr ""
2019-06-12 12:29:00 +00:00
"Les modules doivent être importés au début d'un fichier. Ceci permet "
"d'afficher clairement de quels modules le code à besoin et évite de se "
"demander si le module est dans le contexte. Faire un seul ``import`` par "
"ligne rend l'ajout et la suppression d'une importation de module plus aisé, "
"mais importer plusieurs modules sur une même ligne prend moins d'espace."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:299
2016-10-30 09:46:26 +00:00
msgid "It's good practice if you import modules in the following order:"
2021-10-27 17:49:12 +00:00
msgstr "Il est recommandé d'importer les modules dans l'ordre suivant :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:301
#, fuzzy
msgid ""
"standard library modules -- e.g. :mod:`sys`, :mod:`os`, :mod:`argparse`, :"
"mod:`re`"
2016-10-30 09:46:26 +00:00
msgstr ""
"les modules de la bibliothèque standard — p. ex. ``sys``, ``os``, "
"``getopt``, ``re``"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:302
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"third-party library modules (anything installed in Python's site-packages "
"directory) -- e.g. :mod:`!dateutil`, :mod:`!requests`, :mod:`!PIL.Image`"
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"les modules externes (tout ce qui est installé dans le dossier *site-"
"packages* de Python) — p. ex. *mx.DateTime, ZODB, PIL.Image*, etc."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:304
#, fuzzy
msgid "locally developed modules"
2019-06-12 12:29:00 +00:00
msgstr "les modules développés en local"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:306
2016-10-30 09:46:26 +00:00
msgid ""
"It is sometimes necessary to move imports to a function or class to avoid "
"problems with circular imports. Gordon McMillan says:"
msgstr ""
2019-06-12 12:29:00 +00:00
"Il est parfois nécessaire de déplacer des importations dans une fonction ou "
"une classe pour éviter les problèmes d'importations circulaires. Comme le "
2021-10-27 17:49:12 +00:00
"souligne Gordon McMillan :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:309
2016-10-30 09:46:26 +00:00
msgid ""
"Circular imports are fine where both modules use the \"import <module>\" "
"form of import. They fail when the 2nd module wants to grab a name out of "
"the first (\"from module import name\") and the import is at the top level. "
"That's because names in the 1st are not yet available, because the first "
"module is busy importing the 2nd."
msgstr ""
2019-06-12 12:29:00 +00:00
"Il n'y a aucun souci à faire des importations circulaires tant que les deux "
"modules utilisent la forme ``import <module>``. Ça ne pose problème que si "
2019-06-12 12:29:00 +00:00
"le second module cherche à récupérer un nom du premier module (*\"from "
"module import name\"*) et que l'importation est dans l'espace de nommage du "
"fichier. Les noms du premier module ne sont en effet pas encore disponibles "
"car le premier module est occupé à importer le second."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:315
2016-10-30 09:46:26 +00:00
msgid ""
"In this case, if the second module is only used in one function, then the "
"import can easily be moved into that function. By the time the import is "
"called, the first module will have finished initializing, and the second "
"module can do its import."
msgstr ""
2019-06-12 12:29:00 +00:00
"Dans ce cas, si le second module n'est utilisé que dans une fonction, "
"l'importation peut facilement être déplacée dans cette fonction. Au moment "
"où l'importation sera appelée, le premier module aura fini de s'initialiser "
"et le second pourra faire son importation."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:320
2016-10-30 09:46:26 +00:00
msgid ""
"It may also be necessary to move imports out of the top level of code if "
"some of the modules are platform-specific. In that case, it may not even be "
"possible to import all of the modules at the top of the file. In this case, "
"importing the correct modules in the corresponding platform-specific code is "
"a good option."
msgstr ""
2019-06-12 12:29:00 +00:00
"Il peut parfois être nécessaire de déplacer des importations de modules hors "
"de l'espace de plus haut niveau du code si certains de ces modules dépendent "
"de la machine utilisée. Dans ce cas de figure, il est parfois impossible "
"d'importer tous les modules au début du fichier. Dans ce cas, il est "
"recommandé d'importer les modules adéquats dans le code spécifique à la "
"machine."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:325
2016-10-30 09:46:26 +00:00
msgid ""
"Only move imports into a local scope, such as inside a function definition, "
"if it's necessary to solve a problem such as avoiding a circular import or "
"are trying to reduce the initialization time of a module. This technique is "
"especially helpful if many of the imports are unnecessary depending on how "
"the program executes. You may also want to move imports into a function if "
"the modules are only ever used in that function. Note that loading a module "
"the first time may be expensive because of the one time initialization of "
"the module, but loading a module multiple times is virtually free, costing "
"only a couple of dictionary lookups. Even if the module name has gone out "
"of scope, the module is probably available in :data:`sys.modules`."
msgstr ""
2021-10-27 17:49:12 +00:00
"Les importations ne devraient être déplacées dans un espace de nommage "
"local, comme dans la définition d'une fonction, que si cela est nécessaire "
"pour résoudre un problème comme éviter des dépendances circulaires ou "
"réduire le temps d'initialisation d'un module. Cette technique est "
"particulièrement utile si la majorité des importations est superflue selon "
"le flux d'exécution du programme. Il est également pertinent de déplacer des "
"importations dans une fonction si le module n'est utilisé qu'au sein de "
"cette fonction. Le premier chargement d'un module peut être coûteux à cause "
"du coût fixe d'initialisation d'un module, mais charger un module plusieurs "
"fois est quasiment gratuit, cela ne coûte que quelques indirections dans un "
2019-06-12 12:29:00 +00:00
"dictionnaire. Même si le nom du module est sorti du contexte courant, le "
"module est probablement disponible dans :data:`sys.modules`."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:338
2016-10-30 09:46:26 +00:00
msgid "Why are default values shared between objects?"
2021-10-27 17:49:12 +00:00
msgstr "Pourquoi les arguments par défaut sont-ils partagés entre les objets ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:340
2016-10-30 09:46:26 +00:00
msgid ""
"This type of bug commonly bites neophyte programmers. Consider this "
"function::"
msgstr ""
2019-06-12 12:29:00 +00:00
"C'est un problème que rencontrent souvent les programmeurs débutants. "
"Examinons la fonction suivante ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:347
2016-10-30 09:46:26 +00:00
msgid ""
"The first time you call this function, ``mydict`` contains a single item. "
"The second time, ``mydict`` contains two items because when ``foo()`` begins "
"executing, ``mydict`` starts out with an item already in it."
msgstr ""
2019-06-12 12:29:00 +00:00
"Au premier appel de cette fonction, ``mydict`` ne contient qu'un seul "
"élément. Au second appel, ``mydict`` contient deux éléments car quand "
"``foo()`` commence son exécution, ``mydict`` contient déjà un élément."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:351
2016-10-30 09:46:26 +00:00
msgid ""
"It is often expected that a function call creates new objects for default "
"values. This is not what happens. Default values are created exactly once, "
"when the function is defined. If that object is changed, like the "
"dictionary in this example, subsequent calls to the function will refer to "
"this changed object."
msgstr ""
"On est souvent amené à croire qu'un appel de fonction créé des nouveaux "
2019-06-12 12:29:00 +00:00
"objets pour les valeurs par défaut. Ce n'est pas le cas. Les valeurs par "
"défaut ne sont créées qu'une et une seule fois, au moment où la fonction est "
"définie. Si l'objet est modifié, comme le dictionnaire dans cet exemple, les "
"appels suivants à cette fonction font référence à l'objet ainsi modifié."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:356
2016-10-30 09:46:26 +00:00
msgid ""
"By definition, immutable objects such as numbers, strings, tuples, and "
"``None``, are safe from change. Changes to mutable objects such as "
"dictionaries, lists, and class instances can lead to confusion."
msgstr ""
2019-06-12 12:29:00 +00:00
"Par définition, les objets immuables comme les nombres, les chaînes de "
"caractères, les *n*-uplets et ``None`` ne sont pas modifiés. Les changements "
2021-05-19 16:06:14 +00:00
"sur des objets modifiables comme les dictionnaires, les listes et les "
"instances de classe peuvent porter à confusion."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:360
2016-10-30 09:46:26 +00:00
msgid ""
"Because of this feature, it is good programming practice to not use mutable "
"objects as default values. Instead, use ``None`` as the default value and "
"inside the function, check if the parameter is ``None`` and create a new "
"list/dictionary/whatever if it is. For example, don't write::"
msgstr ""
2019-06-12 12:29:00 +00:00
"En raison de cette fonctionnalité, il vaut mieux ne pas utiliser d'objets "
2021-05-19 16:06:14 +00:00
"modifiables comme valeurs par défaut. Il vaut mieux utiliser ``None`` comme "
2019-06-12 12:29:00 +00:00
"valeur par défaut et, à l'intérieur de la fonction, vérifier si le paramètre "
"est à ``None`` et créer une nouvelle liste, dictionnaire ou autre, le cas "
"échéant. Par exemple, il ne faut pas écrire ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:368
2016-10-30 09:46:26 +00:00
msgid "but::"
msgstr "mais plutôt ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:374
2016-10-30 09:46:26 +00:00
msgid ""
"This feature can be useful. When you have a function that's time-consuming "
"to compute, a common technique is to cache the parameters and the resulting "
"value of each call to the function, and return the cached value if the same "
"value is requested again. This is called \"memoizing\", and can be "
"implemented like this::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Cette fonctionnalité a une utilité. Il est courant de mettre en cache les "
"paramètres et la valeur de retour de chacun des appels d'une fonction "
"coûteuse à exécuter, et de renvoyer la valeur stockée en cache si le même "
"appel est ré-effectué. C'est la technique dite de « mémoïsation », qui "
"s'implémente de la manière suivante ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:389
2016-10-30 09:46:26 +00:00
msgid ""
"You could use a global variable containing a dictionary instead of the "
"default value; it's a matter of taste."
msgstr ""
2019-06-12 12:29:00 +00:00
"Il est possible d'utiliser une variable globale contenant un dictionnaire à "
2021-10-27 17:49:12 +00:00
"la place de la valeur par défaut ; ce n'est qu'une question de goût."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:394
2016-10-30 09:46:26 +00:00
msgid ""
"How can I pass optional or keyword parameters from one function to another?"
msgstr ""
2021-10-27 17:49:12 +00:00
"Comment passer des paramètres optionnels ou nommés d'une fonction à l'autre ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:396
2016-10-30 09:46:26 +00:00
msgid ""
"Collect the arguments using the ``*`` and ``**`` specifiers in the "
"function's parameter list; this gives you the positional arguments as a "
"tuple and the keyword arguments as a dictionary. You can then pass these "
"arguments when calling another function by using ``*`` and ``**``::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Il faut récupérer les arguments en utilisant les sélecteurs ``*`` et ``**`` "
2021-10-27 17:49:12 +00:00
"dans la liste des paramètres de la fonction ; ceci donne les arguments "
"positionnels sous la forme d'un *n*-uplet et les arguments nommés sous forme "
2019-06-12 12:29:00 +00:00
"de dictionnaire. Ces arguments peuvent être passés à une autre fonction en "
"utilisant ``*`` et ``**`` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:415
2016-10-30 09:46:26 +00:00
msgid "What is the difference between arguments and parameters?"
2021-10-27 17:49:12 +00:00
msgstr "Quelle est la différence entre les arguments et les paramètres ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:417
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
":term:`Parameters <parameter>` are defined by the names that appear in a "
"function definition, whereas :term:`arguments <argument>` are the values "
"actually passed to a function when calling it. Parameters define what :term:"
"`kind of arguments <parameter>` a function can accept. For example, given "
"the function definition::"
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"Les :term:`paramètres <parameter>` sont les noms qui apparaissent dans une "
"définition de fonction, alors que les :term:`arguments <argument>` sont les "
"valeurs qui sont réellement passées à une fonction lors de l'appel de celle-"
"ci. Les paramètres définissent les types des arguments qu'une fonction "
"accepte. Ainsi, avec la définition de fonction suivante ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:426
2016-10-30 09:46:26 +00:00
msgid ""
"*foo*, *bar* and *kwargs* are parameters of ``func``. However, when calling "
"``func``, for example::"
msgstr ""
2019-06-12 12:29:00 +00:00
"*foo*, *bar* et *kwargs* sont des paramètres de ``func``. Mais à l'appel de "
"``func`` avec, par exemple ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:431
2016-10-30 09:46:26 +00:00
msgid "the values ``42``, ``314``, and ``somevar`` are arguments."
2019-06-12 12:29:00 +00:00
msgstr "les valeurs ``42``, ``314``, et ``somevar`` sont des arguments."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:435
2016-10-30 09:46:26 +00:00
msgid "Why did changing list 'y' also change list 'x'?"
2021-10-27 17:49:12 +00:00
msgstr "Pourquoi modifier la liste 'y' modifie aussi la liste 'x' ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:437
2016-10-30 09:46:26 +00:00
msgid "If you wrote code like::"
msgstr "Si vous avez écrit du code comme ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:447
2016-10-30 09:46:26 +00:00
msgid ""
"you might be wondering why appending an element to ``y`` changed ``x`` too."
msgstr ""
2019-06-12 12:29:00 +00:00
"vous vous demandez peut-être pourquoi l'ajout d'un élément à ``y`` a aussi "
"changé ``x``."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:449
2016-10-30 09:46:26 +00:00
msgid "There are two factors that produce this result:"
2021-10-27 17:49:12 +00:00
msgstr "Il y a deux raisons qui conduisent à ce comportement :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:451
2016-10-30 09:46:26 +00:00
msgid ""
"Variables are simply names that refer to objects. Doing ``y = x`` doesn't "
"create a copy of the list -- it creates a new variable ``y`` that refers to "
"the same object ``x`` refers to. This means that there is only one object "
"(the list), and both ``x`` and ``y`` refer to it."
msgstr ""
2019-06-12 12:29:00 +00:00
"Les variables ne sont que des noms qui font référence à des objets. La ligne "
"``y = x`` ne crée pas une copie de la liste — elle crée une nouvelle "
"variable ``y`` qui pointe sur le même objet que ``x``. Ceci signifie qu'il "
"n'existe qu'un seul objet (la liste) auquel ``x`` et ``y`` font référence."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:455
2016-10-30 09:46:26 +00:00
msgid ""
"Lists are :term:`mutable`, which means that you can change their content."
msgstr ""
2019-06-12 12:29:00 +00:00
"Les listes sont des :term:`muable`, ce qui signifie que leur contenu peut "
"être modifié."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:457
2016-10-30 09:46:26 +00:00
msgid ""
"After the call to :meth:`~list.append`, the content of the mutable object "
"has changed from ``[]`` to ``[10]``. Since both the variables refer to the "
"same object, using either name accesses the modified value ``[10]``."
msgstr ""
2019-06-12 12:29:00 +00:00
"Après l'appel de :meth:`~list.append`, le contenu de l'objet muable est "
"passé de ``[]`` à ``[10]``. Vu que les deux variables font référence au même "
"objet, il est possible d'accéder à la valeur modifiée ``[10]`` avec chacun "
"des noms."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:461
2016-10-30 09:46:26 +00:00
msgid "If we instead assign an immutable object to ``x``::"
msgstr "Si au contraire, on affecte un objet immuable à ``x`` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:471
2016-10-30 09:46:26 +00:00
msgid ""
"we can see that in this case ``x`` and ``y`` are not equal anymore. This is "
"because integers are :term:`immutable`, and when we do ``x = x + 1`` we are "
"not mutating the int ``5`` by incrementing its value; instead, we are "
"creating a new object (the int ``6``) and assigning it to ``x`` (that is, "
"changing which object ``x`` refers to). After this assignment we have two "
"objects (the ints ``6`` and ``5``) and two variables that refer to them "
"(``x`` now refers to ``6`` but ``y`` still refers to ``5``)."
msgstr ""
2019-06-12 12:29:00 +00:00
"on observe que ``x`` et ``y`` ne sont ici plus égales. Les entiers sont des "
"immuables (:term:`immutable`), et ``x = x + 1`` ne change pas l'entier ``5`` "
"en incrémentant sa valeur. Au contraire, un nouvel objet est créé (l'entier "
2021-10-27 17:49:12 +00:00
"``6``) et affecté à ``x`` (c'est-à-dire qu'on change l'objet auquel fait "
2019-06-12 12:29:00 +00:00
"référence ``x``). Après cette affectation on a deux objets (les entiers "
"``6`` et ``5``) et deux variables qui font référence à ces deux objets "
"(``x`` fait désormais référence à ``6`` mais ``y`` fait toujours référence à "
"``5``)."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:479
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"Some operations (for example ``y.append(10)`` and ``y.sort()``) mutate the "
"object, whereas superficially similar operations (for example ``y = y + "
"[10]`` and :func:`sorted(y) <sorted>`) create a new object. In general in "
"Python (and in all cases in the standard library) a method that mutates an "
"object will return ``None`` to help avoid getting the two types of "
"operations confused. So if you mistakenly write ``y.sort()`` thinking it "
"will give you a sorted copy of ``y``, you'll instead end up with ``None``, "
"which will likely cause your program to generate an easily diagnosed error."
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"Certaines opérations (par exemple, ``y.append(10)`` et ``y.sort()``) "
"modifient l'objet, alors que des opérations identiques en apparence (par "
"exemple ``y = y + [10]`` et ``sorted(y)``) créent un nouvel objet. En "
"général, en Python, une méthode qui modifie un objet renvoie ``None`` (c'est "
"même systématique dans la bibliothèque standard) pour éviter la confusion "
"entre les deux opérations. Donc écrire par erreur ``y.sort()`` en pensant "
"obtenir une copie triée de ``y`` donne ``None``, ce qui conduit très souvent "
"le programme à générer une erreur facile à diagnostiquer."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:488
2016-10-30 09:46:26 +00:00
msgid ""
"However, there is one class of operations where the same operation sometimes "
"has different behaviors with different types: the augmented assignment "
"operators. For example, ``+=`` mutates lists but not tuples or ints "
"(``a_list += [1, 2, 3]`` is equivalent to ``a_list.extend([1, 2, 3])`` and "
"mutates ``a_list``, whereas ``some_tuple += (1, 2, 3)`` and ``some_int += "
"1`` create new objects)."
msgstr ""
2019-06-12 12:29:00 +00:00
"Il existe cependant une classe d'opérations qui se comporte différemment "
"selon le type : les opérateurs d'affectation incrémentaux. Par exemple, "
"``+=`` modifie les listes mais pas les *n*-uplets ni les entiers (``a_list "
"+= [1, 2, 3]`` équivaut à ``a_list.extend([1, 2, 3])`` et modifie "
"``a_list``, alors que ``some_tuple += (1, 2, 3)`` et ``some_int += 1`` "
"créent de nouveaux objets)."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:495
2016-10-30 09:46:26 +00:00
msgid "In other words:"
2021-10-27 17:49:12 +00:00
msgstr "En d'autres termes :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:497
2016-10-30 09:46:26 +00:00
msgid ""
"If we have a mutable object (:class:`list`, :class:`dict`, :class:`set`, "
"etc.), we can use some specific operations to mutate it and all the "
"variables that refer to it will see the change."
msgstr ""
2019-06-12 12:29:00 +00:00
"Il est possible d'appliquer des opérations qui modifient un objet muable (:"
"class:`list`, :class:`dict`, :class:`set`, etc.) et toutes les variables qui "
"y font référence verront le changement."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:500
2016-10-30 09:46:26 +00:00
msgid ""
"If we have an immutable object (:class:`str`, :class:`int`, :class:`tuple`, "
"etc.), all the variables that refer to it will always see the same value, "
"but operations that transform that value into a new value always return a "
"new object."
msgstr ""
2019-06-12 12:29:00 +00:00
"Toutes les variables qui font référence à un objet immuable (:class:`str`, :"
"class:`int`, :class:`tuple`, etc.) renvoient la même valeur, mais les "
"opérations qui transforment cette valeur en une nouvelle valeur renvoient "
"toujours un nouvel objet."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:505
2016-10-30 09:46:26 +00:00
msgid ""
"If you want to know if two variables refer to the same object or not, you "
"can use the :keyword:`is` operator, or the built-in function :func:`id`."
msgstr ""
2019-06-12 12:29:00 +00:00
"L'opérateur :keyword:`is` ou la fonction native :func:`id` permettent de "
"savoir si deux variables font référence au même objet."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:510
2016-10-30 09:46:26 +00:00
msgid "How do I write a function with output parameters (call by reference)?"
msgstr ""
2021-10-27 17:49:12 +00:00
"Comment écrire une fonction qui modifie ses paramètres ? (passage par "
2019-06-12 12:29:00 +00:00
"référence)"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:512
2016-10-30 09:46:26 +00:00
msgid ""
"Remember that arguments are passed by assignment in Python. Since "
"assignment just creates references to objects, there's no alias between an "
"argument name in the caller and callee, and so no call-by-reference per se. "
"You can achieve the desired effect in a number of ways."
msgstr ""
2019-06-12 12:29:00 +00:00
"En Python, les arguments sont passés comme des affectations de variables. Vu "
"qu'une affectation crée des références à des objets, il n'y a pas de lien "
2019-06-12 12:29:00 +00:00
"entre un argument dans l'appel de la fonction et sa définition, et donc pas "
"de passage par référence en soi. Il y a cependant plusieurs façons d'en "
2019-06-12 12:29:00 +00:00
"émuler un."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:517
2016-10-30 09:46:26 +00:00
msgid "By returning a tuple of the results::"
msgstr "En renvoyant un *n*-uplet de résultats ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:528
2016-10-30 09:46:26 +00:00
msgid "This is almost always the clearest solution."
2019-06-12 12:29:00 +00:00
msgstr "C'est presque toujours la meilleure solution."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:530
2016-10-30 09:46:26 +00:00
msgid ""
"By using global variables. This isn't thread-safe, and is not recommended."
msgstr ""
2019-06-12 12:29:00 +00:00
"En utilisant des variables globales. Cette approche ne fonctionne pas dans "
"des contextes à plusieurs fils d'exécution (elle n'est pas *thread-safe*), "
"et n'est donc pas recommandée."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:532
2016-10-30 09:46:26 +00:00
msgid "By passing a mutable (changeable in-place) object::"
msgstr "En passant un objet muable (modifiable sur place) ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:543
2016-10-30 09:46:26 +00:00
msgid "By passing in a dictionary that gets mutated::"
msgstr "En passant un dictionnaire, qui sera modifié ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:554
2016-10-30 09:46:26 +00:00
msgid "Or bundle up values in a class instance::"
msgstr "Ou regrouper les valeurs dans une instance de classe ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:571
2016-10-30 09:46:26 +00:00
msgid "There's almost never a good reason to get this complicated."
2019-06-12 12:29:00 +00:00
msgstr "Faire quelque chose d'aussi compliqué est rarement une bonne idée."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:573
2016-10-30 09:46:26 +00:00
msgid "Your best choice is to return a tuple containing the multiple results."
msgstr ""
"La meilleure option reste de renvoyer un *n*-uplet contenant les différents "
2016-10-30 09:46:26 +00:00
"résultats."
#: faq/programming.rst:577
2016-10-30 09:46:26 +00:00
msgid "How do you make a higher order function in Python?"
2021-10-27 17:49:12 +00:00
msgstr "Comment construire une fonction d'ordre supérieur en Python ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:579
2016-10-30 09:46:26 +00:00
msgid ""
"You have two choices: you can use nested scopes or you can use callable "
"objects. For example, suppose you wanted to define ``linear(a,b)`` which "
"returns a function ``f(x)`` that computes the value ``a*x+b``. Using nested "
"scopes::"
msgstr ""
2021-10-27 17:49:12 +00:00
"Deux possibilités : on peut utiliser des portées imbriquées ou bien des "
2019-06-12 12:29:00 +00:00
"objets appelables. Par exemple, supposons que l'on souhaite définir "
"``linear(a, b)`` qui renvoie une fonction ``f(x)`` qui calcule la valeur "
"``a*x+b``. En utilisant les portées imbriquées ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:588
2016-10-30 09:46:26 +00:00
msgid "Or using a callable object::"
msgstr "Ou en utilisant un objet appelable ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:598
2016-10-30 09:46:26 +00:00
msgid "In both cases, ::"
msgstr "Dans les deux cas ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:602
2016-10-30 09:46:26 +00:00
msgid "gives a callable object where ``taxes(10e6) == 0.3 * 10e6 + 2``."
msgstr "donne un objet appelable où ``taxes(10e6) == 0.3 * 10e6 + 2``."
#: faq/programming.rst:604
2016-10-30 09:46:26 +00:00
msgid ""
"The callable object approach has the disadvantage that it is a bit slower "
"and results in slightly longer code. However, note that a collection of "
"callables can share their signature via inheritance::"
msgstr ""
"L'approche par objet appelable a le désavantage d'être légèrement plus lente "
"et de produire un code légèrement plus long. Cependant, il faut noter qu'une "
2019-06-12 12:29:00 +00:00
"collection d'objet appelables peuvent partager leurs signatures par "
"héritage ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:613
2016-10-30 09:46:26 +00:00
msgid "Object can encapsulate state for several methods::"
msgstr "Les objets peuvent encapsuler un état pour plusieurs méthodes ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:631
2016-10-30 09:46:26 +00:00
msgid ""
"Here ``inc()``, ``dec()`` and ``reset()`` act like functions which share the "
"same counting variable."
msgstr ""
"Ici ``inc()``, ``dec()`` et ``reset()`` agissent comme des fonctions "
"partageant une même variable compteur."
#: faq/programming.rst:636
2016-10-30 09:46:26 +00:00
msgid "How do I copy an object in Python?"
msgstr "Comment copier un objet en Python ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:638
2016-10-30 09:46:26 +00:00
msgid ""
"In general, try :func:`copy.copy` or :func:`copy.deepcopy` for the general "
"case. Not all objects can be copied, but most can."
msgstr ""
2019-06-12 12:29:00 +00:00
"En général, essayez :func:`copy.copy` ou :func:`copy.deepcopy`. Tous les "
"objets ne peuvent pas être copiés, mais la plupart le peuvent."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:641
2016-10-30 09:46:26 +00:00
msgid ""
"Some objects can be copied more easily. Dictionaries have a :meth:`~dict."
"copy` method::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Certains objets peuvent être copiés plus facilement que d'autres. Les "
"dictionnaires ont une méthode :meth:`~dict.copy` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:646
2016-10-30 09:46:26 +00:00
msgid "Sequences can be copied by slicing::"
msgstr "Les séquences peuvent être copiées via la syntaxe des tranches ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:652
2016-10-30 09:46:26 +00:00
msgid "How can I find the methods or attributes of an object?"
2021-10-27 17:49:12 +00:00
msgstr "Comment récupérer les méthodes ou les attributs d'un objet ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:654
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"For an instance ``x`` of a user-defined class, :func:`dir(x) <dir>` returns "
"an alphabetized list of the names containing the instance attributes and "
2016-10-30 09:46:26 +00:00
"methods and attributes defined by its class."
msgstr ""
"Pour une instance x d'une classe définie par un utilisateur, ``dir(x)`` "
"renvoie une liste alphabétique des noms contenants les attributs de "
"l'instance, et les attributs et méthodes définies par sa classe."
#: faq/programming.rst:660
2016-10-30 09:46:26 +00:00
msgid "How can my code discover the name of an object?"
2021-10-27 17:49:12 +00:00
msgstr "Comment un code peut-il obtenir le nom d'un objet ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:662
2016-10-30 09:46:26 +00:00
msgid ""
"Generally speaking, it can't, because objects don't really have names. "
2019-09-04 09:35:23 +00:00
"Essentially, assignment always binds a name to a value; the same is true of "
2016-10-30 09:46:26 +00:00
"``def`` and ``class`` statements, but in that case the value is a callable. "
"Consider the following code::"
msgstr ""
2019-06-12 12:29:00 +00:00
"C'est impossible en général, parce qu'un objet n'a pas de nom à proprement "
"parler. Schématiquement, l'affectation fait correspondre un nom à une "
"valeur ; c'est vrai aussi pour les instructions ``def`` et ``class``, à la "
2019-06-12 12:29:00 +00:00
"différence près que, dans ce cas, la valeur est un appelable. Par exemple, "
"dans le code suivant ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:678
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"Arguably the class has a name: even though it is bound to two names and "
"invoked through the name ``B`` the created instance is still reported as an "
"instance of class ``A``. However, it is impossible to say whether the "
"instance's name is ``a`` or ``b``, since both names are bound to the same "
"value."
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"Affirmer que la classe a un nom est discutable. Bien qu'elle soit liée à "
"deux noms, et qu'elle soit appelée via le nom B, l'instance créée déclare "
"tout de même être une instance de la classe A. De même, il est impossible de "
"dire si le nom de l'instance est a ou b, les deux noms étant attachés à la "
2016-10-30 09:46:26 +00:00
"même valeur."
#: faq/programming.rst:683
2016-10-30 09:46:26 +00:00
msgid ""
"Generally speaking it should not be necessary for your code to \"know the "
"names\" of particular values. Unless you are deliberately writing "
"introspective programs, this is usually an indication that a change of "
"approach might be beneficial."
msgstr ""
"De façon générale, une application ne devrait pas avoir besoin de "
 connaître le nom » d'une valeur particulière. À moins d'être délibérément "
"en train d'écrire un programme introspectif, c'est souvent l'indication "
"qu'un changement d'approche serait bénéfique."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:688
2016-10-30 09:46:26 +00:00
msgid ""
"In comp.lang.python, Fredrik Lundh once gave an excellent analogy in answer "
"to this question:"
msgstr ""
2018-10-04 15:55:29 +00:00
"Sur *comp.lang.python*, Fredrik Lundh a donné un jour une excellente "
2021-10-27 17:49:12 +00:00
"analogie pour répondre à cette question :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:691
2016-10-30 09:46:26 +00:00
msgid ""
"The same way as you get the name of that cat you found on your porch: the "
"cat (object) itself cannot tell you its name, and it doesn't really care -- "
"so the only way to find out what it's called is to ask all your neighbours "
"(namespaces) if it's their cat (object)..."
msgstr ""
2019-06-12 12:29:00 +00:00
"C'est pareil que trouver le nom du chat qui traîne devant votre porte : le "
"chat (objet) ne peut pas vous dire lui-même son nom, et il s'en moque un peu "
"­ alors le meilleur moyen de savoir comment il s'appelle est de demander à "
"tous vos voisins (espaces de nommage) si c'est leur chat (objet)…"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:696
2016-10-30 09:46:26 +00:00
msgid ""
"....and don't be surprised if you'll find that it's known by many names, or "
"no name at all!"
msgstr ""
2019-06-12 12:29:00 +00:00
"…et ne soyez pas surpris si vous découvrez qu'il est connu sous plusieurs "
2021-10-27 17:49:12 +00:00
"noms, ou s'il n'a pas de nom du tout !"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:701
2016-10-30 09:46:26 +00:00
msgid "What's up with the comma operator's precedence?"
2021-10-27 17:49:12 +00:00
msgstr "Qu'en est-il de la précédence de l'opérateur virgule ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:703
2016-10-30 09:46:26 +00:00
msgid "Comma is not an operator in Python. Consider this session::"
msgstr ""
2019-06-12 12:29:00 +00:00
"La virgule n'est pas un opérateur en Python. Observez le code suivant ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:708
2016-10-30 09:46:26 +00:00
msgid ""
"Since the comma is not an operator, but a separator between expressions the "
"above is evaluated as if you had entered::"
msgstr ""
"Comme la virgule n'est pas un opérateur, mais un séparateur entre deux "
2019-06-12 12:29:00 +00:00
"expressions, l'expression ci-dessus est évaluée de la même façon que si vous "
"aviez écrit ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:713
2016-10-30 09:46:26 +00:00
msgid "not::"
msgstr "et non ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:717
2016-10-30 09:46:26 +00:00
msgid ""
"The same is true of the various assignment operators (``=``, ``+=`` etc). "
"They are not truly operators but syntactic delimiters in assignment "
"statements."
msgstr ""
2019-06-12 12:29:00 +00:00
"Ceci est vrai pour tous les opérateurs d'affectation (``=``, ``+=`` etc). Ce "
"ne sont pas vraiment des opérateurs mais plutôt des délimiteurs syntaxiques "
"dans les instructions d'affectation."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:722
2016-10-30 09:46:26 +00:00
msgid "Is there an equivalent of C's \"?:\" ternary operator?"
2021-10-27 17:49:12 +00:00
msgstr "Existe-t-il un équivalent à l'opérateur ternaire « ?: » du C ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:724
2016-10-30 09:46:26 +00:00
msgid "Yes, there is. The syntax is as follows::"
2019-06-12 12:29:00 +00:00
msgstr "Oui. Sa syntaxe est la suivante ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:731
2016-10-30 09:46:26 +00:00
msgid ""
"Before this syntax was introduced in Python 2.5, a common idiom was to use "
"logical operators::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Avant l'introduction de cette syntaxe dans Python 2.5, il était courant "
"d'utiliser les opérateurs de logique ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:736
2016-10-30 09:46:26 +00:00
msgid ""
"However, this idiom is unsafe, as it can give wrong results when *on_true* "
"has a false boolean value. Therefore, it is always better to use the ``... "
"if ... else ...`` form."
msgstr ""
2019-06-12 12:29:00 +00:00
"Cet idiome est dangereux, car il donne un résultat erroné quand *on_true* a "
"la valeur booléenne fausse. Il faut donc toujours utiliser la forme ``... "
"if ... else ...``."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:742
2016-10-30 09:46:26 +00:00
msgid "Is it possible to write obfuscated one-liners in Python?"
msgstr ""
"Est-il possible d'écrire des programmes obscurcis (*obfuscated*) d'une ligne "
2021-10-27 17:49:12 +00:00
"en Python ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:744
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
2018-12-24 13:20:55 +00:00
"Yes. Usually this is done by nesting :keyword:`lambda` within :keyword:`!"
"lambda`. See the following three examples, slightly adapted from Ulf "
"Bartelt::"
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"Oui. C'est souvent le cas en imbriquant des :keyword:`lambda` dans des :"
"keyword:`!lambda`. Par exemple les trois morceaux de code suivants, créés "
"par Ulf Bartelt ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:771
2016-10-30 09:46:26 +00:00
msgid "Don't try this at home, kids!"
2021-10-27 17:49:12 +00:00
msgstr "Les enfants, ne faites pas ça chez vous !"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:777
2019-03-20 08:41:37 +00:00
msgid "What does the slash(/) in the parameter list of a function mean?"
msgstr ""
2019-06-12 12:29:00 +00:00
"Que signifie la barre oblique (/) dans la liste des paramètres d'une "
2021-10-27 17:49:12 +00:00
"fonction ?"
2019-03-20 08:41:37 +00:00
#: faq/programming.rst:779
#, fuzzy
2019-03-20 08:41:37 +00:00
msgid ""
"A slash in the argument list of a function denotes that the parameters prior "
"to it are positional-only. Positional-only parameters are the ones without "
"an externally usable name. Upon calling a function that accepts positional-"
2019-03-20 08:41:37 +00:00
"only parameters, arguments are mapped to parameters based solely on their "
2019-10-09 16:10:12 +00:00
"position. For example, :func:`divmod` is a function that accepts positional-"
2019-03-20 08:41:37 +00:00
"only parameters. Its documentation looks like this::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Une barre oblique dans la liste des arguments d'une fonction indique que les "
"paramètres la précédant sont uniquement positionnels. Les paramètres "
"uniquement positionnels ne peuvent pas être référencés par leur nom depuis "
"l'extérieur. Lors de l'appel d'une fonction qui accepte des paramètres "
"uniquement positionnels, les arguments sont affectés aux paramètres en "
"fonction de leur position. Par exemple, la fonction :func:`divmod` n'accepte "
2019-06-12 12:29:00 +00:00
"que des paramètres uniquement positionnels. Sa documentation est la "
"suivante ::"
2019-03-20 08:41:37 +00:00
#: faq/programming.rst:792
2019-03-20 08:41:37 +00:00
msgid ""
2019-10-09 16:10:12 +00:00
"The slash at the end of the parameter list means that both parameters are "
"positional-only. Thus, calling :func:`divmod` with keyword arguments would "
2019-03-20 08:41:37 +00:00
"lead to an error::"
msgstr ""
2019-06-12 12:29:00 +00:00
"La barre oblique à la fin de la liste des paramètres signifie que les trois "
"paramètres sont uniquement positionnels. Et donc, appeler :func:`divmod` "
"avec des arguments nommés provoque une erreur ::"
2019-03-20 08:41:37 +00:00
#: faq/programming.rst:803
2016-10-30 09:46:26 +00:00
msgid "Numbers and strings"
msgstr "Nombres et chaînes de caractères"
#: faq/programming.rst:806
2016-10-30 09:46:26 +00:00
msgid "How do I specify hexadecimal and octal integers?"
2021-10-27 17:49:12 +00:00
msgstr "Comment écrire des entiers hexadécimaux ou octaux ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:808
2016-10-30 09:46:26 +00:00
msgid ""
"To specify an octal digit, precede the octal value with a zero, and then a "
"lower or uppercase \"o\". For example, to set the variable \"a\" to the "
"octal value \"10\" (8 in decimal), type::"
msgstr ""
"Pour écrire un entier octal, faites précéder la valeur octale par un zéro, "
2019-06-12 12:29:00 +00:00
"puis un \"o\" majuscule ou minuscule. Par exemple pour affecter la valeur "
"octale \"10\" (8 en décimal) à la variable \"a\", tapez ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:816
2016-10-30 09:46:26 +00:00
msgid ""
"Hexadecimal is just as easy. Simply precede the hexadecimal number with a "
"zero, and then a lower or uppercase \"x\". Hexadecimal digits can be "
"specified in lower or uppercase. For example, in the Python interpreter::"
msgstr ""
2019-06-12 12:29:00 +00:00
"L'hexadécimal est tout aussi simple, faites précéder le nombre hexadécimal "
2016-10-30 09:46:26 +00:00
"par un zéro, puis un \"x\" majuscule ou minuscule. Les nombres hexadécimaux "
"peuvent être écrits en majuscules ou en minuscules. Par exemple, dans "
"l'interpréteur Python ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:829
2016-10-30 09:46:26 +00:00
msgid "Why does -22 // 10 return -3?"
2018-10-04 15:50:29 +00:00
msgstr "Pourquoi ``-22 // 10`` donne-t-il ``-3`` ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:831
2016-10-30 09:46:26 +00:00
msgid ""
"It's primarily driven by the desire that ``i % j`` have the same sign as "
"``j``. If you want that, and also want::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Cela est principalement dû à la volonté que ``i % j`` ait le même signe que "
"j. Si vous voulez en plus que ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:836
2016-10-30 09:46:26 +00:00
msgid ""
"then integer division has to return the floor. C also requires that "
"identity to hold, and then compilers that truncate ``i // j`` need to make "
"``i % j`` have the same sign as ``i``."
msgstr ""
2019-06-12 12:29:00 +00:00
"alors la division entière doit renvoyer l'entier inférieur. Le C impose "
"également que cette égalité soit vérifiée, et donc les compilateurs qui "
2016-10-30 09:46:26 +00:00
"tronquent ``i // j`` ont besoin que ``i % j`` ait le même signe que ``i``."
#: faq/programming.rst:840
2016-10-30 09:46:26 +00:00
msgid ""
"There are few real use cases for ``i % j`` when ``j`` is negative. When "
"``j`` is positive, there are many, and in virtually all of them it's more "
"useful for ``i % j`` to be ``>= 0``. If the clock says 10 now, what did it "
"say 200 hours ago? ``-190 % 12 == 2`` is useful; ``-190 % 12 == -10`` is a "
"bug waiting to bite."
msgstr ""
2019-06-12 12:29:00 +00:00
"Il y a peu de cas d'utilisation réels pour ``i % j`` quand ``j`` est "
"négatif. Quand ``j`` est positif, il y en a beaucoup, et dans pratiquement "
"tous, il est plus utile que ``i % j`` soit ``>=0``. Si l'horloge affiche "
2021-10-27 17:49:12 +00:00
"10 h maintenant, qu'affichait-elle il y a 200 heures ? ``-190 % 12 == 2`` "
"est utile ; ``-190 % 12 == -10`` est un bogue en puissance."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:848
msgid "How do I get int literal attribute instead of SyntaxError?"
msgstr ""
"Pourquoi ai-je une erreur de syntaxe en essayant de lire un attribut d'un "
"entier littéral ?"
#: faq/programming.rst:850
#, fuzzy
msgid ""
"Trying to lookup an ``int`` literal attribute in the normal manner gives a :"
"exc:`SyntaxError` because the period is seen as a decimal point::"
msgstr ""
"Essayer d'utiliser l'opérateur d'accès à un attribut sur un entier littéral "
"conduit à une erreur de syntaxe car le point est compris comme un séparateur "
"décimal en notation anglo-saxonne ::"
#: faq/programming.rst:859
msgid ""
"The solution is to separate the literal from the period with either a space "
"or parentheses."
msgstr ""
"Il faut séparer l'entier du point, soit avec une espace, soit avec des "
"parenthèses."
#: faq/programming.rst:869
2016-10-30 09:46:26 +00:00
msgid "How do I convert a string to a number?"
2021-10-27 17:49:12 +00:00
msgstr "Comment convertir une chaîne de caractères en nombre ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:871
2016-10-30 09:46:26 +00:00
msgid ""
"For integers, use the built-in :func:`int` type constructor, e.g. "
"``int('144') == 144``. Similarly, :func:`float` converts to floating-point, "
"e.g. ``float('144') == 144.0``."
msgstr ""
2019-06-12 12:29:00 +00:00
"Pour les entiers, utilisez le constructeur natif de :func:`int`, par exemple "
"``int('144') == 144``. De façon similaire, :func:`float` donne la valeur "
"flottante, par exemple ``float('144') == 144.0``."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:875
2016-10-30 09:46:26 +00:00
msgid ""
"By default, these interpret the number as decimal, so that ``int('0144') == "
2020-07-20 08:56:42 +00:00
"144`` holds true, and ``int('0x144')`` raises :exc:`ValueError`. "
"``int(string, base)`` takes the base to convert from as a second optional "
"argument, so ``int( '0x144', 16) == 324``. If the base is specified as 0, "
"the number is interpreted using Python's rules: a leading '0o' indicates "
"octal, and '0x' indicates a hex number."
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"Par défaut, ces fonctions interprètent les nombres comme des décimaux, de "
"telle façon que ``int('0144') == 144`` et ``int('0x144')`` lève une :exc:"
"`ValueError`. Le second argument (optionnel) de ``int(string, base)`` est la "
"base dans laquelle convertir, donc ``int('0x144', 16) == 324``. Si la base "
"donnée est 0, le nombre est interprété selon les règles Python : un préfixe "
2019-06-12 12:29:00 +00:00
"``0o`` indique de l'octal et ``0x`` indique de l'hexadécimal."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:882
2016-10-30 09:46:26 +00:00
msgid ""
"Do not use the built-in function :func:`eval` if all you need is to convert "
"strings to numbers. :func:`eval` will be significantly slower and it "
"presents a security risk: someone could pass you a Python expression that "
"might have unwanted side effects. For example, someone could pass "
"``__import__('os').system(\"rm -rf $HOME\")`` which would erase your home "
"directory."
msgstr ""
2019-06-12 12:29:00 +00:00
"N'utilisez pas la fonction native :func:`eval` pour convertir des chaînes de "
"caractères en nombres. :func:`eval` est beaucoup plus lente et pose des "
2021-10-27 17:49:12 +00:00
"problèmes de sécurité : quelqu'un pourrait vous envoyer une expression "
2019-06-12 12:29:00 +00:00
"Python pouvant avoir des effets de bord indésirables. Par exemple, quelqu'un "
"pourrait passer ``__import__('os').system(\"rm -rf $HOME\")`` ce qui "
"effacerait votre répertoire personnel."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:889
2016-10-30 09:46:26 +00:00
msgid ""
":func:`eval` also has the effect of interpreting numbers as Python "
"expressions, so that e.g. ``eval('09')`` gives a syntax error because Python "
"does not allow leading '0' in a decimal number (except '0')."
msgstr ""
":func:`eval` a aussi pour effet d'interpréter les nombres comme des "
2019-06-12 12:29:00 +00:00
"expressions Python. Ainsi ``eval('09')`` produit une erreur de syntaxe, "
"parce que Python ne permet pas les '0' en tête d'un nombre décimal (à "
"l'exception du nombre '0')."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:895
2016-10-30 09:46:26 +00:00
msgid "How do I convert a number to a string?"
2021-10-27 17:49:12 +00:00
msgstr "Comment convertir un nombre en chaîne de caractères ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:897
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"To convert, e.g., the number ``144`` to the string ``'144'``, use the built-"
"in type constructor :func:`str`. If you want a hexadecimal or octal "
"representation, use the built-in functions :func:`hex` or :func:`oct`. For "
"fancy formatting, see the :ref:`f-strings` and :ref:`formatstrings` "
"sections, e.g. ``\"{:04d}\".format(144)`` yields ``'0144'`` and ``\"{:.3f}\"."
2016-10-30 09:46:26 +00:00
"format(1.0/3.0)`` yields ``'0.333'``."
msgstr ""
2019-06-12 12:29:00 +00:00
"Pour transformer, par exemple, le nombre 144 en la chaîne de caractères "
"'144', il faut utiliser la fonction native :func:`str`. Pour obtenir la "
"représentation hexadécimale ou octale, il faut utiliser les fonctions "
"natives :func:`hex` ou :func:`oct`. Pour des représentations non-"
"conventionnelles, se référer aux sections :ref:`f-strings` et :ref:"
"`formatstrings`, par exemple ``\"{:04d}\".format(144)`` produit ``'0144'`` "
"et ``\"{:.3f}\".format(1.0/3.0)`` produit ``'0.333'``."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:906
2016-10-30 09:46:26 +00:00
msgid "How do I modify a string in place?"
2021-10-27 17:49:12 +00:00
msgstr "Comment modifier une chaîne de caractères « sur place » ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:908
2016-10-30 09:46:26 +00:00
msgid ""
"You can't, because strings are immutable. In most situations, you should "
"simply construct a new string from the various parts you want to assemble it "
"from. However, if you need an object with the ability to modify in-place "
"unicode data, try using an :class:`io.StringIO` object or the :mod:`array` "
"module::"
msgstr ""
2019-06-12 12:29:00 +00:00
"C'est impossible car les chaînes de caractères sont immuables. Dans la "
"plupart des cas, il faut tout simplement construire une nouvelle chaîne à "
"partir des morceaux de l'ancienne. Si toutefois vous avez besoin d'un objet "
"capable de modifier de la donnée Unicode « sur place », essayez d'utiliser "
"un objet :class:`io.StringIO` ou le module :mod:`array` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:938
2016-10-30 09:46:26 +00:00
msgid "How do I use strings to call functions/methods?"
msgstr ""
2019-06-12 12:29:00 +00:00
"Comment utiliser des chaînes de caractères pour appeler des fonctions/"
"méthodes ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:940
2016-10-30 09:46:26 +00:00
msgid "There are various techniques."
2019-06-12 12:29:00 +00:00
msgstr "Il y a plusieurs façons de faire."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:942
2016-10-30 09:46:26 +00:00
msgid ""
"The best is to use a dictionary that maps strings to functions. The primary "
"advantage of this technique is that the strings do not need to match the "
"names of the functions. This is also the primary technique used to emulate "
"a case construct::"
msgstr ""
"La meilleure est d'utiliser un dictionnaire qui fait correspondre les "
2019-06-12 12:29:00 +00:00
"chaînes de caractères à des fonctions. Le principal avantage de cette "
"technique est que les chaînes n'ont pas besoin d'être égales aux noms de "
"fonctions. C'est aussi la façon principale d'imiter la construction "
"\"case\" ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:957
2016-10-30 09:46:26 +00:00
msgid "Use the built-in function :func:`getattr`::"
msgstr "Utiliser la fonction :func:`getattr` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:962
2016-10-30 09:46:26 +00:00
msgid ""
"Note that :func:`getattr` works on any object, including classes, class "
"instances, modules, and so on."
msgstr ""
2018-11-13 22:32:17 +00:00
"Notez que :func:`getattr` marche sur n'importe quel objet, ceci inclut les "
2016-10-30 09:46:26 +00:00
"classes, les instances de classes, les modules et ainsi de suite."
#: faq/programming.rst:965
2016-10-30 09:46:26 +00:00
msgid "This is used in several places in the standard library, like this::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Ceci est utilisé à plusieurs reprises dans la bibliothèque standard, de "
"cette façon ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:978
2020-12-18 06:09:57 +00:00
msgid "Use :func:`locals` to resolve the function name::"
msgstr "Utilisez :func:`locals` pour résoudre le nom de la fonction ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:990
2016-10-30 09:46:26 +00:00
msgid ""
"Is there an equivalent to Perl's chomp() for removing trailing newlines from "
"strings?"
msgstr ""
2018-10-04 15:55:29 +00:00
"Existe-t-il un équivalent à la fonction ``chomp()`` de Perl, pour retirer "
2019-06-12 12:29:00 +00:00
"les caractères de fin de ligne d'une chaîne de caractères ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:992
2016-10-30 09:46:26 +00:00
msgid ""
"You can use ``S.rstrip(\"\\r\\n\")`` to remove all occurrences of any line "
"terminator from the end of the string ``S`` without removing other trailing "
"whitespace. If the string ``S`` represents more than one line, with several "
"empty lines at the end, the line terminators for all the blank lines will be "
"removed::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Vous pouvez utiliser ``S.rstrip(\"\\r\\n\")`` pour retirer toutes les "
"occurrences de tout marqueur de fin de ligne à la fin d'une chaîne de "
"caractère ``S``, sans en enlever aucune espace. Si la chaîne ``S`` "
"représente plus d'une ligne, avec plusieurs lignes vides, les marqueurs de "
"fin de ligne de chaque ligne vide seront retirés ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1004
2016-10-30 09:46:26 +00:00
msgid ""
"Since this is typically only desired when reading text one line at a time, "
"using ``S.rstrip()`` this way works well."
msgstr ""
2019-06-12 12:29:00 +00:00
"Vu que cela ne sert presque qu'à lire un texte ligne à ligne, utiliser ``S."
"rstrip()`` de cette manière fonctionne correctement."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1009
2016-10-30 09:46:26 +00:00
msgid "Is there a scanf() or sscanf() equivalent?"
2018-10-04 15:55:29 +00:00
msgstr "Existe-t-il un équivalent à ``scanf()`` ou ``sscanf()`` ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1011
2016-10-30 09:46:26 +00:00
msgid "Not as such."
msgstr "Pas exactement."
#: faq/programming.rst:1013
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"For simple input parsing, the easiest approach is usually to split the line "
"into whitespace-delimited words using the :meth:`~str.split` method of "
"string objects and then convert decimal strings to numeric values using :"
"func:`int` or :func:`float`. :meth:`!split()` supports an optional \"sep\" "
2016-10-30 09:46:26 +00:00
"parameter which is useful if the line uses something other than whitespace "
"as a separator."
msgstr ""
2019-06-12 12:29:00 +00:00
"Pour une simple analyse de chaîne, l'approche la plus simple est "
2016-10-30 09:46:26 +00:00
"généralement de découper la ligne en mots délimités par des espaces, en "
2019-06-12 12:29:00 +00:00
"utilisant la méthode :meth:`~str.split` des objets chaîne de caractères, et "
"ensuite de convertir les chaînes de décimaux en valeurs numériques en "
"utilisant la fonction :func:`int` ou :func:`float`. ``split()`` possède un "
2016-10-30 09:46:26 +00:00
"paramètre optionnel \"sep\" qui est utile si la ligne utilise autre chose "
2019-06-12 12:29:00 +00:00
"que des espaces comme séparateurs."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1019
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"For more complicated input parsing, regular expressions are more powerful "
"than C's ``sscanf`` and better suited for the task."
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"Pour des analyses plus compliquées, les expressions rationnelles sont plus "
2016-10-30 09:46:26 +00:00
"puissantes que la fonction :c:func:`sscanf` de C et mieux adaptées à la "
"tâche."
#: faq/programming.rst:1024
2016-10-30 09:46:26 +00:00
msgid "What does 'UnicodeDecodeError' or 'UnicodeEncodeError' error mean?"
msgstr ""
2018-10-04 15:50:29 +00:00
"Que signifient les erreurs ``UnicodeDecodeError`` ou ``UnicodeEncodeError`` ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1026
2016-10-30 09:46:26 +00:00
msgid "See the :ref:`unicode-howto`."
2019-06-12 12:29:00 +00:00
msgstr "Voir :ref:`unicode-howto`."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1032
msgid "Can I end a raw string with an odd number of backslashes?"
msgstr ""
#: faq/programming.rst:1034
msgid ""
"A raw string ending with an odd number of backslashes will escape the "
"string's quote::"
msgstr ""
#: faq/programming.rst:1042
msgid ""
"There are several workarounds for this. One is to use regular strings and "
"double the backslashes::"
msgstr ""
#: faq/programming.rst:1048
msgid ""
"Another is to concatenate a regular string containing an escaped backslash "
"to the raw string::"
msgstr ""
#: faq/programming.rst:1054
msgid ""
"It is also possible to use :func:`os.path.join` to append a backslash on "
"Windows::"
msgstr ""
#: faq/programming.rst:1059
msgid ""
"Note that while a backslash will \"escape\" a quote for the purposes of "
"determining where the raw string ends, no escaping occurs when interpreting "
"the value of the raw string. That is, the backslash remains present in the "
"value of the raw string::"
msgstr ""
#: faq/programming.rst:1067
msgid "Also see the specification in the :ref:`language reference <strings>`."
msgstr ""
#: faq/programming.rst:1070
2016-10-30 09:46:26 +00:00
msgid "Performance"
2019-06-12 12:29:00 +00:00
msgstr "Performances"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1073
2016-10-30 09:46:26 +00:00
msgid "My program is too slow. How do I speed it up?"
2021-10-27 17:49:12 +00:00
msgstr "Mon programme est trop lent. Comment l'accélérer ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1075
2016-10-30 09:46:26 +00:00
msgid ""
"That's a tough one, in general. First, here are a list of things to "
"remember before diving further:"
msgstr ""
2019-06-12 12:29:00 +00:00
"Question difficile en général. Il faut garder en tête les points suivants "
2021-10-27 17:49:12 +00:00
"avant d'aller plus loin :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1078
2016-10-30 09:46:26 +00:00
msgid ""
"Performance characteristics vary across Python implementations. This FAQ "
2020-02-04 10:14:03 +00:00
"focuses on :term:`CPython`."
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"Les performances varient en fonction des implémentations de Python. Cette "
"FAQ ne traite que de :term:`CPython`."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1080
2016-10-30 09:46:26 +00:00
msgid ""
"Behaviour can vary across operating systems, especially when talking about I/"
"O or multi-threading."
msgstr ""
2019-06-12 12:29:00 +00:00
"Les comportements peuvent différer d'un système d'exploitation à l'autre, "
"tout particulièrement quand il s'agit d'entrée/sortie ou de fils d'exécution "
"multiples."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1082
2016-10-30 09:46:26 +00:00
msgid ""
"You should always find the hot spots in your program *before* attempting to "
"optimize any code (see the :mod:`profile` module)."
msgstr ""
2019-06-12 12:29:00 +00:00
"Il faut toujours essayer de trouver où sont les points de contention d'un "
"programme *avant* d'essayer d'optimiser du code (voir le module :mod:"
"`profile`)."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1084
2016-10-30 09:46:26 +00:00
msgid ""
"Writing benchmark scripts will allow you to iterate quickly when searching "
"for improvements (see the :mod:`timeit` module)."
msgstr ""
2019-06-12 12:29:00 +00:00
"Écrire des scripts d'évaluation de performances permet de progresser "
"rapidement dans la recherche d'améliorations (voir le module :mod:`timeit`)."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1086
2016-10-30 09:46:26 +00:00
msgid ""
"It is highly recommended to have good code coverage (through unit testing or "
"any other technique) before potentially introducing regressions hidden in "
"sophisticated optimizations."
msgstr ""
2019-06-12 12:29:00 +00:00
"Il est très fortement recommandé d'avoir une bonne couverture de code (avec "
"des tests unitaires ou autre) avant d'ajouter des erreurs dans des "
"optimisations sophistiquées."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1090
2016-10-30 09:46:26 +00:00
msgid ""
"That being said, there are many tricks to speed up Python code. Here are "
"some general principles which go a long way towards reaching acceptable "
"performance levels:"
msgstr ""
2019-06-12 12:29:00 +00:00
"Ceci étant dit, il y a beaucoup d'astuces pour accélérer du code Python. "
"Voici quelques principes généraux qui peuvent aider à atteindre des niveaux "
2021-10-27 17:49:12 +00:00
"de performance satisfaisants :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1094
2016-10-30 09:46:26 +00:00
msgid ""
"Making your algorithms faster (or changing to faster ones) can yield much "
"larger benefits than trying to sprinkle micro-optimization tricks all over "
"your code."
msgstr ""
2019-06-12 12:29:00 +00:00
"Améliorer les algorithmes (ou en changer pour des plus performants) peut "
2021-10-27 17:49:12 +00:00
"produire de bien meilleurs résultats que d'optimiser çà et là de petites "
2019-06-12 12:29:00 +00:00
"portions du code."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1098
2016-10-30 09:46:26 +00:00
msgid ""
"Use the right data structures. Study documentation for the :ref:`bltin-"
"types` and the :mod:`collections` module."
msgstr ""
2019-06-12 12:29:00 +00:00
"Utiliser les structures de données adaptées. Se référer à la documentation "
"des :ref:`bltin-types` et du module :mod:`collections`."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1101
2016-10-30 09:46:26 +00:00
msgid ""
"When the standard library provides a primitive for doing something, it is "
"likely (although not guaranteed) to be faster than any alternative you may "
"come up with. This is doubly true for primitives written in C, such as "
"builtins and some extension types. For example, be sure to use either the :"
"meth:`list.sort` built-in method or the related :func:`sorted` function to "
"do sorting (and see the :ref:`sortinghowto` for examples of moderately "
"advanced usage)."
msgstr ""
2019-06-12 12:29:00 +00:00
"Quand la bibliothèque standard fournit une implémentation pour quelque "
"chose, il y a de fortes chances (même si ce n'est pas systématique) que "
2021-10-27 17:49:12 +00:00
"cette implémentation soit plus rapide que la vôtre. C'est d'autant plus vrai "
2019-06-12 12:29:00 +00:00
"pour les routines écrites en C, comme les routines natives et certaines "
"extensions de types. Par exemple, il faut utiliser la méthode native :meth:"
"`list.sort` ou la fonction :func:`sorted` similaire pour classer (et se "
"référer à la section :ref:`sortinghowto` pour des exemples d'utilisation "
"courante)."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1109
2016-10-30 09:46:26 +00:00
msgid ""
"Abstractions tend to create indirections and force the interpreter to work "
"more. If the levels of indirection outweigh the amount of useful work done, "
"your program will be slower. You should avoid excessive abstraction, "
"especially under the form of tiny functions or methods (which are also often "
"detrimental to readability)."
msgstr ""
2019-06-12 12:29:00 +00:00
"Les abstractions ont tendance à créer des indirections et obligent "
"l'interpréteur à faire plus d'efforts. Si le niveau d'indirection dépasse la "
"quantité de travail effectif, le programme sera ralenti. Il faut toujours "
2019-06-12 12:29:00 +00:00
"éviter trop d'indirections, en particulier sous la forme de fonctions ou "
"méthodes trop petites (qui nuisent aussi souvent à la clarté du code)."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1115
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"If you have reached the limit of what pure Python can allow, there are tools "
"to take you further away. For example, `Cython <https://cython.org>`_ can "
2016-10-30 09:46:26 +00:00
"compile a slightly modified version of Python code into a C extension, and "
"can be used on many different platforms. Cython can take advantage of "
"compilation (and optional type annotations) to make your code significantly "
"faster than when interpreted. If you are confident in your C programming "
"skills, you can also :ref:`write a C extension module <extending-index>` "
"yourself."
msgstr ""
"Si vous atteignez les limites de ce que du Python « pur » permet de faire, "
2019-06-12 12:29:00 +00:00
"il y a des outils qui permettent d'aller plus loin. Par exemple, `Cython "
"<http://cython.org>`_ peut compiler une version légèrement modifiée de code "
"Python en une extension C et est disponible sur de nombreuses plate-formes. "
"Cython peut bénéficier de la compilation (et de l'annotation, optionnelle, "
"des types) pour rendre votre code beaucoup plus rapide que s'il était "
"interprété. Si vous avez confiance en vos capacités de programmation en C, "
"vous pouvez aussi :ref:`écrire un module d'extension en C<extending-index>` "
"vous-même."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1125
2016-10-30 09:46:26 +00:00
msgid ""
"The wiki page devoted to `performance tips <https://wiki.python.org/moin/"
"PythonSpeed/PerformanceTips>`_."
msgstr ""
2019-06-12 12:29:00 +00:00
"La page wiki dédiée aux `astuces de performance <https://wiki.python.org/"
"moin/PythonSpeed/PerformanceTips>`_."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1131
2016-10-30 09:46:26 +00:00
msgid "What is the most efficient way to concatenate many strings together?"
msgstr ""
2019-06-12 12:29:00 +00:00
"Quelle est la manière la plus efficace de concaténer un grand nombre de "
2021-10-27 17:49:12 +00:00
"chaînes de caractères ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1133
2016-10-30 09:46:26 +00:00
msgid ""
":class:`str` and :class:`bytes` objects are immutable, therefore "
"concatenating many strings together is inefficient as each concatenation "
"creates a new object. In the general case, the total runtime cost is "
"quadratic in the total string length."
msgstr ""
2019-06-12 12:29:00 +00:00
"Les objets :class:`str` et :class:`bytes` sont immuables, par conséquent "
"concaténer un grand nombre de chaînes de caractères entre elles n'est pas "
"très efficace car chaque concaténation crée un nouvel objet. Dans le cas "
"général, la complexité est quadratique par rapport à la taille totale de la "
"chaîne."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1138
2016-10-30 09:46:26 +00:00
msgid ""
"To accumulate many :class:`str` objects, the recommended idiom is to place "
"them into a list and call :meth:`str.join` at the end::"
msgstr ""
"Pour mettre bout à bout un grand nombre d'objets :class:`str`, la technique "
2019-06-12 12:29:00 +00:00
"recommandée consiste à toutes les mettre dans une liste et appeler la "
"méthode :meth:`str.join` à la fin ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1146
2016-10-30 09:46:26 +00:00
msgid "(another reasonably efficient idiom is to use :class:`io.StringIO`)"
msgstr ""
2019-06-12 12:29:00 +00:00
"(une autre technique relativement efficace consiste à utiliser :class:`io."
"StringIO`)"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1148
2016-10-30 09:46:26 +00:00
msgid ""
"To accumulate many :class:`bytes` objects, the recommended idiom is to "
"extend a :class:`bytearray` object using in-place concatenation (the ``+=`` "
"operator)::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Pour concaténer un grand nombre d'objets :class:`bytes`, la technique "
"recommandée consiste à étendre un objet :class:`bytearray` en utilisant la "
"concaténation en-place (l'opérateur ``+=``) ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1157
2016-10-30 09:46:26 +00:00
msgid "Sequences (Tuples/Lists)"
msgstr "Séquences (*n*-uplets / listes)"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1160
2016-10-30 09:46:26 +00:00
msgid "How do I convert between tuples and lists?"
2021-10-27 17:49:12 +00:00
msgstr "Comment convertir les listes en *n*-uplets et inversement ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1162
2016-10-30 09:46:26 +00:00
msgid ""
"The type constructor ``tuple(seq)`` converts any sequence (actually, any "
"iterable) into a tuple with the same items in the same order."
msgstr ""
2019-06-12 12:29:00 +00:00
"Le constructeur de type ``tuple(seq)`` convertit toute séquence (plus "
"précisément, tout itérable) en un *n*-uplet avec les mêmes éléments dans le "
2019-06-12 12:29:00 +00:00
"même ordre."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1165
2016-10-30 09:46:26 +00:00
msgid ""
"For example, ``tuple([1, 2, 3])`` yields ``(1, 2, 3)`` and ``tuple('abc')`` "
"yields ``('a', 'b', 'c')``. If the argument is a tuple, it does not make a "
"copy but returns the same object, so it is cheap to call :func:`tuple` when "
"you aren't sure that an object is already a tuple."
msgstr ""
2019-06-12 12:29:00 +00:00
"Par exemple ``tuple([1, 2, 3])`` renvoie ``(1, 2, 3)`` et ``tuple('abc')`` "
"renvoie ``('a', 'b', 'c')``. Si l'argument est un *n*-uplet, cela ne crée "
"pas de copie, mais renvoie le même objet, ce qui fait de :func:`tuple` une "
2019-06-12 12:29:00 +00:00
"fonction économique à appeler quand vous ne savez pas si votre objet est "
"déjà un *n*-uplet."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1170
2016-10-30 09:46:26 +00:00
msgid ""
"The type constructor ``list(seq)`` converts any sequence or iterable into a "
"list with the same items in the same order. For example, ``list((1, 2, "
"3))`` yields ``[1, 2, 3]`` and ``list('abc')`` yields ``['a', 'b', 'c']``. "
"If the argument is a list, it makes a copy just like ``seq[:]`` would."
msgstr ""
"Le constructeur de type ``list(seq)`` convertit toute séquence ou itérable "
"en liste contenant les mêmes éléments dans le même ordre. Par exemple, "
"``list((1,2,3))`` renvoie ``[1,2,3]`` et ``list('abc')`` renvoie "
"``['a','b','c']``. Si l'argument est une liste, il renvoie une copie, de la "
2016-10-30 09:46:26 +00:00
"même façon que ``seq[:]``."
#: faq/programming.rst:1177
2016-10-30 09:46:26 +00:00
msgid "What's a negative index?"
2021-10-27 17:49:12 +00:00
msgstr "Qu'est-ce qu'un indice négatif ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1179
2016-10-30 09:46:26 +00:00
msgid ""
"Python sequences are indexed with positive numbers and negative numbers. "
"For positive numbers 0 is the first index 1 is the second index and so "
"forth. For negative indices -1 is the last index and -2 is the penultimate "
"(next to last) index and so forth. Think of ``seq[-n]`` as the same as "
"``seq[len(seq)-n]``."
msgstr ""
2021-10-27 17:49:12 +00:00
"Les séquences Python sont indicées avec des nombres positifs aussi bien que "
2019-06-12 12:29:00 +00:00
"négatifs. Pour les nombres positifs, 0 est le premier indice, 1 est le "
"deuxième, et ainsi de suite. Pour les indices négatifs, ``-1`` est le "
2021-10-27 17:49:12 +00:00
"dernier indice, ``-2`` est le pénultième (avant-dernier), et ainsi de suite. "
2019-06-12 12:29:00 +00:00
"On peut aussi dire que ``seq[-n]`` est équivalent à ``seq[len(seq)-n]``."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1184
2016-10-30 09:46:26 +00:00
msgid ""
"Using negative indices can be very convenient. For example ``S[:-1]`` is "
"all of the string except for its last character, which is useful for "
"removing the trailing newline from a string."
msgstr ""
2019-06-12 12:29:00 +00:00
"Utiliser des indices négatifs peut être très pratique. Par exemple "
"``S[:-1]`` représente la chaîne tout entière à l'exception du dernier "
"caractère, ce qui est pratique pour retirer un caractère de fin de ligne à "
"la fin d'une chaîne."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1190
2016-10-30 09:46:26 +00:00
msgid "How do I iterate over a sequence in reverse order?"
2021-10-27 17:49:12 +00:00
msgstr "Comment itérer à rebours sur une séquence ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1192
2020-12-18 06:09:57 +00:00
msgid "Use the :func:`reversed` built-in function::"
msgstr "Utilisez la fonction native :func:`reversed` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1197
2016-10-30 09:46:26 +00:00
msgid ""
"This won't touch your original sequence, but build a new copy with reversed "
"order to iterate over."
msgstr ""
2019-06-12 12:29:00 +00:00
"Cela ne modifie pas la séquence initiale, mais construit à la place une "
"copie en ordre inverse pour itérer dessus."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1202
2016-10-30 09:46:26 +00:00
msgid "How do you remove duplicates from a list?"
2021-10-27 17:49:12 +00:00
msgstr "Comment retirer les doublons d'une liste ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1204
2016-10-30 09:46:26 +00:00
msgid "See the Python Cookbook for a long discussion of many ways to do this:"
msgstr ""
"Lisez le « livre de recettes » Python pour trouver une longue discussion sur "
2021-10-27 17:49:12 +00:00
"les nombreuses approches possibles :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1206
2016-10-30 09:46:26 +00:00
msgid "https://code.activestate.com/recipes/52560/"
2019-06-12 12:29:00 +00:00
msgstr "https://code.activestate.com/recipes/52560/"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1208
2016-10-30 09:46:26 +00:00
msgid ""
"If you don't mind reordering the list, sort it and then scan from the end of "
"the list, deleting duplicates as you go::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Si changer l'ordre de la liste ne vous dérange pas, commencez par ordonner "
"celle-ci, puis parcourez-la d'un bout à l'autre, en supprimant les doublons "
"trouvés en chemin ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1220
2016-10-30 09:46:26 +00:00
msgid ""
"If all elements of the list may be used as set keys (i.e. they are all :term:"
"`hashable`) this is often faster ::"
2016-10-30 09:46:26 +00:00
msgstr ""
"Si tous les éléments de la liste peuvent être utilisés comme des clés de "
2021-10-27 17:49:12 +00:00
"dictionnaire (c'est-à-dire, qu'elles sont toutes :term:`hachables "
"<hashable>`) ceci est souvent plus rapide ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1225
2016-10-30 09:46:26 +00:00
msgid ""
"This converts the list into a set, thereby removing duplicates, and then "
"back into a list."
msgstr ""
2019-06-12 12:29:00 +00:00
"Ceci convertit la liste en un ensemble, ce qui supprime automatiquement les "
2016-10-30 09:46:26 +00:00
"doublons, puis la transforme à nouveau en liste."
#: faq/programming.rst:1230
2020-10-02 08:55:01 +00:00
msgid "How do you remove multiple items from a list"
msgstr "Comment retirer les doublons d'une liste"
2020-10-02 08:55:01 +00:00
#: faq/programming.rst:1232
2020-10-02 08:55:01 +00:00
msgid ""
"As with removing duplicates, explicitly iterating in reverse with a delete "
"condition is one possibility. However, it is easier and faster to use slice "
"replacement with an implicit or explicit forward iteration. Here are three "
"variations.::"
msgstr ""
"Comme pour supprimer les doublons, il est possible ditérer explicitement à "
"lenvers avec une condition de suppression. Cependant, il est plus facile et "
"plus rapide dutiliser le remplacement des tranches par une itération avant, "
"implicite ou explicite. Voici trois variantes ::"
2020-10-02 08:55:01 +00:00
#: faq/programming.rst:1241
2020-10-16 06:41:36 +00:00
msgid "The list comprehension may be fastest."
msgstr "La liste en compréhension est peut-être la plus rapide ::"
2020-10-02 08:55:01 +00:00
#: faq/programming.rst:1245
2016-10-30 09:46:26 +00:00
msgid "How do you make an array in Python?"
2021-10-27 17:49:12 +00:00
msgstr "Comment construire un tableau en Python ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1247
2016-10-30 09:46:26 +00:00
msgid "Use a list::"
msgstr "Utilisez une liste ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1251
2016-10-30 09:46:26 +00:00
msgid ""
"Lists are equivalent to C or Pascal arrays in their time complexity; the "
"primary difference is that a Python list can contain objects of many "
"different types."
msgstr ""
2021-10-27 17:49:12 +00:00
"Les listes ont un coût équivalent à celui des tableaux C ou Pascal ; la "
2016-10-30 09:46:26 +00:00
"principale différence est qu'une liste Python peut contenir des objets de "
"différents types."
#: faq/programming.rst:1254
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"The ``array`` module also provides methods for creating arrays of fixed "
"types with compact representations, but they are slower to index than "
"lists. Also note that `NumPy <https://numpy.org/>`_ and other third party "
"packages define array-like structures with various characteristics as well."
2016-10-30 09:46:26 +00:00
msgstr ""
"Le module ``array`` fournit des méthodes pour créer des tableaux de types "
"fixes dans une représentation compacte, mais ils sont plus lents à indexer "
"que les listes. Notez aussi que NumPy (et d'autres) fournissent différentes "
"structures de type tableaux, avec des caractéristiques différentes."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1260
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"To get Lisp-style linked lists, you can emulate *cons cells* using tuples::"
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"Pour obtenir des listes chaînées à la sauce Lisp, vous pouvez émuler les "
"*cons cells* en utilisant des *n*-uplets ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1264
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"If mutability is desired, you could use lists instead of tuples. Here the "
"analogue of a Lisp *car* is ``lisp_list[0]`` and the analogue of *cdr* is "
2016-10-30 09:46:26 +00:00
"``lisp_list[1]``. Only do this if you're sure you really need to, because "
"it's usually a lot slower than using Python lists."
msgstr ""
"Si vous voulez pouvoir modifier les éléments, utilisez une liste plutôt "
"qu'un *n*-uplet. Ici la version équivalente du *car* de Lisp est "
2019-06-12 12:29:00 +00:00
"``lisp_list[0]`` et l'équivalent de *cdr* est ``lisp_list[1]``. Ne faites "
"ceci que si vous êtes réellement sûr d'en avoir besoin, cette méthode est en "
"général bien plus lente que les listes Python."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1273
2016-10-30 09:46:26 +00:00
msgid "How do I create a multidimensional list?"
2021-10-27 17:49:12 +00:00
msgstr "Comment créer une liste à plusieurs dimensions ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1275
2016-10-30 09:46:26 +00:00
msgid "You probably tried to make a multidimensional array like this::"
msgstr ""
"Vous avez probablement essayé de créer une liste à plusieurs dimensions de "
"cette façon ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1279
2016-10-30 09:46:26 +00:00
msgid "This looks correct if you print it:"
2021-10-27 17:49:12 +00:00
msgstr "Elle semble correcte si on l'affiche :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1290
2016-10-30 09:46:26 +00:00
msgid "But when you assign a value, it shows up in multiple places:"
msgstr ""
2019-06-12 12:29:00 +00:00
"Mais quand vous affectez une valeur, celle-ci apparaît à plusieurs "
2021-10-27 17:49:12 +00:00
"endroits ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1302
2016-10-30 09:46:26 +00:00
msgid ""
"The reason is that replicating a list with ``*`` doesn't create copies, it "
"only creates references to the existing objects. The ``*3`` creates a list "
"containing 3 references to the same list of length two. Changes to one row "
"will show in all rows, which is almost certainly not what you want."
msgstr ""
2019-06-12 12:29:00 +00:00
"Dupliquer une liste en utilisant ``*`` ne crée en réalité pas de copie mais "
"seulement des références aux objets existants. Le ``*3`` crée une liste "
"contenant trois références à la même liste de longueur deux. Un changement "
"dans une colonne apparaîtra donc dans toutes les colonnes, ce qui n'est très "
"probablement pas ce que vous souhaitiez."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1307
2016-10-30 09:46:26 +00:00
msgid ""
"The suggested approach is to create a list of the desired length first and "
"then fill in each element with a newly created list::"
msgstr ""
2019-06-12 12:29:00 +00:00
"L'approche suggérée est d'abord de créer une liste de la longueur désirée, "
"puis de remplir tous les éléments avec une nouvelle chaîne ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1314
2016-10-30 09:46:26 +00:00
msgid ""
"This generates a list containing 3 different lists of length two. You can "
"also use a list comprehension::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Cela génère une liste contenant elle-même trois listes distinctes, de "
"longueur deux. Vous pouvez aussi utiliser la syntaxe des listes en "
"compréhension ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1320
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"Or, you can use an extension that provides a matrix datatype; `NumPy "
"<https://numpy.org/>`_ is the best known."
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"Vous pouvez aussi utiliser une extension qui fournit un type matriciel "
2021-10-27 17:49:12 +00:00
"natif ; `NumPy <http://www.numpy.org/>`_ est la plus répandue."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1325
#, fuzzy
msgid "How do I apply a method or function to a sequence of objects?"
2021-10-27 17:49:12 +00:00
msgstr "Comment appliquer une méthode à une séquence d'objets ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1327
msgid ""
"To call a method or function and accumulate the return values is a list, a :"
"term:`list comprehension` is an elegant solution::"
msgstr ""
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1334
msgid ""
"To just run the method or function without saving the return values, a "
"plain :keyword:`for` loop will suffice::"
msgstr ""
#: faq/programming.rst:1346
2016-10-30 09:46:26 +00:00
msgid ""
"Why does a_tuple[i] += ['item'] raise an exception when the addition works?"
msgstr ""
"Pourquoi ``a_tuple[i] += ['item']`` lève-t-il une exception alors que "
2021-10-27 17:49:12 +00:00
"l'addition fonctionne ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1348
2016-10-30 09:46:26 +00:00
msgid ""
"This is because of a combination of the fact that augmented assignment "
"operators are *assignment* operators, and the difference between mutable and "
"immutable objects in Python."
msgstr ""
2021-10-27 17:49:12 +00:00
"Ceci est dû à la combinaison de deux facteurs : le fait que les opérateurs "
2019-06-12 12:29:00 +00:00
"d'affectation incrémentaux sont des opérateurs d'*affectation* et à la "
"différence entre les objets muables et immuables en Python."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1352
2016-10-30 09:46:26 +00:00
msgid ""
"This discussion applies in general when augmented assignment operators are "
"applied to elements of a tuple that point to mutable objects, but we'll use "
"a ``list`` and ``+=`` as our exemplar."
msgstr ""
2019-06-12 12:29:00 +00:00
"Cette discussion est valable, en général, quand des opérateurs d'affectation "
"incrémentale sont appliqués aux éléments d'un *n*-uplet qui pointe sur des "
2019-06-12 12:29:00 +00:00
"objets muables, mais on prendra ``list`` et ``+=`` comme exemple."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1356
2016-10-30 09:46:26 +00:00
msgid "If you wrote::"
msgstr "Si vous écrivez ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1364
2016-10-30 09:46:26 +00:00
msgid ""
"The reason for the exception should be immediately clear: ``1`` is added to "
"the object ``a_tuple[0]`` points to (``1``), producing the result object, "
"``2``, but when we attempt to assign the result of the computation, ``2``, "
"to element ``0`` of the tuple, we get an error because we can't change what "
"an element of a tuple points to."
msgstr ""
2021-10-27 17:49:12 +00:00
"La cause de l'exception est claire : ``1`` est ajouté à l'objet "
2019-06-12 12:29:00 +00:00
"``a_tuple[0]`` qui pointe sur (``1``), ce qui produit l'objet résultant "
"``2``, mais, lorsque l'on tente d'affecter le résultat du calcul, ``2``, à "
"l'élément ``0`` du *n*-uplet, on obtient une erreur car il est impossible de "
"modifier la cible sur laquelle pointe un élément d'un *n*-uplet."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1370
2016-10-30 09:46:26 +00:00
msgid ""
"Under the covers, what this augmented assignment statement is doing is "
"approximately this::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Sous le capot, une instruction d'affectation incrémentale fait à peu près "
"ceci ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1379
2016-10-30 09:46:26 +00:00
msgid ""
"It is the assignment part of the operation that produces the error, since a "
"tuple is immutable."
msgstr ""
2019-06-12 12:29:00 +00:00
"C'est la partie de l'affectation de l'opération qui génère l'erreur, vu "
"qu'un *n*-uplet est immuable."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1382
2016-10-30 09:46:26 +00:00
msgid "When you write something like::"
msgstr "Quand vous écrivez un code du style ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1390
2016-10-30 09:46:26 +00:00
msgid ""
"The exception is a bit more surprising, and even more surprising is the fact "
"that even though there was an error, the append worked::"
msgstr ""
2019-06-12 12:29:00 +00:00
"L'exception est un peu plus surprenante et, chose encore plus étrange, "
"malgré l'erreur, l'ajout a fonctionné ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1396
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"To see why this happens, you need to know that (a) if an object implements "
"an :meth:`~object.__iadd__` magic method, it gets called when the ``+=`` "
"augmented assignment is executed, and its return value is what gets used in "
"the assignment statement; and (b) for lists, :meth:`!__iadd__` is equivalent "
"to calling :meth:`~list.extend` on the list and returning the list. That's "
"why we say that for lists, ``+=`` is a \"shorthand\" for :meth:`!list."
"extend`::"
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"Pour comprendre ce qui se passe, il faut savoir que, premièrement, si un "
"objet implémente la méthode magique c, celle-ci est appelée quand "
"l'affectation incrémentale ``+=`` est exécutée et sa valeur de retour est "
2021-10-27 17:49:12 +00:00
"utilisée dans l'instruction d'affectation ; et que, deuxièmement, pour les "
2019-06-12 12:29:00 +00:00
"listes, ``__iadd__`` équivaut à appeler ``extend`` sur la liste et à "
"renvoyer celle-ci. C'est pour cette raison que l'on dit que pour les listes, "
"``+=`` est un \"raccourci\" pour ``list.extend`` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1409
2016-10-30 09:46:26 +00:00
msgid "This is equivalent to::"
msgstr "Cest équivalent à ::"
#: faq/programming.rst:1414
2016-10-30 09:46:26 +00:00
msgid ""
"The object pointed to by a_list has been mutated, and the pointer to the "
"mutated object is assigned back to ``a_list``. The end result of the "
"assignment is a no-op, since it is a pointer to the same object that "
"``a_list`` was previously pointing to, but the assignment still happens."
msgstr ""
2019-06-12 12:29:00 +00:00
"L'objet sur lequel pointe ``a_list`` a été modifié et le pointeur vers "
"l'objet modifié est réaffecté à ``a_list``. *In fine*, l'affectation ne "
"change rien, puisque c'est un pointeur vers le même objet que sur lequel "
"pointait ``a_list``, mais l'affectation a tout de même lieu."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1419
2016-10-30 09:46:26 +00:00
msgid "Thus, in our tuple example what is happening is equivalent to::"
msgstr ""
"Donc, dans notre exemple avec un *n*-uplet, il se passe quelque chose "
"équivalent à ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1427
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"The :meth:`!__iadd__` succeeds, and thus the list is extended, but even "
"though ``result`` points to the same object that ``a_tuple[0]`` already "
"points to, that final assignment still results in an error, because tuples "
"are immutable."
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"L'appel à ``__iadd__`` réussit et la liste est étendue, mais bien que "
"``result`` pointe sur le même objet que ``a_tuple[0]``, l'affectation finale "
"échoue car les *n*-uplets ne sont pas muables."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1433
2016-10-30 09:46:26 +00:00
msgid ""
"I want to do a complicated sort: can you do a Schwartzian Transform in "
"Python?"
msgstr ""
2021-10-27 17:49:12 +00:00
"Je souhaite faire un classement compliqué : peut-on faire une transformation "
"de Schwartz en Python ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1435
2016-10-30 09:46:26 +00:00
msgid ""
"The technique, attributed to Randal Schwartz of the Perl community, sorts "
"the elements of a list by a metric which maps each element to its \"sort "
"value\". In Python, use the ``key`` argument for the :meth:`list.sort` "
"method::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Cette technique, attribuée à Randal Schwartz de la communauté Perl, ordonne "
"les éléments d'une liste à l'aide une transformation qui fait correspondre "
"chaque élément à sa \"valeur de tri\". En Python, ceci est géré par "
"l'argument ``key`` de la méthode :meth:`list.sort` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1444
2016-10-30 09:46:26 +00:00
msgid "How can I sort one list by values from another list?"
2021-10-27 17:49:12 +00:00
msgstr "Comment ordonner une liste en fonction des valeurs d'une autre liste ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1446
2016-10-30 09:46:26 +00:00
msgid ""
"Merge them into an iterator of tuples, sort the resulting list, and then "
"pick out the element you want. ::"
msgstr ""
"Fusionnez-les dans un itérateur de *n*-uplets, ordonnez la liste obtenue, "
"puis choisissez l'élément que vous voulez ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1461
2016-10-30 09:46:26 +00:00
msgid "Objects"
msgstr "Objets"
#: faq/programming.rst:1464
2016-10-30 09:46:26 +00:00
msgid "What is a class?"
msgstr "Qu'est-ce qu'une classe ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1466
2016-10-30 09:46:26 +00:00
msgid ""
"A class is the particular object type created by executing a class "
"statement. Class objects are used as templates to create instance objects, "
"which embody both the data (attributes) and code (methods) specific to a "
"datatype."
msgstr ""
"Une classe est le type d'objet particulier créé par l'exécution d'une "
"déclaration de classe. Les objets de classe sont utilisés comme modèles pour "
"créer des objets, qui incarnent à la fois les données (attributs) et le code "
"(méthodes) spécifiques à un type de données."
#: faq/programming.rst:1470
2016-10-30 09:46:26 +00:00
msgid ""
"A class can be based on one or more other classes, called its base "
"class(es). It then inherits the attributes and methods of its base classes. "
"This allows an object model to be successively refined by inheritance. You "
"might have a generic ``Mailbox`` class that provides basic accessor methods "
"for a mailbox, and subclasses such as ``MboxMailbox``, ``MaildirMailbox``, "
"``OutlookMailbox`` that handle various specific mailbox formats."
msgstr ""
"Une classe peut être fondée sur une ou plusieurs autres classes, appelée sa "
2019-06-12 12:29:00 +00:00
"(ou ses) classe(s) de base. Elle hérite alors des attributs et des méthodes "
"de ses classes mères. Cela permet à un modèle d'objet d'être successivement "
"raffiné par héritage. Vous pourriez avoir une classe générique ``Mailbox``, "
"qui fournit des méthodes d'accès de base pour une boîte aux lettres, et des "
"sous-classes telles que ``MboxMailbox``, ``MaildirMailbox``, "
"``OutlookMailbox`` qui gèrent les plusieurs formats spécifiques de boîtes "
"aux lettres."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1479
2016-10-30 09:46:26 +00:00
msgid "What is a method?"
2021-10-27 17:49:12 +00:00
msgstr "Qu'est-ce qu'une méthode ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1481
2016-10-30 09:46:26 +00:00
msgid ""
"A method is a function on some object ``x`` that you normally call as ``x."
"name(arguments...)``. Methods are defined as functions inside the class "
"definition::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Une méthode est une fonction sur un objet ``x`` qu'on appelle de manière "
"générale sous la forme ``x.name(arguments…)``. Les méthodes sont définies "
"comme des fonctions à l'intérieur de la définition de classe ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1491
2016-10-30 09:46:26 +00:00
msgid "What is self?"
2021-10-27 17:49:12 +00:00
msgstr "Qu'est-ce que self ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1493
2016-10-30 09:46:26 +00:00
msgid ""
"Self is merely a conventional name for the first argument of a method. A "
"method defined as ``meth(self, a, b, c)`` should be called as ``x.meth(a, b, "
"c)`` for some instance ``x`` of the class in which the definition occurs; "
"the called method will think it is called as ``meth(x, a, b, c)``."
msgstr ""
2019-06-12 12:29:00 +00:00
"Par convention, le premier argument d'une méthode est appelé self. Une "
"méthode ``meth(self, a, b, c)`` doit être appelée sous la forme ``x.meth(a, "
"b, c)`` où ``x`` est une instance de la classe dans laquelle cette méthode "
2021-10-27 17:49:12 +00:00
"est définie ; tout se passe comme si la méthode était appelée comme "
2019-06-12 12:29:00 +00:00
"``meth(x, a, b, c)``."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1498
2016-10-30 09:46:26 +00:00
msgid "See also :ref:`why-self`."
msgstr "Voir aussi :ref:`why-self`."
#: faq/programming.rst:1502
2016-10-30 09:46:26 +00:00
msgid ""
"How do I check if an object is an instance of a given class or of a subclass "
"of it?"
msgstr ""
2019-06-12 12:29:00 +00:00
"Comment vérifier si un objet est une instance d'une classe donnée ou d'une "
2021-10-27 17:49:12 +00:00
"sous-classe de celle-ci ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1504
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"Use the built-in function :func:`isinstance(obj, cls) <isinstance>`. You "
"can check if an object is an instance of any of a number of classes by "
"providing a tuple instead of a single class, e.g. ``isinstance(obj, (class1, "
"class2, ...))``, and can also check whether an object is one of Python's "
"built-in types, e.g. ``isinstance(obj, str)`` or ``isinstance(obj, (int, "
"float, complex))``."
2016-10-30 09:46:26 +00:00
msgstr ""
"Utilisez la fonction native ``isinstance(obj, cls)``. Vous pouvez vérifier "
2019-06-12 12:29:00 +00:00
"qu'un objet est une instance de plusieurs classes à la fois en fournissant "
"un *n*-uplet à la place d'une seule classe, par exemple, ``isinstance(obj, "
2019-06-12 12:29:00 +00:00
"(class1, class2, ...))``. Vous pouvez également vérifier qu'un objet est "
"l'un des types natifs de Python, par exemple ``isinstance(obj, str)`` ou "
"``isinstance(obj, (int, float, complex))``."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1511
msgid ""
"Note that :func:`isinstance` also checks for virtual inheritance from an :"
"term:`abstract base class`. So, the test will return ``True`` for a "
"registered class even if hasn't directly or indirectly inherited from it. "
"To test for \"true inheritance\", scan the :term:`MRO` of the class:"
msgstr ""
"Notez que :func:`isinstance` prend aussi en compte l'héritage virtuel d'une :"
"term:`classe mère abstraite <abstract base class>`, c'est à dire qu'elle "
"renvoie ``True`` pour une classe A enregistrée auprès d'une classe mère "
"abstraite B même si A n'est pas directement ou indirectement une classe "
"fille de B. Pour vérifier l'héritage dans le sens plus restreint, parcourez "
"l'\\ :term:`ordre de résolution des méthodes <MRO>` de la classe :"
#: faq/programming.rst:1546
2016-10-30 09:46:26 +00:00
msgid ""
"Note that most programs do not use :func:`isinstance` on user-defined "
"classes very often. If you are developing the classes yourself, a more "
"proper object-oriented style is to define methods on the classes that "
"encapsulate a particular behaviour, instead of checking the object's class "
"and doing a different thing based on what class it is. For example, if you "
"have a function that does something::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Notez que la plupart des programmes n'utilisent que rarement :func:"
"`isInstance` sur les classes définies par l'utilisateur. Si vous développez "
"vous-même des classes, une approche plus orientée-objet consiste définir des "
"méthodes sur les classes qui sont porteuses d'un comportement particulier, "
"plutôt que de vérifier la classe de l'objet et de faire un traitement ad-"
"hoc. Par exemple, si vous avez une fonction qui fait quelque chose ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1560
2016-10-30 09:46:26 +00:00
msgid ""
"A better approach is to define a ``search()`` method on all the classes and "
"just call it::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Une meilleure approche est de définir une méthode ``search()`` dans toutes "
"les classes et qu'il suffit d'appeler de la manière suivante ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1575
2016-10-30 09:46:26 +00:00
msgid "What is delegation?"
2021-10-27 17:49:12 +00:00
msgstr "Qu'est-ce que la délégation ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1577
2016-10-30 09:46:26 +00:00
msgid ""
"Delegation is an object oriented technique (also called a design pattern). "
"Let's say you have an object ``x`` and want to change the behaviour of just "
"one of its methods. You can create a new class that provides a new "
"implementation of the method you're interested in changing and delegates all "
"other methods to the corresponding method of ``x``."
msgstr ""
2019-06-12 12:29:00 +00:00
"La délégation est une technique orientée objet (aussi appelée « patron de "
"conception). Prenons un objet ``x`` dont on souhaite modifier le "
"comportement d'une seule de ses méthodes. On peut créer une nouvelle classe "
"qui fournit une nouvelle implémentation de la méthode qui nous intéresse "
"dans l'évolution et qui délègue toute autre méthode à la méthode "
"correspondante de ``x``."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1583
2016-10-30 09:46:26 +00:00
msgid ""
"Python programmers can easily implement delegation. For example, the "
"following class implements a class that behaves like a file but converts all "
"written data to uppercase::"
msgstr ""
"Les programmeurs Python peuvent facilement mettre en œuvre la délégation. "
"Par exemple, la classe suivante implémente une classe qui se comporte comme "
"un fichier, mais convertit toutes les données écrites en majuscules ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1598
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"Here the ``UpperOut`` class redefines the ``write()`` method to convert the "
2020-05-24 14:31:50 +00:00
"argument string to uppercase before calling the underlying ``self._outfile."
2016-10-30 09:46:26 +00:00
"write()`` method. All other methods are delegated to the underlying ``self."
"_outfile`` object. The delegation is accomplished via the :meth:`~object."
"__getattr__` method; consult :ref:`the language reference <attribute-"
"access>` for more information about controlling attribute access."
2016-10-30 09:46:26 +00:00
msgstr ""
"Ici, la classe ``UpperOut`` redéfinit la méthode ``write()`` pour convertir "
"la chaîne de caractères donnée en argument en majuscules avant d'appeler la "
"méthode sous-jacente ``self._outfile.write()``. Toutes les autres méthodes "
"sont déléguées à l'objet sous-jacent ``self._outfile``. La délégation se "
"fait par la méthode ``__getattr__``, consulter :ref:`the language reference "
"<attribute-access>` pour plus d'informations sur la personnalisation de "
"laccès aux attributs."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1605
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"Note that for more general cases delegation can get trickier. When "
"attributes must be set as well as retrieved, the class must define a :meth:"
"`~object.__setattr__` method too, and it must do so carefully. The basic "
"implementation of :meth:`!__setattr__` is roughly equivalent to the "
2016-10-30 09:46:26 +00:00
"following::"
msgstr ""
"Notez que pour une utilisation plus générale de la délégation, les choses "
"peuvent se compliquer. Lorsque les attributs doivent être définis aussi bien "
"que récupérés, la classe doit définir une méthode :meth:`__setattr__` aussi, "
"et il doit le faire avec soin. La mise en œuvre basique de la méthode :meth:"
"`__setattr__` est à peu près équivalent à ce qui suit ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1616
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"Most :meth:`!__setattr__` implementations must modify :meth:`self.__dict__ "
"<object.__dict__>` to store local state for self without causing an infinite "
"recursion."
2016-10-30 09:46:26 +00:00
msgstr ""
"La plupart des implémentations de :meth:`__setattr__` doivent modifier "
"``self.__dict__`` pour stocker l'état local de self sans provoquer une "
2016-10-30 09:46:26 +00:00
"récursion infinie."
#: faq/programming.rst:1622
2016-10-30 09:46:26 +00:00
msgid ""
"How do I call a method defined in a base class from a derived class that "
"extends it?"
2016-10-30 09:46:26 +00:00
msgstr ""
"Comment appeler une méthode définie dans une classe mère depuis une classe "
"dérivée qui la surcharge ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1624
2016-10-30 09:46:26 +00:00
msgid "Use the built-in :func:`super` function::"
2019-06-12 12:29:00 +00:00
msgstr "Utilisez la fonction native :func:`super` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1630
2016-10-30 09:46:26 +00:00
msgid ""
"In the example, :func:`super` will automatically determine the instance from "
"which it was called (the ``self`` value), look up the :term:`method "
"resolution order` (MRO) with ``type(self).__mro__``, and return the next in "
"line after ``Derived`` in the MRO: ``Base``."
2016-10-30 09:46:26 +00:00
msgstr ""
"Dans cet exemple, :func:`super` détermine automatiquement l'instance dont "
"une méthode l'appelle (l'objet ``self``), observe l'\\ :term:`ordre de "
"résolution des méthodes <method resolution order>` obtenu avec ``type(self)."
"__mro__``, et renvoie la classe qui suit ``Derived`` dans cet ordre, donc "
"``Base``."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1637
2016-10-30 09:46:26 +00:00
msgid "How can I organize my code to make it easier to change the base class?"
msgstr ""
"Comment organiser un code pour permettre de changer la classe mère plus "
2021-10-27 17:49:12 +00:00
"facilement ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1639
2016-10-30 09:46:26 +00:00
msgid ""
2020-12-18 06:09:57 +00:00
"You could assign the base class to an alias and derive from the alias. Then "
"all you have to change is the value assigned to the alias. Incidentally, "
"this trick is also handy if you want to decide dynamically (e.g. depending "
"on availability of resources) which base class to use. Example::"
2016-10-30 09:46:26 +00:00
msgstr ""
"Vous pouvez définir un alias pour la classe mère et dériver depuis l'alias. "
"Ensuite, tout ce que vous devez changer est la valeur attribuée à cet alias. "
"Accessoirement, cette astuce est également utile pour déterminer "
"dynamiquement (par exemple en fonction de la disponibilité de certaines "
"ressources) la classe mère à utiliser. Exemple ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1654
2016-10-30 09:46:26 +00:00
msgid "How do I create static class data and static class methods?"
msgstr ""
2019-06-12 12:29:00 +00:00
"Comment créer des données statiques de classe et des méthodes statiques de "
2021-10-27 17:49:12 +00:00
"classe ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1656
2016-10-30 09:46:26 +00:00
msgid ""
"Both static data and static methods (in the sense of C++ or Java) are "
"supported in Python."
msgstr ""
2019-06-12 12:29:00 +00:00
"Les données statiques et les méthodes statiques (au sens C++ ou Java) sont "
"prises en charge en Python."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1659
2016-10-30 09:46:26 +00:00
msgid ""
"For static data, simply define a class attribute. To assign a new value to "
"the attribute, you have to explicitly use the class name in the assignment::"
msgstr ""
"Pour les données statiques, il suffit de définir un attribut de classe. Pour "
"attribuer une nouvelle valeur à l'attribut, vous devez explicitement "
"utiliser le nom de classe dans l'affectation ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1671
2016-10-30 09:46:26 +00:00
msgid ""
"``c.count`` also refers to ``C.count`` for any ``c`` such that "
"``isinstance(c, C)`` holds, unless overridden by ``c`` itself or by some "
"class on the base-class search path from ``c.__class__`` back to ``C``."
msgstr ""
2019-06-12 12:29:00 +00:00
"``c.count`` se réfère également à ``C.count`` pour tout ``c`` tel que "
2016-10-30 09:46:26 +00:00
"``isInstance (c, C)`` est vrai, sauf remplacement par ``c`` lui-même ou par "
"une classe sur le chemin de recherche de classe mère de ``c.__class__`` "
2016-10-30 09:46:26 +00:00
"jusqu'à ``C``."
#: faq/programming.rst:1675
2016-10-30 09:46:26 +00:00
msgid ""
"Caution: within a method of C, an assignment like ``self.count = 42`` "
"creates a new and unrelated instance named \"count\" in ``self``'s own "
"dict. Rebinding of a class-static data name must always specify the class "
"whether inside a method or not::"
msgstr ""
2021-10-27 17:49:12 +00:00
"Attention : dans une méthode de C, une affectation comme ``self.count = 42`` "
2019-06-12 12:29:00 +00:00
"crée une nouvelle instance sans rapport avec le nom ``count`` dans le "
"dictionnaire de données de ``self``. La redéfinition d'une donnée statique "
"de classe doit toujours spécifier la classe, que l'on soit à l'intérieur "
"d'une méthode ou non ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1682
2016-10-30 09:46:26 +00:00
msgid "Static methods are possible::"
2019-06-12 12:29:00 +00:00
msgstr "Il est possible d'utiliser des méthodes statiques ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1690
2016-10-30 09:46:26 +00:00
msgid ""
"However, a far more straightforward way to get the effect of a static method "
"is via a simple module-level function::"
msgstr ""
"Cependant, d'une manière beaucoup plus simple pour obtenir l'effet d'une "
"méthode statique se fait par une simple fonction au niveau du module ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1696
2016-10-30 09:46:26 +00:00
msgid ""
"If your code is structured so as to define one class (or tightly related "
"class hierarchy) per module, this supplies the desired encapsulation."
msgstr ""
"Si votre code est structuré de manière à définir une classe (ou bien la "
"hiérarchie des classes connexes) par module, ceci fournira l'encapsulation "
"souhaitée."
#: faq/programming.rst:1701
2016-10-30 09:46:26 +00:00
msgid "How can I overload constructors (or methods) in Python?"
2021-10-27 17:49:12 +00:00
msgstr "Comment surcharger les constructeurs (ou méthodes) en Python ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1703
2016-10-30 09:46:26 +00:00
msgid ""
"This answer actually applies to all methods, but the question usually comes "
"up first in the context of constructors."
msgstr ""
2019-06-12 12:29:00 +00:00
"Cette réponse s'applique en fait à toutes les méthodes, mais la question se "
"pose généralement dans le contexte des constructeurs."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1706
2016-10-30 09:46:26 +00:00
msgid "In C++ you'd write"
msgstr "En C++, on écrirait"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1715
2016-10-30 09:46:26 +00:00
msgid ""
"In Python you have to write a single constructor that catches all cases "
"using default arguments. For example::"
msgstr ""
"En Python, vous devez écrire un constructeur unique qui considère tous les "
"cas en utilisant des arguments par défaut. Par exemple ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1725
2016-10-30 09:46:26 +00:00
msgid "This is not entirely equivalent, but close enough in practice."
msgstr ""
"Ce n'est pas tout à fait équivalent, mais suffisamment proche dans la "
"pratique."
#: faq/programming.rst:1727
2016-10-30 09:46:26 +00:00
msgid "You could also try a variable-length argument list, e.g. ::"
msgstr ""
"Vous pouvez aussi utiliser une liste d'arguments de longueur variable, par "
"exemple ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1732
2016-10-30 09:46:26 +00:00
msgid "The same approach works for all method definitions."
msgstr "La même approche fonctionne pour toutes les définitions de méthode."
#: faq/programming.rst:1736
2016-10-30 09:46:26 +00:00
msgid "I try to use __spam and I get an error about _SomeClassName__spam."
msgstr ""
2018-10-04 15:50:29 +00:00
"J'essaie d'utiliser ``__spam`` et j'obtiens une erreur à propos de "
"``_SomeClassName__spam``."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1738
2016-10-30 09:46:26 +00:00
msgid ""
"Variable names with double leading underscores are \"mangled\" to provide a "
"simple but effective way to define class private variables. Any identifier "
"of the form ``__spam`` (at least two leading underscores, at most one "
"trailing underscore) is textually replaced with ``_classname__spam``, where "
"``classname`` is the current class name with any leading underscores "
"stripped."
msgstr ""
"Les noms de variables commençant avec deux tirets bas sont « déformés », "
2019-06-12 12:29:00 +00:00
"c'est un moyen simple mais efficace de définir des variables privées à une "
"classe. Tout identifiant de la forme ``__spam`` (commençant par au moins "
"deux tirets bas et se terminant par au plus un tiret bas) est textuellement "
"remplacé par ``_classname__spam``, où ``classname`` est le nom de la classe "
"en cours sans les éventuels tirets bas du début."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1744
2016-10-30 09:46:26 +00:00
msgid ""
"This doesn't guarantee privacy: an outside user can still deliberately "
"access the \"_classname__spam\" attribute, and private values are visible in "
"the object's ``__dict__``. Many Python programmers never bother to use "
"private variable names at all."
msgstr ""
2021-10-27 17:49:12 +00:00
"Cela ne garantit aucune protection : un utilisateur extérieur peut encore "
2019-06-12 12:29:00 +00:00
"délibérément accéder à l'attribut ``_classname__spam`` et les valeurs "
"privées sont visibles dans l'objet ``__dict__``. De nombreux programmeurs "
"Python ne prennent jamais la peine d'utiliser des noms de variable privés."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1751
2016-10-30 09:46:26 +00:00
msgid "My class defines __del__ but it is not called when I delete the object."
msgstr ""
2019-06-12 12:29:00 +00:00
"Ma classe définit ``__del__`` mais elle n'est pas appelée lorsque je "
"supprime l'objet."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1753
2016-10-30 09:46:26 +00:00
msgid "There are several possible reasons for this."
2019-06-12 12:29:00 +00:00
msgstr "Il y a plusieurs explications possibles."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1755
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"The :keyword:`del` statement does not necessarily call :meth:`~object."
"__del__` -- it simply decrements the object's reference count, and if this "
"reaches zero :meth:`!__del__` is called."
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"La commande *del* n'appelle pas forcément :meth:`__del__` — elle décrémente "
"simplement le compteur de références de l'objet et, si celui-ci arrive à "
"zéro, :meth:`__del__` est appelée."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1759
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"If your data structures contain circular links (e.g. a tree where each child "
"has a parent reference and each parent has a list of children) the reference "
"counts will never go back to zero. Once in a while Python runs an algorithm "
"to detect such cycles, but the garbage collector might run some time after "
"the last reference to your data structure vanishes, so your :meth:`!__del__` "
2016-10-30 09:46:26 +00:00
"method may be called at an inconvenient and random time. This is "
"inconvenient if you're trying to reproduce a problem. Worse, the order in "
"which object's :meth:`!__del__` methods are executed is arbitrary. You can "
2016-10-30 09:46:26 +00:00
"run :func:`gc.collect` to force a collection, but there *are* pathological "
"cases where objects will never be collected."
msgstr ""
"Si la structure de données contient des références circulaires (par exemple "
"un arbre dans lequel chaque fils référence son père, et chaque père garde "
"une liste de ses fils), le compteur de références n'arrivera jamais à zéro. "
2019-06-12 12:29:00 +00:00
"Python exécute périodiquement un algorithme pour détecter ce genre de "
"cycles, mais il peut se passer un certain temps entre le moment où la "
"structure est référencée pour la dernière fois et l'appel du ramasse-"
"miettes, donc la méthode :meth:`__del__` peut être appelée à un moment "
"aléatoire et pas opportun. C'est gênant pour essayer reproduire un problème. "
"Pire, l'ordre dans lequel les méthodes :meth:`__del__` des objets sont "
"appelées est arbitraire. Il est possible de forcer l'appel du ramasse-"
"miettes avec la fonction :func:`gc.collect`, mais il existe certains cas où "
"les objets ne seront jamais nettoyés."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1770
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"Despite the cycle collector, it's still a good idea to define an explicit "
"``close()`` method on objects to be called whenever you're done with them. "
2017-09-12 11:40:22 +00:00
"The ``close()`` method can then remove attributes that refer to subobjects. "
"Don't call :meth:`!__del__` directly -- :meth:`!__del__` should call "
2016-10-30 09:46:26 +00:00
"``close()`` and ``close()`` should make sure that it can be called more than "
"once for the same object."
msgstr ""
2019-06-12 12:29:00 +00:00
"Bien que le ramasse-miette de cycles existe, il est tout de même recommandé "
"de définir une méthode ``close()`` explicite sur des objets, et de l'appeler "
"quand leur cycle de vie s'achève. Cette méthode ``close()`` peut alors "
"supprimer les attributs qui référencent des sous-objets. Il vaut mieux ne "
"pas appeler la méthode :meth:`__del__` directement, mais la méthode :meth:"
"`__del__` devrait appeler la méthode ``close()`` et ``close()`` doit pouvoir "
2019-06-12 12:29:00 +00:00
"être appelée plusieurs fois sur le même objet."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1777
2016-10-30 09:46:26 +00:00
msgid ""
"Another way to avoid cyclical references is to use the :mod:`weakref` "
"module, which allows you to point to objects without incrementing their "
"reference count. Tree data structures, for instance, should use weak "
"references for their parent and sibling references (if they need them!)."
msgstr ""
2019-06-12 12:29:00 +00:00
"Une alternative pour éviter les références cycliques consiste à utiliser le "
"module :mod:`weakref`, qui permet de faire référence à des objets sans "
"incrémenter leur compteur de références. Par exemple, les structures "
"d'arbres devraient utiliser des références faibles entre pères et fils (si "
2021-10-27 17:49:12 +00:00
"nécessaire !)."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1790
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"Finally, if your :meth:`!__del__` method raises an exception, a warning "
2016-10-30 09:46:26 +00:00
"message is printed to :data:`sys.stderr`."
msgstr ""
2019-06-12 12:29:00 +00:00
"Enfin, si la méthode :meth:`__del__` lève une exception, un message "
"d'avertissement s'affiche dans :data:`sys.stderr`."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1795
2016-10-30 09:46:26 +00:00
msgid "How do I get a list of all instances of a given class?"
2021-10-27 17:49:12 +00:00
msgstr "Comment obtenir toutes les instances d'une classe ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1797
2016-10-30 09:46:26 +00:00
msgid ""
"Python does not keep track of all instances of a class (or of a built-in "
"type). You can program the class's constructor to keep track of all "
"instances by keeping a list of weak references to each instance."
msgstr ""
2019-06-12 12:29:00 +00:00
"Python ne tient pas de registre de toutes les instances d'une classe (ni de "
"n'importe quel type natif). Il est cependant possible de programmer le "
"constructeur de la classe de façon à tenir un tel registre, en maintenant "
"une liste de références faibles vers chaque instance."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1803
2016-10-30 09:46:26 +00:00
msgid "Why does the result of ``id()`` appear to be not unique?"
msgstr ""
2019-06-12 12:29:00 +00:00
"Pourquoi le résultat de ``id()`` peut-il être le même pour deux objets "
2021-10-27 17:49:12 +00:00
"différents ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1805
2016-10-30 09:46:26 +00:00
msgid ""
"The :func:`id` builtin returns an integer that is guaranteed to be unique "
"during the lifetime of the object. Since in CPython, this is the object's "
"memory address, it happens frequently that after an object is deleted from "
"memory, the next freshly created object is allocated at the same position in "
"memory. This is illustrated by this example:"
msgstr ""
2019-06-12 12:29:00 +00:00
"La fonction native :func:`id` renvoie un entier dont l'unicité est garantie "
"durant toute la vie de l'objet. Vu qu'en CPython cet entier est en réalité "
"l'adresse mémoire de l'objet, il est fréquent qu'un nouvel objet soit alloué "
"à une adresse mémoire identique à celle d'un objet venant d'être supprimé. "
2021-10-27 17:49:12 +00:00
"Comme l'illustre le code suivant :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1816
2016-10-30 09:46:26 +00:00
msgid ""
"The two ids belong to different integer objects that are created before, and "
"deleted immediately after execution of the ``id()`` call. To be sure that "
"objects whose id you want to examine are still alive, create another "
"reference to the object:"
msgstr ""
2019-06-12 12:29:00 +00:00
"Les deux identifiants appartiennent à des objets entiers créés juste avant "
"l'appel à ``id()`` et détruits immédiatement après. Pour s'assurer que les "
"objets dont on veut examiner les identifiants sont toujours en vie, créons "
2021-10-27 17:49:12 +00:00
"une nouvelle référence à l'objet :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:1829
msgid "When can I rely on identity tests with the *is* operator?"
msgstr "Quand puis-je raisonnablement utiliser le test d'identité *is* ?"
#: faq/programming.rst:1831
msgid ""
"The ``is`` operator tests for object identity. The test ``a is b`` is "
"equivalent to ``id(a) == id(b)``."
msgstr ""
2021-10-27 17:49:12 +00:00
"L'opérateur ``is`` détermine si deux objets sont identiques, c'est-à-dire le "
"même objet. Le test ``a is b`` est équivalent à ``id(a) == id(b)``."
#: faq/programming.rst:1834
msgid ""
"The most important property of an identity test is that an object is always "
"identical to itself, ``a is a`` always returns ``True``. Identity tests are "
"usually faster than equality tests. And unlike equality tests, identity "
"tests are guaranteed to return a boolean ``True`` or ``False``."
msgstr ""
"La propriété la plus importante du test d'identité est qu'un objet est "
2021-10-27 17:49:12 +00:00
"toujours identique à lui-même. Quelle que soit la valeur de *a*, ``a is a`` "
"vaut toujours ``True``. Un test d'identité est généralement plus rapide "
"qu'un test d'égalité. De plus, contrairement à l'opérateur ``==``, "
"l'opérateur ``is`` renvoie toujours un booléen, ``True`` ou ``False``."
#: faq/programming.rst:1839
msgid ""
"However, identity tests can *only* be substituted for equality tests when "
"object identity is assured. Generally, there are three circumstances where "
"identity is guaranteed:"
msgstr ""
"Cependant, les tests d'identité ne peuvent remplacer les tests d'égalité que "
"si l'identité est garantie. C'est le cas dans les trois situations "
"suivantes :"
#: faq/programming.rst:1843
msgid ""
"1) Assignments create new names but do not change object identity. After "
"the assignment ``new = old``, it is guaranteed that ``new is old``."
msgstr ""
"1) Les affectations créent de nouvelles variables, mais pas de nouveaux "
2021-10-27 17:49:12 +00:00
"objets. Après l'affectation ``nouveau = ancien``, ``nouveau is ancien`` vaut "
"toujours ``True``."
#: faq/programming.rst:1846
msgid ""
"2) Putting an object in a container that stores object references does not "
"change object identity. After the list assignment ``s[0] = x``, it is "
"guaranteed that ``s[0] is x``."
msgstr ""
"Le stockage d'un objet dans un conteneur qui fonctionne avec des références "
"n'altère pas l'identité. Si ``s`` est une liste, alors après l'affectation "
"de *x* à l'indice 0, ``s[0] = x``, le test ``s[0] is x`` s'évalue forcément "
"à ``True``."
#: faq/programming.rst:1850
msgid ""
"3) If an object is a singleton, it means that only one instance of that "
"object can exist. After the assignments ``a = None`` and ``b = None``, it "
"is guaranteed that ``a is b`` because ``None`` is a singleton."
msgstr ""
"3) Les singletons sont des objets spéciaux qui ne sont jamais dupliqués. "
"Après les affectations ``a = None`` et ``b = None``, on a forcément ``a is "
"b``, puisque ``None`` est un singleton."
#: faq/programming.rst:1854
msgid ""
"In most other circumstances, identity tests are inadvisable and equality "
"tests are preferred. In particular, identity tests should not be used to "
"check constants such as :class:`int` and :class:`str` which aren't "
"guaranteed to be singletons::"
msgstr ""
"Dans la plupart des autres cas, un test d'identité n'est pas approprié par "
"rapport à un test d'égalité. En particulier, il ne faut pas utiliser ``is`` "
"pour comparer à des constantes comme les entiers (type :class:`int`) ou des "
"chaînes de caractères (type :class:`str`) car ces valeurs ne sont pas "
2021-10-27 17:49:12 +00:00
"nécessairement des singletons ::"
#: faq/programming.rst:1871
msgid "Likewise, new instances of mutable containers are never identical::"
msgstr ""
"De même, deux instances fraîchement créées d'un type de conteneurs muables "
2021-10-27 17:49:12 +00:00
"ne sont jamais identiques ::"
#: faq/programming.rst:1878
msgid ""
"In the standard library code, you will see several common patterns for "
"correctly using identity tests:"
msgstr ""
"Voici quelques exemples de la bibliothèque standard qui illustrent comment "
"utiliser correctement les tests d'identité dans certaines situations "
"particulières :"
#: faq/programming.rst:1881
msgid ""
"1) As recommended by :pep:`8`, an identity test is the preferred way to "
"check for ``None``. This reads like plain English in code and avoids "
"confusion with other objects that may have boolean values that evaluate to "
"false."
msgstr ""
"1) Comme recommandé par la :pep:`8`, il est préférable de comparer avec "
"``None`` par identité. Le test se lit comme de la prose anglaise (``x is "
"None``, ``x is not None``), et cela évite des surprises avec les objets dont "
"la valeur booléenne est ``False``."
#: faq/programming.rst:1885
msgid ""
"2) Detecting optional arguments can be tricky when ``None`` is a valid input "
2022-03-23 17:40:12 +00:00
"value. In those situations, you can create a singleton sentinel object "
"guaranteed to be distinct from other objects. For example, here is how to "
"implement a method that behaves like :meth:`dict.pop`::"
msgstr ""
"2) Savoir si un paramètre facultatif a été passé ou pas peut nécessiter un "
"peu de subtilité lorsque ``None`` est une valeur acceptable pour le "
"paramètre. Dans ces cas, il faut créer un objet singleton dit "
 sentinelle », distinct de toute valeur acceptable. Voici par exemple "
"comment écrire une méthode qui émule :meth:`dict.pop` ::"
#: faq/programming.rst:1901
msgid ""
"3) Container implementations sometimes need to augment equality tests with "
"identity tests. This prevents the code from being confused by objects such "
"as ``float('NaN')`` that are not equal to themselves."
msgstr ""
"3) Il arrive que l'implémentation d'un type de conteneurs doive ajouter des "
"tests d'identité aux tests d'égalité, ceci afin d'éviter un comportement non "
"souhaité avec les objets comme ``float('NaN')`` qui ne sont pas égaux à eux-"
"mêmes."
#: faq/programming.rst:1905
msgid ""
"For example, here is the implementation of :meth:`collections.abc.Sequence."
"__contains__`::"
msgstr ""
"Par exemple, l'implémentation de :meth:`collections.abc.Sequence."
2021-10-27 17:49:12 +00:00
"__contains__` est ::"
#: faq/programming.rst:1916
msgid ""
"How can a subclass control what data is stored in an immutable instance?"
msgstr ""
"Comment définir dans une classe fille les attributs d'une instance immuable ?"
#: faq/programming.rst:1918
#, fuzzy
msgid ""
"When subclassing an immutable type, override the :meth:`~object.__new__` "
"method instead of the :meth:`~object.__init__` method. The latter only runs "
"*after* an instance is created, which is too late to alter data in an "
"immutable instance."
msgstr ""
"Lorsque l'on crée une classe héritant d'une classe d'objets immuables, il "
"faut remplacer la méthode :meth:`__new__`, et non pas la méthode :meth:"
"`__init__`. En effet, cette dernière est exécutée seulement après que "
"l'instance soit créée, donc il y est trop tard pour modifier le contenu "
"d'une instance si elle est immuable."
#: faq/programming.rst:1923
msgid ""
"All of these immutable classes have a different signature than their parent "
"class:"
msgstr ""
"Toutes les classes d'objets immuables suivantes ont des signatures de "
"constructeur différentes de leur classe mère :"
#: faq/programming.rst:1949
msgid "The classes can be used like this:"
msgstr "Ces classes s'utilisent comme ceci :"
#: faq/programming.rst:1966
msgid "How do I cache method calls?"
msgstr "Comment mettre en cache le résultat d'une méthode ?"
#: faq/programming.rst:1968
msgid ""
"The two principal tools for caching methods are :func:`functools."
"cached_property` and :func:`functools.lru_cache`. The former stores results "
"at the instance level and the latter at the class level."
msgstr ""
"Il existe deux outils principaux pour mettre en cache la valeur de retour "
"d'une méthode, à savoir :func:`functools.cached_property`, qui stocke les "
"valeurs au niveau de l'instance, et :func:`functools.lru_cache`, qui le fait "
"au niveau de la classe."
#: faq/programming.rst:1973
msgid ""
"The *cached_property* approach only works with methods that do not take any "
"arguments. It does not create a reference to the instance. The cached "
"method result will be kept only as long as the instance is alive."
msgstr ""
"La fonction ``cached_property`` n'est applicable qu'aux méthodes sans "
2021-10-27 17:49:12 +00:00
"argument. Elle n'induit aucune référence vers l'instance. Le cache est "
"simplement conservé aussi longtemps que l'instance elle-même."
#: faq/programming.rst:1977
msgid ""
2022-03-23 17:40:12 +00:00
"The advantage is that when an instance is no longer used, the cached method "
"result will be released right away. The disadvantage is that if instances "
"accumulate, so too will the accumulated method results. They can grow "
"without bound."
msgstr ""
"L'avantage est que le cache est supprimé aussitôt que l'instance est "
"détruite. L'inconvénient est que les caches peuvent s'accumuler avec les "
"instances, sans limite de nombre."
#: faq/programming.rst:1982
msgid ""
"The *lru_cache* approach works with methods that have hashable arguments. "
"It creates a reference to the instance unless special efforts are made to "
"pass in weak references."
msgstr ""
"La fonction ``lru_cache`` s'applique quant à elle aux méthodes dont les "
"arguments sont hachables. Elle crée une référence forte à l'instance, sauf à "
"passer par des circonvolutions pour que la référence soit faible."
#: faq/programming.rst:1986
msgid ""
"The advantage of the least recently used algorithm is that the cache is "
"bounded by the specified *maxsize*. The disadvantage is that instances are "
"kept alive until they age out of the cache or until the cache is cleared."
msgstr ""
"L'avantage de l'algorithme LRU est d'offrir une limitation sur la taille du "
2021-10-27 17:49:12 +00:00
"cache, que l'on peut régler avec le paramètre *maxsize* (NdT : LRU signifie "
"*Least Recently Used* en anglais, les entrées du cache les plus anciennes "
"sont évincées pour conserver la taille). L'inconvénient est qu'une référence "
"forte vers l'instance est conservée dans le cache, ce qui maintient "
"l'instance hors de portée du ramasse-miettes jusqu'à ce que l'entrée soit "
"effacée du cache ou que le cache soit remis à zéro."
#: faq/programming.rst:1991
msgid "This example shows the various techniques::"
2021-10-27 17:49:12 +00:00
msgstr "Voici une démonstration des différentes techniques ::"
#: faq/programming.rst:2015
msgid ""
"The above example assumes that the *station_id* never changes. If the "
"relevant instance attributes are mutable, the *cached_property* approach "
"can't be made to work because it cannot detect changes to the attributes."
msgstr ""
"Cet exemple suppose que l'attribut *station_id* n'est jamais changé. Si les "
2021-10-27 17:49:12 +00:00
"attributs utilisés par la méthode sont susceptibles d'être modifiés, "
"``cached_property`` ne peut pas fonctionner car elle ne peut pas détecter "
"les mutations pour invalider le cache."
#: faq/programming.rst:2020
2022-05-22 21:15:02 +00:00
#, fuzzy
msgid ""
2022-05-22 21:15:02 +00:00
"To make the *lru_cache* approach work when the *station_id* is mutable, the "
"class needs to define the :meth:`~object.__eq__` and :meth:`~object."
"__hash__` methods so that the cache can detect relevant attribute updates::"
msgstr ""
"En revanche, ``lru_cache`` est utilisable à condition de définir les "
"méthodes ``__eq__`` et ``__hash__`` pour que le cache soit à même de "
2021-10-27 17:49:12 +00:00
"détecter toute modification des attributs ::"
#: faq/programming.rst:2046
2016-10-30 09:46:26 +00:00
msgid "Modules"
msgstr "Modules"
#: faq/programming.rst:2049
2016-10-30 09:46:26 +00:00
msgid "How do I create a .pyc file?"
2021-10-27 17:49:12 +00:00
msgstr "Comment créer des fichiers ``.pyc`` ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2051
2016-10-30 09:46:26 +00:00
msgid ""
"When a module is imported for the first time (or when the source file has "
"changed since the current compiled file was created) a ``.pyc`` file "
"containing the compiled code should be created in a ``__pycache__`` "
"subdirectory of the directory containing the ``.py`` file. The ``.pyc`` "
"file will have a filename that starts with the same name as the ``.py`` "
"file, and ends with ``.pyc``, with a middle component that depends on the "
"particular ``python`` binary that created it. (See :pep:`3147` for details.)"
msgstr ""
2019-06-12 12:29:00 +00:00
"Quand un module est importé pour la première fois (ou si le fichier source a "
"été modifié depuis la création du fichier compilé), un fichier ``.pyc`` "
"contenant le code précompilé est créé dans un sous-dossier ``__pycache__`` "
"du dossier contentant le fichier ``.py``. Le nom du fichier ``.pyc`` est "
"identique au fichier ``.py`` et se termine par ``.pyc``, avec une partie "
"centrale qui dépend du binaire ``python`` qui l'a créé (voir la :pep:`3147` "
"pour de plus amples précisions)."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2059
2016-10-30 09:46:26 +00:00
msgid ""
"One reason that a ``.pyc`` file may not be created is a permissions problem "
"with the directory containing the source file, meaning that the "
"``__pycache__`` subdirectory cannot be created. This can happen, for "
"example, if you develop as one user but run as another, such as if you are "
"testing with a web server."
msgstr ""
2019-06-12 12:29:00 +00:00
"Une des raisons pour lesquelles un fichier ``.pyc`` peut ne pas être créé "
"est un problème de droits sur le dossier qui contient le fichier source, ce "
"qui veut dire qu'il est impossible de créer le sous-dossier ``__pycache__``. "
"Ceci peut arriver, par exemple, si vous développez en tant qu'un certain "
"utilisateur, mais que le code est exécuté en tant qu'un autre utilisateur, "
"par exemple pour tester un serveur Web."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2064
2016-10-30 09:46:26 +00:00
msgid ""
"Unless the :envvar:`PYTHONDONTWRITEBYTECODE` environment variable is set, "
"creation of a .pyc file is automatic if you're importing a module and Python "
"has the ability (permissions, free space, etc...) to create a "
"``__pycache__`` subdirectory and write the compiled module to that "
"subdirectory."
msgstr ""
2021-10-27 17:49:12 +00:00
"La création du fichier ``.pyc`` est automatique durant l'importation d'un "
"module si Python est capable (en termes de droits, d'espace disque, etc) de "
"créer un sous-dossier ``__pycache__`` et d'écrire le module ainsi compilé "
"dans ce sous-répertoire, à moins que la variable d'environnement :envvar:"
2019-06-12 12:29:00 +00:00
"`PYTHONDONTWRITEBYTECODE` soit définie."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2069
2016-10-30 09:46:26 +00:00
msgid ""
"Running Python on a top level script is not considered an import and no ``."
"pyc`` will be created. For example, if you have a top-level module ``foo."
"py`` that imports another module ``xyz.py``, when you run ``foo`` (by typing "
"``python foo.py`` as a shell command), a ``.pyc`` will be created for "
"``xyz`` because ``xyz`` is imported, but no ``.pyc`` file will be created "
"for ``foo`` since ``foo.py`` isn't being imported."
msgstr ""
2019-06-12 12:29:00 +00:00
"Exécuter du Python dans un script de plus haut niveau n'est pas considéré "
2021-10-27 17:49:12 +00:00
"comme une importation et le fichier ``.pyc`` n'est pas créé. Par exemple, si "
"un module de plus haut niveau ``foo.py`` importe un autre module ``xyz.py``, "
2019-06-12 12:29:00 +00:00
"alors à l'exécution de ``foo`` (en tapant ``python foo.py`` dans la "
"console), un fichier ``.pyc`` est créé pour ``xyz`` mais pas pour ``foo`` "
"car ``foo.py`` n'est pas importé."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2076
2016-10-30 09:46:26 +00:00
msgid ""
"If you need to create a ``.pyc`` file for ``foo`` -- that is, to create a ``."
"pyc`` file for a module that is not imported -- you can, using the :mod:"
"`py_compile` and :mod:`compileall` modules."
msgstr ""
2019-06-12 12:29:00 +00:00
"Pour créer un fichier ``.pyc`` pour ``foo`` — c'est-à-dire créer un fichier "
"``.pyc`` pour un module qui n'est pas importé — il existe les modules :mod:"
"`py_compile` et :mod:`compileall`."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2080
2016-10-30 09:46:26 +00:00
msgid ""
"The :mod:`py_compile` module can manually compile any module. One way is to "
"use the ``compile()`` function in that module interactively::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Le module :mod:`py_compile` peut compiler n'importe quel module "
"manuellement. Il est ainsi possible d'appeler la fonction ``compile()`` de "
"manière interactive ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2086
2016-10-30 09:46:26 +00:00
msgid ""
"This will write the ``.pyc`` to a ``__pycache__`` subdirectory in the same "
"location as ``foo.py`` (or you can override that with the optional parameter "
"``cfile``)."
msgstr ""
2019-06-12 12:29:00 +00:00
"Ces lignes écrivent le ``.pyc`` dans un sous-dossier ``__pycache__`` à côté "
"de ``foo.py`` (le paramètre optionnel ``cfile`` permet de changer ce "
"comportement)."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2090
2016-10-30 09:46:26 +00:00
msgid ""
"You can also automatically compile all files in a directory or directories "
"using the :mod:`compileall` module. You can do it from the shell prompt by "
"running ``compileall.py`` and providing the path of a directory containing "
"Python files to compile::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Tous les fichiers d'un ou plusieurs dossiers peuvent aussi être compilés "
"avec le module :mod:`compileall`. C'est possible depuis l'invite de commande "
"en exécutant ``compileall.py`` avec le chemin du dossier contenant les "
"fichiers Python à compiler ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2099
2016-10-30 09:46:26 +00:00
msgid "How do I find the current module name?"
2021-10-27 17:49:12 +00:00
msgstr "Comment obtenir le nom du module actuel ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2101
2016-10-30 09:46:26 +00:00
msgid ""
"A module can find out its own module name by looking at the predefined "
"global variable ``__name__``. If this has the value ``'__main__'``, the "
"program is running as a script. Many modules that are usually used by "
"importing them also provide a command-line interface or a self-test, and "
"only execute this code after checking ``__name__``::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Un module peut déterminer son propre nom en examinant la variable globale "
"prédéfinie ``__name__``. Si celle-ci vaut ``'__main__'``, c'est que le "
"programme est exécuté comme un script. Beaucoup de modules qui doivent "
"normalement être importés pour pouvoir être utilisés fournissent aussi une "
"interface en ligne de commande ou un test automatique. Ils n'exécutent cette "
"portion du code qu'après avoir vérifié la valeur de ``__name__`` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2116
2016-10-30 09:46:26 +00:00
msgid "How can I have modules that mutually import each other?"
2021-10-27 17:49:12 +00:00
msgstr "Comment avoir des modules qui s'importent mutuellement ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2118
2016-10-30 09:46:26 +00:00
msgid "Suppose you have the following modules:"
2021-10-27 17:49:12 +00:00
msgstr "Considérons les modules suivants :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2120
msgid ":file:`foo.py`::"
2021-10-27 17:49:12 +00:00
msgstr ":file:`foo.py` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2125
msgid ":file:`bar.py`::"
2021-10-27 17:49:12 +00:00
msgstr ":file:`bar.py` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2130
2016-10-30 09:46:26 +00:00
msgid "The problem is that the interpreter will perform the following steps:"
2021-10-27 17:49:12 +00:00
msgstr "Le problème réside dans les étapes que l'interpréteur va réaliser :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2132
msgid "main imports ``foo``"
msgstr "*main* importe *foo* ;"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2133
msgid "Empty globals for ``foo`` are created"
msgstr "Les variables globales (vides) de *foo* sont créées ;"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2134
msgid "``foo`` is compiled and starts executing"
msgstr "*foo* est compilé et commence à s'exécuter ;"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2135
msgid "``foo`` imports ``bar``"
msgstr "*foo* importe *bar* ;"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2136
msgid "Empty globals for ``bar`` are created"
msgstr "Les variables globales (vides) de *bar* sont créées ;"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2137
msgid "``bar`` is compiled and starts executing"
msgstr "*bar* est compilé et commence à s'exécuter ;"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2138
2016-10-30 09:46:26 +00:00
msgid ""
"``bar`` imports ``foo`` (which is a no-op since there already is a module "
"named ``foo``)"
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"*bar* importe *foo* (en réalité, rien ne passe car il y a déjà un module "
"appelé *foo*) ;"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2139
msgid ""
"The import mechanism tries to read ``foo_var`` from ``foo`` globals, to set "
"``bar.foo_var = foo.foo_var``"
msgstr ""
2021-10-27 17:49:12 +00:00
"La mécanique des importations tente de lire *foo_var* dans les variables "
"globales de *foo* pour procéder à l'affectation ``bar.foo_var = foo."
"foo_var``."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2141
2016-10-30 09:46:26 +00:00
msgid ""
"The last step fails, because Python isn't done with interpreting ``foo`` yet "
"and the global symbol dictionary for ``foo`` is still empty."
msgstr ""
2019-06-12 12:29:00 +00:00
"La dernière étape échoue car Python n'a pas fini d'interpréter ``foo`` et le "
"dictionnaire global des symboles de ``foo`` est encore vide."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2144
2016-10-30 09:46:26 +00:00
msgid ""
"The same thing happens when you use ``import foo``, and then try to access "
"``foo.foo_var`` in global code."
msgstr ""
2019-06-12 12:29:00 +00:00
"Le même phénomène arrive quand on utilise ``import foo``, et qu'on essaye "
"ensuite d'accéder à ``foo.foo_var`` dans le code global."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2147
2016-10-30 09:46:26 +00:00
msgid "There are (at least) three possible workarounds for this problem."
2019-06-12 12:29:00 +00:00
msgstr "Il y a (au moins) trois façons de contourner ce problème."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2149
2016-10-30 09:46:26 +00:00
msgid ""
"Guido van Rossum recommends avoiding all uses of ``from <module> import ..."
"``, and placing all code inside functions. Initializations of global "
"variables and class variables should use constants or built-in functions "
"only. This means everything from an imported module is referenced as "
"``<module>.<name>``."
msgstr ""
2019-06-12 12:29:00 +00:00
"Guido van Rossum déconseille d'utiliser ``from <module> import ...`` et de "
"mettre tout le code dans des fonctions. L'initialisation des variables "
"globales et des variables de classe ne doit utiliser que des constantes ou "
"des fonctions natives. Ceci implique que tout ce qui est fourni par un "
"module soit référencé par ``<module>.<nom>``."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2154
2016-10-30 09:46:26 +00:00
msgid ""
"Jim Roskind suggests performing steps in the following order in each module:"
msgstr ""
2019-06-12 12:29:00 +00:00
"Jim Roskind recommande d'effectuer les étapes suivantes dans cet ordre dans "
2021-10-27 17:49:12 +00:00
"chaque module :"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2156
2016-10-30 09:46:26 +00:00
msgid ""
"exports (globals, functions, and classes that don't need imported base "
"classes)"
msgstr ""
2019-06-12 12:29:00 +00:00
"les exportations (variables globales, fonctions et les classes qui ne "
"nécessitent d'importer des classes mères)"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2158
2016-10-30 09:46:26 +00:00
msgid "``import`` statements"
2019-06-12 12:29:00 +00:00
msgstr "les instructions ``import``"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2159
2016-10-30 09:46:26 +00:00
msgid ""
"active code (including globals that are initialized from imported values)."
msgstr ""
2019-06-12 12:29:00 +00:00
"le code (avec les variables globales qui sont initialisées à partir de "
"valeurs importées)."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2161
2016-10-30 09:46:26 +00:00
msgid ""
"Van Rossum doesn't like this approach much because the imports appear in a "
2016-10-30 09:46:26 +00:00
"strange place, but it does work."
msgstr ""
2019-06-12 12:29:00 +00:00
"van Rossum désapprouve cette approche car les importations se trouvent à un "
"endroit bizarre, mais cela fonctionne."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2164
2016-10-30 09:46:26 +00:00
msgid ""
"Matthias Urlichs recommends restructuring your code so that the recursive "
"import is not necessary in the first place."
msgstr ""
2019-06-12 12:29:00 +00:00
"Matthias Urlichs conseille de restructurer le code pour éviter les "
"importations récursives."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2167
2016-10-30 09:46:26 +00:00
msgid "These solutions are not mutually exclusive."
2019-06-12 12:29:00 +00:00
msgstr "Ces solutions peuvent être combinées."
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2171
2016-10-30 09:46:26 +00:00
msgid "__import__('x.y.z') returns <module 'x'>; how do I get z?"
msgstr ""
"``__import__('x.y.z')`` renvoie ``<module 'x'>`` ; comment accéder à ``z`` ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2173
2016-10-30 09:46:26 +00:00
msgid ""
"Consider using the convenience function :func:`~importlib.import_module` "
"from :mod:`importlib` instead::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Utilisez plutôt la fonction :func:`~importlib.import_module` de :mod:"
"`importlib` ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2180
2016-10-30 09:46:26 +00:00
msgid ""
"When I edit an imported module and reimport it, the changes don't show up. "
"Why does this happen?"
msgstr ""
2019-06-12 12:29:00 +00:00
"Quand j'édite un module et que je le réimporte, je ne vois pas les "
2021-10-27 17:49:12 +00:00
"changements. Pourquoi ?"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2182
2016-10-30 09:46:26 +00:00
msgid ""
"For reasons of efficiency as well as consistency, Python only reads the "
"module file on the first time a module is imported. If it didn't, in a "
"program consisting of many modules where each one imports the same basic "
"module, the basic module would be parsed and re-parsed many times. To force "
"re-reading of a changed module, do this::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Pour des raisons de performance et de cohérence, Python ne lit le fichier "
"d'un module que la première fois où celui-ci est importé. Si ce n'était pas "
"le cas, dans un programme composé d'un très grand nombre de modules qui "
"importent tous le même module de base, ce module de base serait analysé et "
"ré-analysé un très grand nombre de fois. Pour forcer la relecture d'un "
"module, il faut faire ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2192
2016-10-30 09:46:26 +00:00
msgid ""
"Warning: this technique is not 100% fool-proof. In particular, modules "
"containing statements like ::"
msgstr ""
2019-06-12 12:29:00 +00:00
"Attention, cette technique ne marche pas systématiquement. En particulier, "
"les modules qui contiennent des instructions comme ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2197
2016-10-30 09:46:26 +00:00
msgid ""
"will continue to work with the old version of the imported objects. If the "
"module contains class definitions, existing class instances will *not* be "
"updated to use the new class definition. This can result in the following "
2018-06-28 13:32:56 +00:00
"paradoxical behaviour::"
2016-10-30 09:46:26 +00:00
msgstr ""
2019-06-12 12:29:00 +00:00
"continuent de fonctionner avec l'ancienne version des objets importés. Si le "
"module contient une définition de classe, les instances déjà existantes de "
2019-06-12 12:29:00 +00:00
"celle-ci ne sont *pas* mises à jour avec la nouvelle définition de la "
"classe. Ceci peut conduire au comportement paradoxal suivant ::"
2016-10-30 09:46:26 +00:00
#: faq/programming.rst:2210
2016-10-30 09:46:26 +00:00
msgid ""
"The nature of the problem is made clear if you print out the \"identity\" of "
2018-06-28 13:32:56 +00:00
"the class objects::"
2016-10-30 09:46:26 +00:00
msgstr ""
"La nature du problème apparaît clairement en affichant « l'identité » des "
2019-06-12 12:29:00 +00:00
"objets de la classe ::"
2020-10-02 08:55:01 +00:00
#~ msgid "Use a list comprehension::"
#~ msgstr "Utilisez une liste en compréhension ::"
#~ msgid ""
#~ "For version prior to 3.0, you may be using classic classes: For a class "
#~ "definition such as ``class Derived(Base): ...`` you can call method "
#~ "``meth()`` defined in ``Base`` (or one of ``Base``'s base classes) as "
#~ "``Base.meth(self, arguments...)``. Here, ``Base.meth`` is an unbound "
#~ "method, so you need to provide the ``self`` argument."
#~ msgstr ""
#~ "Pour les versions antérieures à 3.0, vous pouvez utiliser des classes "
#~ "classiques : pour une définition de classe comme ``class "
#~ "Derived(Base): ...`` vous pouvez appeler la méthode ``meth()`` définie "
#~ "dans ``Base`` (ou l'une des classes de base de ``Base``) en faisant "
#~ "``Base.meth(self, arguments...)``. Ici, ``Base.meth`` est une méthode non "
#~ "liée, il faut donc fournir l'argument ``self``."
#~ msgid "bar.foo_var = foo.foo_var"
#~ msgstr "bar.foo_var = foo.foo_var"
2021-06-04 11:47:25 +00:00
#, fuzzy
#~ msgid ""
#~ "Obviously, freeze requires a C compiler. There are several other "
#~ "utilities which don't:"
#~ msgstr ""
#~ "Bien évidemment, *freeze* nécessite un compilateur C. Il existe d'autres "
#~ "outils qui peuvent s'en passer. Un de ceux-ci est py2exe de Thomas Heller "
#~ "(pour Windows uniquement) disponible sur"
#~ msgid ""
#~ "Pydb is a version of the standard Python debugger pdb, modified for use "
#~ "with DDD (Data Display Debugger), a popular graphical debugger front "
#~ "end. Pydb can be found at http://bashdb.sourceforge.net/pydb/ and DDD "
#~ "can be found at https://www.gnu.org/software/ddd."
#~ msgstr ""
#~ "*Pydb* est une version du débogueur standard Python *pdb*, modifié pour "
#~ "être utilisé avec DDD (Data Display Debugger), un célèbre débogueur "
#~ "graphique. *Pydb* est disponible sur http://bashdb.sourceforge.net/pydb/ "
#~ "et DDD est disponible sur https://www.gnu.org/software/ddd."
#~ msgid "Komodo IDE (https://komodoide.com/)"
#~ msgstr "Komodo IDE (https://komodoide.com/)"
#~ msgid ""
#~ "Another tool is Anthony Tuininga's `cx_Freeze <https://anthony-tuininga."
#~ "github.io/cx_Freeze/>`_."
#~ msgstr ""
#~ "Un autre de ces outils est `cx_Freeze <https://anthony-tuininga.github.io/"
#~ "cx_Freeze/>`_ d'Anthony Tuininga."
2020-12-18 06:09:57 +00:00
#~ msgid ""
#~ "Note: Using :func:`eval` is slow and dangerous. If you don't have "
#~ "absolute control over the contents of the string, someone could pass a "
#~ "string that resulted in an arbitrary function being executed."
#~ msgstr ""
#~ "Note : utiliser :func:`eval` est lent est dangereux. Si vous n'avez pas "
#~ "un contrôle absolu sur le contenu de la chaîne de caractères, quelqu'un "
#~ "pourrait passer une chaîne de caractères pouvant appeler n'importe quelle "
#~ "fonction."
#~ msgid "With Python 2.3, you can use an extended slice syntax::"
#~ msgstr ""
#~ "Avec Python 2.3 vous pouvez utiliser la syntaxe étendue de tranches ::"
#~ msgid "An alternative for the last step is::"
#~ msgstr "Vous pouvez remplacer la dernière étape par ::"
#~ msgid ""
#~ "If you find this more legible, you might prefer to use this instead of "
#~ "the final list comprehension. However, it is almost twice as slow for "
#~ "long lists. Why? First, the ``append()`` operation has to reallocate "
#~ "memory, and while it uses some tricks to avoid doing that each time, it "
#~ "still has to do it occasionally, and that costs quite a bit. Second, the "
#~ "expression \"result.append\" requires an extra attribute lookup, and "
#~ "third, there's a speed reduction from having to make all those function "
#~ "calls."
#~ msgstr ""
#~ "Si cela vous semble plus lisible, vous pouvez utiliser cette forme plutôt "
#~ "qu'une liste en compréhension. Toutefois, ce code est presque deux fois "
#~ "plus lent pour une liste de grande taille. Pourquoi ? Tout d'abord, parce "
#~ "que ``append()`` doit ré-allouer de la mémoire et, même si elle utilise "
#~ "quelques astuces pour éviter d'effectuer la ré-allocation à chaque appel, "
#~ "elle doit tout de même le faire de temps en temps, ce qui coûte assez "
#~ "cher. Deuxièmement, parce que l'expression ``result.append`` fait un "
#~ "accès supplémentaire à un attribut et, enfin, parce que tous ces appels "
#~ "de fonctions réduisent la vitesse d'exécution."
2020-10-02 08:55:01 +00:00
#~ msgid ""
#~ "`Boa Constructor <http://boa-constructor.sourceforge.net/>`_ is an IDE "
#~ "and GUI builder that uses wxWidgets. It offers visual frame creation and "
#~ "manipulation, an object inspector, many views on the source like object "
#~ "browsers, inheritance hierarchies, doc string generated html "
#~ "documentation, an advanced debugger, integrated help, and Zope support."
#~ msgstr ""
#~ "`Boa Constructor <http://boa-constructor.sourceforge.net/>`_ est un EDI "
#~ "et un constructeur d'interface homme-machine basé sur *wxWidgets*. Il "
#~ "propose la création et la manipulation de fenêtres, un inspecteur "
#~ "d'objets, de nombreuses façons de visualiser des sources comme un "
#~ "navigateur d'objets, les hiérarchies d'héritage, la documentation html "
#~ "générée par les docstrings, un débogueur avancé, une aide intégrée et la "
#~ "prise en charge de Zope."
#~ msgid ""
#~ "PyChecker is a static analysis tool that finds bugs in Python source code "
#~ "and warns about code complexity and style. You can get PyChecker from "
#~ "http://pychecker.sourceforge.net/."
#~ msgstr ""
#~ "*PyChecker* est un outil d'analyse statique qui trouve les bogues dans le "
#~ "code source Python et émet des avertissements relatifs à la complexité et "
#~ "au style du code. *PyChecker* est disponible sur http://pychecker."
#~ "sourceforge.net/."
#~ msgid ""
#~ "`Pylint <https://www.pylint.org/>`_ is another tool that checks if a "
#~ "module satisfies a coding standard, and also makes it possible to write "
#~ "plug-ins to add a custom feature. In addition to the bug checking that "
#~ "PyChecker performs, Pylint offers some additional features such as "
#~ "checking line length, whether variable names are well-formed according to "
#~ "your coding standard, whether declared interfaces are fully implemented, "
#~ "and more. https://docs.pylint.org/ provides a full list of Pylint's "
#~ "features."
#~ msgstr ""
#~ "Pylint <https://www.pylint.org/>`_ est un autre outil qui vérifie si un "
#~ "module satisfait aux normes de développement, et qui permet en plus "
#~ "d'écrire des greffons pour ajouter des fonctionnalités personnalisées. "
#~ "En plus de la vérification des bogues effectuée par PyChecker, Pylint "
#~ "effectue quelques vérifications supplémentaires comme la longueur des "
#~ "lignes, les conventions de nommage des variables, que les interfaces "
#~ "déclarées sont implémentées en totalité, et plus encore. https://docs."
#~ "pylint.org/ fournit la liste complète des fonctionnalités de Pylint."