Traduction de library/__main__.po (#1751)

Co-authored-by: Christophe Nanteuil <35002064+christopheNan@users.noreply.github.com>
This commit is contained in:
Jean-Abou-Samra 2021-10-29 08:37:05 +02:00 committed by GitHub
parent fe68872fc6
commit 5084a5c86a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,34 +6,38 @@ msgstr ""
"Project-Id-Version: Python 3\n" "Project-Id-Version: Python 3\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-09-23 16:16+0200\n" "POT-Creation-Date: 2021-09-23 16:16+0200\n"
"PO-Revision-Date: 2017-11-07 22:52+0100\n" "PO-Revision-Date: 2021-10-28 17:30+0200\n"
"Last-Translator: Julien Palard <julien@palard.fr>\n" "Last-Translator: Jean Abou Samra <jean@abou-samra.fr>\n"
"Language-Team: FRENCH <traductions@lists.afpy.org>\n" "Language-Team: FRENCH <traductions@lists.afpy.org>\n"
"Language: fr\n" "Language: fr\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.0\n"
#: library/__main__.rst:2 #: library/__main__.rst:2
#, fuzzy
msgid ":mod:`__main__` --- Top-level code environment" msgid ":mod:`__main__` --- Top-level code environment"
msgstr ":mod:`__main__` — Point d'entrée des scripts" msgstr ":mod:`__main__` — Environnement d'exécution principal"
#: library/__main__.rst:10 #: library/__main__.rst:10
msgid "" msgid ""
"In Python, the special name ``__main__`` is used for two important " "In Python, the special name ``__main__`` is used for two important "
"constructs:" "constructs:"
msgstr "" msgstr ""
"En Python, le nom ``__main__`` a une fonction particulière. Il intervient "
"dans deux cas :"
#: library/__main__.rst:12 #: library/__main__.rst:12
msgid "" msgid ""
"the name of the top-level environment of the program, which can be checked " "the name of the top-level environment of the program, which can be checked "
"using the ``__name__ == '__main__'`` expression; and" "using the ``__name__ == '__main__'`` expression; and"
msgstr "" msgstr ""
"c'est le nom de l'environnement d'exécution principal, ce qui donne lieu au "
"test courant ``__name__ == '__main__'`` ;"
#: library/__main__.rst:14 #: library/__main__.rst:14
msgid "the ``__main__.py`` file in Python packages." msgid "the ``__main__.py`` file in Python packages."
msgstr "" msgstr "c'est aussi le nom du fichier ``__main__.py`` dans les paquets Python."
#: library/__main__.rst:16 #: library/__main__.rst:16
msgid "" msgid ""
@ -42,10 +46,15 @@ msgid ""
"detail below. If you're new to Python modules, see the tutorial section :" "detail below. If you're new to Python modules, see the tutorial section :"
"ref:`tut-modules` for an introduction." "ref:`tut-modules` for an introduction."
msgstr "" msgstr ""
"Les deux sont liés aux modules Python, à la manière de s'en servir en tant "
"qu'utilisateur et à la manière dont ils interagissent entre eux. Cette page "
"contient des détails sur les modules Python. Si vous ne les avez jamais "
"utilisés, commencez par la section qui leur est consacrée dans le "
"tutoriel : :ref:`tut-modules`."
#: library/__main__.rst:25 #: library/__main__.rst:25
msgid "``__name__ == '__main__'``" msgid "``__name__ == '__main__'``"
msgstr "" msgstr "``__name__ == '__main__'``"
#: library/__main__.rst:27 #: library/__main__.rst:27
msgid "" msgid ""
@ -53,22 +62,29 @@ msgid ""
"module's name. Usually, this is the name of the Python file itself without " "module's name. Usually, this is the name of the Python file itself without "
"the ``.py`` extension::" "the ``.py`` extension::"
msgstr "" msgstr ""
"Lorsqu'un module ou un paquet Python est importé, son attribut ``__name__`` "
"est défini à son nom, qui est la plupart du temps le nom du fichier qui le "
"contient sans l'extension ``.py`` :"
#: library/__main__.rst:35 #: library/__main__.rst:35
msgid "" msgid ""
"If the file is part of a package, ``__name__`` will also include the parent " "If the file is part of a package, ``__name__`` will also include the parent "
"package's path::" "package's path::"
msgstr "" msgstr ""
"Si le fichier fait partie d'un paquet, ``__name__`` donne tout le chemin "
"d'accès :"
#: library/__main__.rst:42 #: library/__main__.rst:42
msgid "" msgid ""
"However, if the module is executed in the top-level code environment, its " "However, if the module is executed in the top-level code environment, its "
"``__name__`` is set to the string ``'__main__'``." "``__name__`` is set to the string ``'__main__'``."
msgstr "" msgstr ""
"En revanche, si le module est exécuté dans l'environnement d'exécution "
"principal, la variable ``__name__`` vaut ``'__main__'``."
#: library/__main__.rst:46 #: library/__main__.rst:46
msgid "What is the \"top-level code environment\"?" msgid "What is the \"top-level code environment\"?"
msgstr "" msgstr "Qu'est-ce que l'« environnement d'exécution principal » ?"
#: library/__main__.rst:48 #: library/__main__.rst:48
msgid "" msgid ""
@ -78,62 +94,73 @@ msgid ""
"program needs. Sometimes \"top-level code\" is called an *entry point* to " "program needs. Sometimes \"top-level code\" is called an *entry point* to "
"the application." "the application."
msgstr "" msgstr ""
"L'environnement principal a pour nom ``__main__``. Il s'agit du premier "
"module Python dont l'exécution a été demandée par l'utilisateur final. On le "
"qualifie de principal car c'est lui qui importe tous les autres modules "
"nécessités par le programme. On l'appelle parfois le point d'entrée de "
"l'application."
#: library/__main__.rst:53 #: library/__main__.rst:53
msgid "The top-level code environment can be:" msgid "The top-level code environment can be:"
msgstr "" msgstr "L'environnement principal peut prendre diverses formes :"
#: library/__main__.rst:55 #: library/__main__.rst:55
msgid "the scope of an interactive prompt::" msgid "the scope of an interactive prompt::"
msgstr "" msgstr "l'environnement d'une invite de commande interactive :"
#: library/__main__.rst:60 #: library/__main__.rst:60
msgid "the Python module passed to the Python interpreter as a file argument:" msgid "the Python module passed to the Python interpreter as a file argument:"
msgstr "" msgstr ""
"le module passé directement en tant que fichier à la commande de "
"l'interpréteur Python :"
#: library/__main__.rst:67 #: library/__main__.rst:67
msgid "" msgid ""
"the Python module or package passed to the Python interpreter with the :" "the Python module or package passed to the Python interpreter with the :"
"option:`-m` argument:" "option:`-m` argument:"
msgstr "" msgstr ""
"le module ou paquet passé à l'interpréteur avec l'option :option:`-m` :"
# Minuscule car toujours dans la même énumération, ignorez l'avertissement que Poedit affiche à cause de la majuscule à « Python ».
#: library/__main__.rst:75 #: library/__main__.rst:75
msgid "Python code read by the Python interpreter from standard input:" msgid "Python code read by the Python interpreter from standard input:"
msgstr "" msgstr "le code lu par l'interpréteur depuis l'entrée standard :"
#: library/__main__.rst:86 #: library/__main__.rst:86
msgid "" msgid ""
"Python code passed to the Python interpreter with the :option:`-c` argument:" "Python code passed to the Python interpreter with the :option:`-c` argument:"
msgstr "" msgstr "le code passé à l'interpréteur avec l'option :option:`-c` :"
#: library/__main__.rst:97 #: library/__main__.rst:97
msgid "" msgid ""
"In each of these situations, the top-level module's ``__name__`` is set to " "In each of these situations, the top-level module's ``__name__`` is set to "
"``'__main__'``." "``'__main__'``."
msgstr "" msgstr ""
"Dans chacun de ces cas, l'attribut ``__name__`` du module principal est mis "
"à ``'__main__'``."
#: library/__main__.rst:100 #: library/__main__.rst:100
#, fuzzy
msgid "" msgid ""
"As a result, a module can discover whether or not it is running in the top-" "As a result, a module can discover whether or not it is running in the top-"
"level environment by checking its own ``__name__``, which allows a common " "level environment by checking its own ``__name__``, which allows a common "
"idiom for conditionally executing code when the module is not initialized " "idiom for conditionally executing code when the module is not initialized "
"from an import statement::" "from an import statement::"
msgstr "" msgstr ""
"Un module peut découvrir s'il est exécuté dans le *scope* principal en " "Un module peut donc savoir s'il est exécuté dans l'environnement principal "
"vérifiant son ``__name__``, ce qui permet typiquement d'exécuter du code " "en vérifiant son ``__name__``, ce qui permet typiquement d'exécuter du code "
"lorsque le module est exécuté avec ``python -m`` mais pas lorsqu'il est " "lorsque le module est initialisé d'une manière autre que l'importation ::"
"importé ::"
#: library/__main__.rst:111 #: library/__main__.rst:111
msgid "" msgid ""
"For a more detailed look at how ``__name__`` is set in all situations, see " "For a more detailed look at how ``__name__`` is set in all situations, see "
"the tutorial section :ref:`tut-modules`." "the tutorial section :ref:`tut-modules`."
msgstr "" msgstr ""
"Pour plus de détails sur la manière dont ``__name__`` est défini dans les "
"divers cas, voir la section :ref:`tut-modules` dans le tutoriel."
#: library/__main__.rst:239 #: library/__main__.rst:239
msgid "Idiomatic Usage" msgid "Idiomatic Usage"
msgstr "" msgstr "Utilisation idiomatique"
#: library/__main__.rst:118 #: library/__main__.rst:118
msgid "" msgid ""
@ -142,6 +169,11 @@ msgid ""
"like this were to be imported from a different module, for example to unit " "like this were to be imported from a different module, for example to unit "
"test it, the script code would unintentionally execute as well." "test it, the script code would unintentionally execute as well."
msgstr "" msgstr ""
"Il arrive qu'un module contienne du code qui ne doit s'exécuter que lorsque "
"le module est utilisé comme script. On peut penser à l'analyse des arguments "
"passés en ligne de commande, ou bien à la lecture de l'entrée standard. Il "
"ne faudrait pas que ces opérations soient effectuées lorsque le module est "
"importé depuis un autre module, comme pour les tests."
#: library/__main__.rst:123 #: library/__main__.rst:123
msgid "" msgid ""
@ -149,6 +181,9 @@ msgid ""
"handy. Code within this block won't run unless the module is executed in the " "handy. Code within this block won't run unless the module is executed in the "
"top-level environment." "top-level environment."
msgstr "" msgstr ""
"C'est dans ces situations que sert la construction ``if __name__ == "
"'__main__'``. Le code mis à l'intérieur du bloc n'est exécuté que si le "
"module est dans l'environnement principal."
#: library/__main__.rst:127 #: library/__main__.rst:127
msgid "" msgid ""
@ -156,6 +191,10 @@ msgid ""
"'__main__'`` can improve code clarity and correctness. Most often, a " "'__main__'`` can improve code clarity and correctness. Most often, a "
"function named ``main`` encapsulates the program's primary behavior::" "function named ``main`` encapsulates the program's primary behavior::"
msgstr "" msgstr ""
"Il vaut mieux mettre aussi peu de code que possible sous le ``if __name__ == "
"'__main__'`` pour garder le code clair et limiter les risques d'erreur. La "
"plupart du temps, on écrit une fonction ``main`` qui contient tout le code "
"spécifique à l'utilisation comme script :"
#: library/__main__.rst:151 #: library/__main__.rst:151
msgid "" msgid ""
@ -166,6 +205,11 @@ msgid ""
"the global variable instead of a local name. A ``main`` function solves " "the global variable instead of a local name. A ``main`` function solves "
"this problem." "this problem."
msgstr "" msgstr ""
"Si, dans le module ci-dessus, le code de ``main`` était placé directement "
"dans le ``if __name__ == '__main__'``, la variable ``phrase`` serait "
"globale, et d'autres fonctions pourraient s'en servir par erreur à la place "
"d'une variable locale. Encapsuler le code dans la fonction ``main`` évite "
"cet ennui."
#: library/__main__.rst:158 #: library/__main__.rst:158
msgid "" msgid ""
@ -174,10 +218,14 @@ msgid ""
"imported, the ``echo`` and ``main`` functions will be defined, but neither " "imported, the ``echo`` and ``main`` functions will be defined, but neither "
"of them will be called, because ``__name__ != '__main__'``." "of them will be called, because ``__name__ != '__main__'``."
msgstr "" msgstr ""
"De plus, la fonction ``echo`` est elle-même séparée du reste, et on peut "
"l'importer dans un autre module. Le fait d'importer ``echo.py`` définit les "
"fonctions ``main`` et ``echo``, mais n'en appelle aucune, puisque "
"``__name__ != '__main__'``."
#: library/__main__.rst:165 #: library/__main__.rst:165
msgid "Packaging Considerations" msgid "Packaging Considerations"
msgstr "" msgstr "Considérations liées à l'empaquetage"
#: library/__main__.rst:167 #: library/__main__.rst:167
msgid "" msgid ""
@ -186,6 +234,12 @@ msgid ""
"pip.pypa.io/>`_ inserts the function call into a template script, where the " "pip.pypa.io/>`_ inserts the function call into a template script, where the "
"return value of ``main`` is passed into :func:`sys.exit`. For example::" "return value of ``main`` is passed into :func:`sys.exit`. For example::"
msgstr "" msgstr ""
"Les fonctions ``main`` servent souvent à créer des outils qui s'exécutent en "
"ligne de commande. Les scripts sont ajoutés au système à l'aide de points "
"d'entrée, qui demandent à `pip <https://pip.pypa.io/>`_ de créer un "
"exécutable. Il le fait en insérant un appel à la fonction à l'intérieur d'un "
"modèle prédéfini où la valeur qu'elle renvoie est passée directement à :func:"
"`sys.exit` :"
#: library/__main__.rst:175 #: library/__main__.rst:175
msgid "" msgid ""
@ -194,6 +248,11 @@ msgid ""
"`sys.exit`; typically, an integer or ``None`` (which is implicitly returned " "`sys.exit`; typically, an integer or ``None`` (which is implicitly returned "
"if your function does not have a return statement)." "if your function does not have a return statement)."
msgstr "" msgstr ""
"Puisque l'appel de ``main`` est encapsulé dans :func:`sys.exit`, ``main`` "
"doit renvoyer une valeur qui convienne comme argument à :func:`sys.exit`, "
"par exemple un code de retour sous forme d'entier. La valeur ``None`` est "
"également acceptée, et c'est d'ailleurs celle que renvoie la fonction si "
"elle se termine sans rencontrer d'instruction ``return``."
#: library/__main__.rst:180 #: library/__main__.rst:180
msgid "" msgid ""
@ -202,6 +261,10 @@ msgid ""
"if we later package it as a console script entry-point in a pip-installable " "if we later package it as a console script entry-point in a pip-installable "
"package." "package."
msgstr "" msgstr ""
"Il est utile de se conformer à cette convention. De cette manière, le module "
"se comporte de la même manière s'il est distribué comme script à l'aide des "
"points d'entrée que lorsqu'il est exécuté directement (avec ``python3 echo."
"py``)."
#: library/__main__.rst:185 #: library/__main__.rst:185
msgid "" msgid ""
@ -212,6 +275,11 @@ msgid ""
"py`` example from earlier exemplifies using the ``sys.exit(main())`` " "py`` example from earlier exemplifies using the ``sys.exit(main())`` "
"convention." "convention."
msgstr "" msgstr ""
"En particulier, mieux vaut éviter de renvoyer une chaîne de caractères "
"depuis la fonction ``main``. En effet, si :func:`sys.exit` reçoit une "
"chaîne, elle l'interprète comme un message d'erreur, qu'elle affiche sur :"
"data:`sys.stderr` avant de terminer le programme avec le code de retour 1 "
"(erreur). L'exemple de ``echo.py`` ci-dessus montre la pratique recommandée."
#: library/__main__.rst:193 #: library/__main__.rst:193
msgid "" msgid ""
@ -219,10 +287,13 @@ msgid ""
"collection of tutorials and references on how to distribute and install " "collection of tutorials and references on how to distribute and install "
"Python packages with modern tools." "Python packages with modern tools."
msgstr "" msgstr ""
"Le `guide de l'empaquetage en Python <https://packaging.python.org/>`_ (en "
"anglais) contient plusieurs tutoriels et documents de référence autour de la "
"distribution et de l'installation de paquets Python avec des outils modernes."
#: library/__main__.rst:199 #: library/__main__.rst:199
msgid "``__main__.py`` in Python Packages" msgid "``__main__.py`` in Python Packages"
msgstr "" msgstr "Le fichier ``__main__.py`` dans les paquets Python"
#: library/__main__.rst:201 #: library/__main__.rst:201
msgid "" msgid ""
@ -231,12 +302,19 @@ msgid ""
"to provide a command-line interface for a package. Consider the following " "to provide a command-line interface for a package. Consider the following "
"hypothetical package, \"bandclass\":" "hypothetical package, \"bandclass\":"
msgstr "" msgstr ""
"Si vous n'êtes pas familier des paquets Python, lisez :ref:`tut-packages` "
"dans le tutoriel. Un fichier ``__main__.py`` permet à un paquet de définir "
"une interface en ligne de commande. Prenons pour exemple un paquet nommé "
"*bandclass* :"
#: library/__main__.rst:213 #: library/__main__.rst:213
msgid "" msgid ""
"``__main__.py`` will be executed when the package itself is invoked directly " "``__main__.py`` will be executed when the package itself is invoked directly "
"from the command line using the :option:`-m` flag. For example:" "from the command line using the :option:`-m` flag. For example:"
msgstr "" msgstr ""
"Le fichier ``__main__.py`` qu'il contient s'exécute lorsque le paquet est "
"appelé depuis la ligne de commande avec l'option :option:`-m` de "
"l'interpréteur, comme ceci :"
#: library/__main__.rst:220 #: library/__main__.rst:220
msgid "" msgid ""
@ -245,6 +323,10 @@ msgid ""
"this hypothetical case, it might make sense to allow the teacher to search " "this hypothetical case, it might make sense to allow the teacher to search "
"for students::" "for students::"
msgstr "" msgstr ""
"Cette commande lance l'exécution de ``__main__.py``. Il vous appartient, en "
"tant que concepteur du paquet, de déterminer ce qu'elle doit faire. Dans "
"notre exemple, elle pourrait rechercher un étudiant dans une base de "
"données ::"
#: library/__main__.rst:233 #: library/__main__.rst:233
msgid "" msgid ""
@ -253,6 +335,10 @@ msgid ""
"within a package. For more details, see :ref:`intra-package-references` in " "within a package. For more details, see :ref:`intra-package-references` in "
"the :ref:`tut-modules` section of the tutorial." "the :ref:`tut-modules` section of the tutorial."
msgstr "" msgstr ""
"Remarquez l'importation ``from .student import search_students``. Le point "
"avant ``student`` sert à rendre le chemin ``student`` relatif à la position "
"du module qui l'importe. Pour plus d'informations, voir :ref:`intra-package-"
"references` dans la section :ref:`tut-modules` du tutoriel."
#: library/__main__.rst:241 #: library/__main__.rst:241
msgid "" msgid ""
@ -261,6 +347,10 @@ msgid ""
"execute from other modules. Those other modules can then be easily unit-" "execute from other modules. Those other modules can then be easily unit-"
"tested and are properly reusable." "tested and are properly reusable."
msgstr "" msgstr ""
"En général, on ne met pas le code de ``__main__.py`` dans un bloc ``if "
"__name__ == '__main__'``. Il vaut mieux définir toutes les fonctions utiles "
"dans d'autres modules et réduire la taille du fichier ``__main__.py`` au "
"minimum. Il est alors plus facile de tester et réutiliser ces autres modules."
#: library/__main__.rst:246 #: library/__main__.rst:246
msgid "" msgid ""
@ -268,6 +358,10 @@ msgid ""
"for a ``__main__.py`` file within a package, because its ``__name__`` " "for a ``__main__.py`` file within a package, because its ``__name__`` "
"attribute will include the package's path if imported::" "attribute will include the package's path if imported::"
msgstr "" msgstr ""
"Cependant, un ``if __name__ == '__main__'``, s'il est présent dans le "
"``__main__.py``, fonctionne correctement. En effet, si ``__main__.py`` est "
"importé depuis autre module, son attribut ``__name__`` contient, avant "
"``__main__``, le nom du paquet dont il fait partie :"
#: library/__main__.rst:254 #: library/__main__.rst:254
msgid "" msgid ""
@ -275,6 +369,9 @@ msgid ""
"file though. Hence, for consistency, minimal ``__main__.py`` like the :mod:" "file though. Hence, for consistency, minimal ``__main__.py`` like the :mod:"
"`venv` one mentioned above are preferred." "`venv` one mentioned above are preferred."
msgstr "" msgstr ""
"Malgré tout, cela ne fonctionne pas pour les fichiers ``__main__.py`` à la "
"racine d'une archive ZIP. Aussi est-il préférable d'écrire des ``__main__."
"py`` dans le style minimal de celui de :mod:`venv` mentionné ci-dessous."
#: library/__main__.rst:260 #: library/__main__.rst:260
msgid "" msgid ""
@ -282,12 +379,18 @@ msgid ""
"in the standard library. It doesn't contain a ``if __name__ == '__main__'`` " "in the standard library. It doesn't contain a ``if __name__ == '__main__'`` "
"block. You can invoke it with ``python3 -m venv [directory]``." "block. You can invoke it with ``python3 -m venv [directory]``."
msgstr "" msgstr ""
"Le module :mod:`venv` de la bibliothèque standard est un exemple de paquet "
"contenant un fichier ``__main__.py`` minimal, sans ``if __name__ == "
"'__main__'``. Il s'appelle avec la commande :samp:`python3 -m venv {dossier}"
"`."
#: library/__main__.rst:264 #: library/__main__.rst:264
msgid "" msgid ""
"See :mod:`runpy` for more details on the :option:`-m` flag to the " "See :mod:`runpy` for more details on the :option:`-m` flag to the "
"interpreter executable." "interpreter executable."
msgstr "" msgstr ""
"La documentation du module :mod:`runpy` fournit une description complète de "
"l'option :option:`-m` de l'interpréteur."
#: library/__main__.rst:267 #: library/__main__.rst:267
msgid "" msgid ""
@ -295,10 +398,13 @@ msgid ""
"this case Python looks for a ``__main__.py`` file in the root directory of " "this case Python looks for a ``__main__.py`` file in the root directory of "
"the archive." "the archive."
msgstr "" msgstr ""
"Le module :mod:`zipapp` exécute des applications emballées dans une archive "
"ZIP. Dans ce cas, l'interpréteur recherche un fichier ``__main__.py`` à la "
"racine de l'archive."
#: library/__main__.rst:274 #: library/__main__.rst:274
msgid "``import __main__``" msgid "``import __main__``"
msgstr "" msgstr "``import __main__``"
#: library/__main__.rst:276 #: library/__main__.rst:276
msgid "" msgid ""
@ -308,18 +414,23 @@ msgid ""
"doesn't import a ``__main__.py`` file but rather whichever module that " "doesn't import a ``__main__.py`` file but rather whichever module that "
"received the special name ``'__main__'``." "received the special name ``'__main__'``."
msgstr "" msgstr ""
"Quel que soit le module principal d'un programme, les autres modules peuvent "
"accéder à l':term:`espace de nommage <namespace>` dans lequel il s'exécute "
"en important le module spécial ``__main__``. Celui-ci ne correspond pas "
"forcément à un fichier ``__main__.py``. Il s'agit simplement du module qui a "
"reçu le nom ``'__main__'``."
#: library/__main__.rst:282 #: library/__main__.rst:282
msgid "Here is an example module that consumes the ``__main__`` namespace::" msgid "Here is an example module that consumes the ``__main__`` namespace::"
msgstr "" msgstr "Voici un exemple d'utilisation du module ``__main__`` :"
#: library/__main__.rst:300 #: library/__main__.rst:300
msgid "Example usage of this module could be as follows::" msgid "Example usage of this module could be as follows::"
msgstr "" msgstr "Ce code s'utilise comme ceci :"
#: library/__main__.rst:319 #: library/__main__.rst:319
msgid "Now, if we started our program, the result would look like this:" msgid "Now, if we started our program, the result would look like this:"
msgstr "" msgstr "Le programme ci-dessus donne la sortie :"
#: library/__main__.rst:326 #: library/__main__.rst:326
msgid "" msgid ""
@ -327,6 +438,10 @@ msgid ""
"the line with ``my_name = \"Dinsdale\"`` fixes the program and now it exits " "the line with ``my_name = \"Dinsdale\"`` fixes the program and now it exits "
"with status code 0, indicating success:" "with status code 0, indicating success:"
msgstr "" msgstr ""
"Son code de retour est 1, ce qui signifie une erreur. En supprimant la "
"marque de commentaire en début de ligne ``my_name = \"Dinsdale\"``, le "
"programme est corrigé, et renvoie au système le code 0 car il n'y a plus "
"d'erreur :"
#: library/__main__.rst:335 #: library/__main__.rst:335
msgid "" msgid ""
@ -335,6 +450,10 @@ msgid ""
"the ``if __name__ == \"__main__\"`` block of the ``start`` module. Why does " "the ``if __name__ == \"__main__\"`` block of the ``start`` module. Why does "
"this work?" "this work?"
msgstr "" msgstr ""
"On pourrait s'attendre à un problème au moment de l'importation de "
"``__main__`` : cela ne provoque-t-il pas l'exécution anticipée du code de "
"script sous ``if __name__ == '__main__'`` dans le module principal "
"``start`` ?"
#: library/__main__.rst:339 #: library/__main__.rst:339
msgid "" msgid ""
@ -348,24 +467,42 @@ msgid ""
"<import-dunder-main>` in the import system's reference for details on how " "<import-dunder-main>` in the import system's reference for details on how "
"this works." "this works."
msgstr "" msgstr ""
"En fait, le déroulement de l'exécution est le suivant : au lancement de "
"l'interpréteur, un module ``__main__`` initialement vide est inséré dans :"
"attr:`sys.modules`. Il se remplit au fur et à mesure de l'exécution du code "
"principal. Dans notre exemple, le module principal est ``start``, qui "
"s'exécute ligne par ligne et en vient à importer ``namely``. Or ``namely``, "
"à son tour, importe ``__main__``, c'est-à-dire en fait ``start``. On a donc "
"une importation cyclique. Puisque le module ``__main__`` est déjà présent "
"dans :attr:`sys.modules`, bien qu'encore incomplet, il est directement passé "
"à ``namely`` sans réimportation. La section :ref:`import-dunder-main` dans "
"le document de référence du système d'importation explique plus avant ce "
"fonctionnement."
#: library/__main__.rst:348 #: library/__main__.rst:348
msgid "" msgid ""
"The Python REPL is another example of a \"top-level environment\", so " "The Python REPL is another example of a \"top-level environment\", so "
"anything defined in the REPL becomes part of the ``__main__`` scope::" "anything defined in the REPL becomes part of the ``__main__`` scope::"
msgstr "" msgstr ""
"L'interpréteur interactif est un autre environnement d'exécution principal "
"possible. Toute variable qui y est définie appartient à l'espace de nommage "
"``__main__`` :"
#: library/__main__.rst:364 #: library/__main__.rst:364
msgid "" msgid ""
"Note that in this case the ``__main__`` scope doesn't contain a ``__file__`` " "Note that in this case the ``__main__`` scope doesn't contain a ``__file__`` "
"attribute as it's interactive." "attribute as it's interactive."
msgstr "" msgstr ""
"Dans ce cas, il n'y a pas de variable ``__file__``, puisque cela n'a pas de "
"sens dans le mode interactif."
#: library/__main__.rst:367 #: library/__main__.rst:367
msgid "" msgid ""
"The ``__main__`` scope is used in the implementation of :mod:`pdb` and :mod:" "The ``__main__`` scope is used in the implementation of :mod:`pdb` and :mod:"
"`rlcompleter`." "`rlcompleter`."
msgstr "" msgstr ""
"Le module ``__main__`` est notamment employé dans les implémentations de :"
"mod:`pdb` et :mod:`rlcompleter`."
#~ msgid "" #~ msgid ""
#~ "``'__main__'`` is the name of the scope in which top-level code executes. " #~ "``'__main__'`` is the name of the scope in which top-level code executes. "