forked from AFPy/python-docs-fr
7369 lines
285 KiB
Plaintext
7369 lines
285 KiB
Plaintext
# SOME DESCRIPTIVE TITLE.
|
|
# Copyright (C) 1990-2010, Python Software Foundation
|
|
# This file is distributed under the same license as the Python package.
|
|
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
|
#, fuzzy
|
|
msgid ""
|
|
msgstr ""
|
|
"Project-Id-Version: PACKAGE VERSION\n"
|
|
"Report-Msgid-Bugs-To: \n"
|
|
"POT-Creation-Date: 2014-11-03 09:23\n"
|
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
|
"Language: \n"
|
|
"MIME-Version: 1.0\n"
|
|
"Content-Type: text/plain; charset=UTF-8\n"
|
|
"Content-Transfer-Encoding: 8bit\n"
|
|
"X-Generator: Translate Toolkit 1.7.0\n"
|
|
|
|
#: ../src/Doc/faq/design.rst:3
|
|
msgid "Design and History FAQ"
|
|
msgstr "FAQ Histoire et Design"
|
|
|
|
#: ../src/Doc/faq/design.rst:6
|
|
msgid "Why does Python use indentation for grouping of statements?"
|
|
msgstr "Pourquoi Python utilise l'indentation pour grouper les instructions ?"
|
|
|
|
#: ../src/Doc/faq/design.rst:8
|
|
msgid ""
|
|
"Guido van Rossum believes that using indentation for grouping is extremely "
|
|
"elegant and contributes a lot to the clarity of the average Python program. "
|
|
"Most people learn to love this feature after a while."
|
|
msgstr ""
|
|
"Guido van Rossum pense que l'usage de l'indentation pour regrouper les blocs "
|
|
"d'instruction est élégant et contribue énormément à la clareté globale du "
|
|
"programme Python. La plupart des gens finissent par aimer cette "
|
|
"particularité au bout d'un moment."
|
|
|
|
#: ../src/Doc/faq/design.rst:12
|
|
msgid ""
|
|
"Since there are no begin/end brackets there cannot be a disagreement between "
|
|
"grouping perceived by the parser and the human reader. Occasionally C "
|
|
"programmers will encounter a fragment of code like this::"
|
|
msgstr ""
|
|
"Comme il n'y a pas d'accolades de début/fin, il ne peut y avoir de "
|
|
"différence entre le bloc perçu par l'analyseur syntaxique et le lecteur "
|
|
"humain. Parfois les programmeurs C pourront trouver un morceau de code comme "
|
|
"celui-ci::"
|
|
|
|
#: ../src/Doc/faq/design.rst:21
|
|
msgid ""
|
|
"Only the ``x++`` statement is executed if the condition is true, but the "
|
|
"indentation leads you to believe otherwise. Even experienced C programmers "
|
|
"will sometimes stare at it a long time wondering why ``y`` is being "
|
|
"decremented even for ``x > y``."
|
|
msgstr ""
|
|
"Seule l'instruction ``x++`` sera exécutée si la condition est vraie, mais "
|
|
"l'indentation pourrait vous faire penser le contraire. Mêmes des "
|
|
"développeurs C expérimentés resteront pendant un moment à se demander "
|
|
"pourquoi ``y`` est décrémenté même si ``x > y``."
|
|
|
|
#: ../src/Doc/faq/design.rst:26
|
|
msgid ""
|
|
"Because there are no begin/end brackets, Python is much less prone to coding-"
|
|
"style conflicts. In C there are many different ways to place the braces. If "
|
|
"you're used to reading and writing code that uses one style, you will feel "
|
|
"at least slightly uneasy when reading (or being required to write) another "
|
|
"style."
|
|
msgstr ""
|
|
"Comme il n'y a pas d'accolades de début/fin, Python est moins sujet aux "
|
|
"conflits de style de code. En C, on peut placer les accolades de nombreuses "
|
|
"façons. Si vous êtes habitués à lire et écrire selon un style particulier, "
|
|
"vous pourriez vous sentir perturbé en lisant (ou en devant écrire) avec un "
|
|
"autre style."
|
|
|
|
#: ../src/Doc/faq/design.rst:31
|
|
#, fuzzy
|
|
msgid ""
|
|
"Many coding styles place begin/end brackets on a line by themselves. This "
|
|
"makes programs considerably longer and wastes valuable screen space, making "
|
|
"it harder to get a good overview of a program. Ideally, a function should "
|
|
"fit on one screen (say, 20-30 lines). 20 lines of Python can do a lot more "
|
|
"work than 20 lines of C. This is not solely due to the lack of begin/end "
|
|
"brackets -- the lack of declarations and the high-level data types are also "
|
|
"responsible -- but the indentation-based syntax certainly helps."
|
|
msgstr ""
|
|
"Nombre de styles de programmation placent les accolades de début/fin sur une "
|
|
"ligne à part. Cela rend les sources beaucoup plus longues et fait perdre une "
|
|
"bonne partie de l'espace visible sur l'écran, rendant plus compliqué un "
|
|
"aperçu global du programme. Idéalement, une fonction doit être visible sur "
|
|
"un même écran (environ 20 ou 30 lignes). 20 lignes de Python peuvent faire "
|
|
"beaucoup plus que 20 lignes de C. Ce n'est pas seulement dû à l'absence "
|
|
"d'accolades de début/fin -- l'absence de déclarations et les types de haut-"
|
|
"niveau en sont également responsables -- mais la syntaxe basée sur "
|
|
"l'indentation y est pour beaucoup."
|
|
|
|
#: ../src/Doc/faq/design.rst:41
|
|
msgid "Why am I getting strange results with simple arithmetic operations?"
|
|
msgstr ""
|
|
"Pourquoi ai-je d'étranges résultats suite à de simples opérations "
|
|
"arithmétiques ?"
|
|
|
|
#: ../src/Doc/faq/design.rst:43
|
|
msgid "See the next question."
|
|
msgstr "Voir la question suivante."
|
|
|
|
#: ../src/Doc/faq/design.rst:47
|
|
msgid "Why are floating point calculations so inaccurate?"
|
|
msgstr "Pourquoi les calculs à virgules flottantes sont si imprécis ?"
|
|
|
|
#: ../src/Doc/faq/design.rst:49
|
|
msgid "People are often very surprised by results like this::"
|
|
msgstr "Les gens sont très souvent surpris par des résultats comme celui-ci ::"
|
|
|
|
#: ../src/Doc/faq/design.rst:54
|
|
msgid ""
|
|
"and think it is a bug in Python. It's not. This has nothing to do with "
|
|
"Python, but with how the underlying C platform handles floating point "
|
|
"numbers, and ultimately with the inaccuracies introduced when writing down "
|
|
"numbers as a string of a fixed number of digits."
|
|
msgstr ""
|
|
"et pensent que c'est un bogue dans Python. Ça ne l'est pas. Ceci n'a rien à "
|
|
"voir avec Python, mais avec la manière dont la plateforme C sous-jacente "
|
|
"gère les nombres à virgule flottante et enfin, les imprécisions introduites "
|
|
"lors de l'écriture des nombres en chaînes de caractères d'un nombre fixe de "
|
|
"chiffres."
|
|
|
|
#: ../src/Doc/faq/design.rst:59
|
|
msgid ""
|
|
"The internal representation of floating point numbers uses a fixed number of "
|
|
"binary digits to represent a decimal number. Some decimal numbers can't be "
|
|
"represented exactly in binary, resulting in small roundoff errors."
|
|
msgstr ""
|
|
"La représentation interne des nombres à virgule flottante utilise un nombre "
|
|
"fixe de chiffres binaires pour représenter un nombre décimal. Certains "
|
|
"nombres décimaux ne peuvent être représentés exactement en binaire, "
|
|
"résultant ainsi à de petites erreurs d'arrondi."
|
|
|
|
#: ../src/Doc/faq/design.rst:63
|
|
msgid ""
|
|
"In decimal math, there are many numbers that can't be represented with a "
|
|
"fixed number of decimal digits, e.g. 1/3 = 0.3333333333......."
|
|
msgstr ""
|
|
"En mathématiques, beaucoup de nombre ne peuvent être représentés par un "
|
|
"nombre fixe de chiffres, par exemple 1/3 = 0.3333333333......."
|
|
|
|
#: ../src/Doc/faq/design.rst:66
|
|
msgid ""
|
|
"In base 2, 1/2 = 0.1, 1/4 = 0.01, 1/8 = 0.001, etc. .2 equals 2/10 equals "
|
|
"1/5, resulting in the binary fractional number 0.001100110011001..."
|
|
msgstr ""
|
|
"En base 2, 1/2 = 0.1, 1/4 = 0.01, 1/8 = 0.001, etc. .2 est égale à 2/10 qui "
|
|
"est égale à 1/5, ayant pour résultat le nombre fractionnel binaire "
|
|
"0.001100110011001..."
|
|
|
|
#: ../src/Doc/faq/design.rst:69
|
|
msgid ""
|
|
"Floating point numbers only have 32 or 64 bits of precision, so the digits "
|
|
"are cut off at some point, and the resulting number is 0.199999999999999996 "
|
|
"in decimal, not 0.2."
|
|
msgstr ""
|
|
"Les nombres à virgule flottante ont une précision de seulement 32 ou 64 "
|
|
"bits, donc les chiffres finissent par être tronqués, et le nombre résultant "
|
|
"est 0.199999999999999996 en décimal, pas 0.2."
|
|
|
|
#: ../src/Doc/faq/design.rst:73
|
|
msgid ""
|
|
"A floating point number's ``repr()`` function prints as many digits are "
|
|
"necessary to make ``eval(repr(f)) == f`` true for any float f. The "
|
|
"``str()`` function prints fewer digits and this often results in the more "
|
|
"sensible number that was probably intended::"
|
|
msgstr ""
|
|
"La fonction ``repr()`` d'un nombre décimal affiche autant de chiffres que "
|
|
"nécessaire pour rendre l'expression ``eval(repr(f)) == f`` vraie pour tout "
|
|
"nombre décimal f. La fonction ``str()`` affiche moins de chiffres et "
|
|
"correspond généralement plus au nombre attendu ::"
|
|
|
|
#: ../src/Doc/faq/design.rst:83
|
|
msgid ""
|
|
"One of the consequences of this is that it is error-prone to compare the "
|
|
"result of some computation to a float with ``==``. Tiny inaccuracies may "
|
|
"mean that ``==`` fails. Instead, you have to check that the difference "
|
|
"between the two numbers is less than a certain threshold::"
|
|
msgstr ""
|
|
"En conséquence comparer le résultat d'un calcul avec un nombre flottant "
|
|
"avec l'opérateur '==' est propice à l'obtention d'erreurs. D'infimes "
|
|
"imprécisions peuvent faire qu'un test d'égalité avec \"==\" échoue. Au lieu "
|
|
"de cela, vous devez vérifier que la différence entre les deux chiffres est "
|
|
"inférieure à un certain seuil ::"
|
|
|
|
#: ../src/Doc/faq/design.rst:94
|
|
msgid ""
|
|
"Please see the chapter on :ref:`floating point arithmetic <tut-fp-issues>` "
|
|
"in the Python tutorial for more information."
|
|
msgstr ""
|
|
"Veuillez vous référer au chapitre sur :ref:`floating point arithmetic <tut-"
|
|
"fp-issues>` du tutoriel python pour de plus amples informations."
|
|
|
|
#: ../src/Doc/faq/design.rst:99
|
|
msgid "Why are Python strings immutable?"
|
|
msgstr "Pourquoi les chaînes de caractères Python sont-elles immuable ?"
|
|
|
|
#: ../src/Doc/faq/design.rst:101
|
|
msgid "There are several advantages."
|
|
msgstr "Il y a plusieurs avantages."
|
|
|
|
#: ../src/Doc/faq/design.rst:103
|
|
msgid ""
|
|
"One is performance: knowing that a string is immutable means we can allocate "
|
|
"space for it at creation time, and the storage requirements are fixed and "
|
|
"unchanging. This is also one of the reasons for the distinction between "
|
|
"tuples and lists."
|
|
msgstr ""
|
|
"La première concerne la performance : savoir qu'une chaîne de caractères est "
|
|
"immuable signifie que l'allocation mémoire allouée lors de la création de "
|
|
"cette chaîne est fixe et figé. C'est aussi l'une des raisons pour lesquelles "
|
|
"on fait la distinction entre les tuples et les listes."
|
|
|
|
#: ../src/Doc/faq/design.rst:108
|
|
msgid ""
|
|
"Another advantage is that strings in Python are considered as \"elemental\" "
|
|
"as numbers. No amount of activity will change the value 8 to anything else, "
|
|
"and in Python, no amount of activity will change the string \"eight\" to "
|
|
"anything else."
|
|
msgstr ""
|
|
"Un autre avantage est que les chaînes en Python sont considérées aussi "
|
|
"\"élémentaires\" que les nombres. Aucun processus ne changera la valeur du "
|
|
"nombre 8 en autre chose, et en Python, aucun processus changera la chaîne de "
|
|
"caractère \"huit\" en autre chose."
|
|
|
|
#: ../src/Doc/faq/design.rst:116
|
|
msgid "Why must 'self' be used explicitly in method definitions and calls?"
|
|
msgstr ""
|
|
"Pourquoi \"self\" doit-il être explicitement utilisé dans les définitions et "
|
|
"les appels de méthode ?"
|
|
|
|
#: ../src/Doc/faq/design.rst:118
|
|
msgid ""
|
|
"The idea was borrowed from Modula-3. It turns out to be very useful, for a "
|
|
"variety of reasons."
|
|
msgstr ""
|
|
"L'idée a été empruntée à Modula-3. Il s'avère être très utile, pour diverses "
|
|
"raisons."
|
|
|
|
#: ../src/Doc/faq/design.rst:121
|
|
msgid ""
|
|
"First, it's more obvious that you are using a method or instance attribute "
|
|
"instead of a local variable. Reading ``self.x`` or ``self.meth()`` makes it "
|
|
"absolutely clear that an instance variable or method is used even if you "
|
|
"don't know the class definition by heart. In C++, you can sort of tell by "
|
|
"the lack of a local variable declaration (assuming globals are rare or "
|
|
"easily recognizable) -- but in Python, there are no local variable "
|
|
"declarations, so you'd have to look up the class definition to be sure. "
|
|
"Some C++ and Java coding standards call for instance attributes to have an "
|
|
"``m_`` prefix, so this explicitness is still useful in those languages, too."
|
|
msgstr ""
|
|
"Tout d'abord, il est plus évident d'utiliser une méthode ou un attribut "
|
|
"d'instance par exemple au lieu d'une variable locale. Lire ``self.x`` ou "
|
|
"``self.meth()`` est sans ambiguité sur le fait que c'est une variable "
|
|
"d'instance ou une méthode qui est utilisée, même si vous ne connaissez pas "
|
|
"la définition de classe par cœur. En C++, vous pouvez les reconnaitre par "
|
|
"l'absence d'une déclaration de variable locale (en supposant que les "
|
|
"variables globales sont rares ou facilement reconnaissables) - mais en "
|
|
"Python, il n'y a pas de déclarations de variables locales, de sorte que vous "
|
|
"devez chercher la définition de classe pour être sûr. Certaines normes de "
|
|
"codages C++ et Java préfixent les attributs d'instance par ``m_``. Cette "
|
|
"syntaxe explicite est ainsi utile également pour ces langages."
|
|
|
|
#: ../src/Doc/faq/design.rst:131
|
|
msgid ""
|
|
"Second, it means that no special syntax is necessary if you want to "
|
|
"explicitly reference or call the method from a particular class. In C++, if "
|
|
"you want to use a method from a base class which is overridden in a derived "
|
|
"class, you have to use the ``::`` operator -- in Python you can write "
|
|
"``baseclass.methodname(self, <argument list>)``. This is particularly "
|
|
"useful for :meth:`__init__` methods, and in general in cases where a derived "
|
|
"class method wants to extend the base class method of the same name and thus "
|
|
"has to call the base class method somehow."
|
|
msgstr ""
|
|
"Ensuite, ça veut dire qu'aucune syntaxe spéciale n'est nécessaire si vous "
|
|
"souhaitez explicitement référencer ou appeler la méthode depuis une classe "
|
|
"en particulier. En C++, si vous utilisez la méthode d'une classe de base "
|
|
"elle-même surchargée par une classe dérivée, vous devez utiliser l'opérateur "
|
|
"``::`` -- en Python vous pouvez écrire ``baseclass.methodname(self, "
|
|
"<argument list>)``. C'est particulièrement utile pour les méthodes :meth:"
|
|
"`__init__`, et de manière générale dans les cas où une classe dérivée veut "
|
|
"étendre la méthode du même nom de la classe de base, devant ainsi appeler la "
|
|
"méthode de la classe de base d'une certaine manière."
|
|
|
|
#: ../src/Doc/faq/design.rst:140
|
|
msgid ""
|
|
"Finally, for instance variables it solves a syntactic problem with "
|
|
"assignment: since local variables in Python are (by definition!) those "
|
|
"variables to which a value is assigned in a function body (and that aren't "
|
|
"explicitly declared global), there has to be some way to tell the "
|
|
"interpreter that an assignment was meant to assign to an instance variable "
|
|
"instead of to a local variable, and it should preferably be syntactic (for "
|
|
"efficiency reasons). C++ does this through declarations, but Python doesn't "
|
|
"have declarations and it would be a pity having to introduce them just for "
|
|
"this purpose. Using the explicit ``self.var`` solves this nicely. "
|
|
"Similarly, for using instance variables, having to write ``self.var`` means "
|
|
"that references to unqualified names inside a method don't have to search "
|
|
"the instance's directories. To put it another way, local variables and "
|
|
"instance variables live in two different namespaces, and you need to tell "
|
|
"Python which namespace to use."
|
|
msgstr ""
|
|
"Enfin, pour des variables d'instance, ça résout un problème syntactique pour "
|
|
"l'assignation : puisque les variables locales en Python sont (par "
|
|
"définition !) ces variables auxquelles les valeurs sont assignées dans le "
|
|
"corps d'une fonction (et n'étant pas déclarées explicitement globales), il "
|
|
"doit y avoir un moyen de dire à l'interpréteur qu'une assignation est censée "
|
|
"assigner une variable d'instance plutôt qu'une variable locale, et doit de "
|
|
"préférence être syntactique (pour des raisons d'efficacité). C++ fait ça au "
|
|
"travers de déclarations, mais Python n'a pas de déclarations et ça serait "
|
|
"dommage d'avoir à les introduire juste pour cette raison. Utiliser "
|
|
"explicitement ``self.var`` résout ça avec élégance. Pareillement, pour "
|
|
"utiliser des variables d'instance, avoir à écrire ``self.var`` signifie que "
|
|
"les références vers des noms non-qualifiés au sein d'une méthode n'ont pas à "
|
|
"être cherchés dans l'annuaire d'instances. En d'autres termes, les variables "
|
|
"locales et les variables d'instance vivent dans deux différents espaces de "
|
|
"noms, et vous devez dire à Python quel espace de noms utiliser."
|
|
|
|
#: ../src/Doc/faq/design.rst:156
|
|
msgid "Why can't I use an assignment in an expression?"
|
|
msgstr "Pourquoi ne puis-je pas utiliser d'assignation dans une expression ?"
|
|
|
|
#: ../src/Doc/faq/design.rst:158
|
|
msgid ""
|
|
"Many people used to C or Perl complain that they want to use this C idiom:"
|
|
msgstr ""
|
|
"De nombreuses personnes habituées à C ou Perl se plaignent de vouloir "
|
|
"utiliser cet idiome C :"
|
|
|
|
#: ../src/Doc/faq/design.rst:166
|
|
msgid "where in Python you're forced to write this::"
|
|
msgstr "où en Python vous êtes forcé à écrire ceci ::"
|
|
|
|
#: ../src/Doc/faq/design.rst:174
|
|
msgid ""
|
|
"The reason for not allowing assignment in Python expressions is a common, "
|
|
"hard-to-find bug in those other languages, caused by this construct:"
|
|
msgstr ""
|
|
"La raison pour ne pas autoriser l'assignation dans les expressions en Python "
|
|
"est un bug fréquent, et difficile à trouver dans ces autres langages, causé "
|
|
"par cette construction :"
|
|
|
|
#: ../src/Doc/faq/design.rst:186
|
|
msgid ""
|
|
"The error is a simple typo: ``x = 0``, which assigns 0 to the variable "
|
|
"``x``, was written while the comparison ``x == 0`` is certainly what was "
|
|
"intended."
|
|
msgstr ""
|
|
"Cette erreur est une simple coquille : ``x = 0``, qui assigne 0 à la "
|
|
"variable ``x``, a été écrit alors que la comparaison ``x == 0`` est "
|
|
"certainement ce qui était souhaité."
|
|
|
|
#: ../src/Doc/faq/design.rst:189
|
|
msgid ""
|
|
"Many alternatives have been proposed. Most are hacks that save some typing "
|
|
"but use arbitrary or cryptic syntax or keywords, and fail the simple "
|
|
"criterion for language change proposals: it should intuitively suggest the "
|
|
"proper meaning to a human reader who has not yet been introduced to the "
|
|
"construct."
|
|
msgstr ""
|
|
"De nombreuses alternatives ont été proposées. La plupart des hacks "
|
|
"économisaient de la frappe mais utilisaient d'arbitraires ou cryptiques "
|
|
"syntaxes ou mot-clés et faillait le simple critère pour proposition de "
|
|
"changement du langage : ça doit intuitivement suggérer la bonne "
|
|
"signification au lecteur qui n'a pas encore été introduit à la construction."
|
|
|
|
#: ../src/Doc/faq/design.rst:194
|
|
msgid ""
|
|
"An interesting phenomenon is that most experienced Python programmers "
|
|
"recognize the ``while True`` idiom and don't seem to be missing the "
|
|
"assignment in expression construct much; it's only newcomers who express a "
|
|
"strong desire to add this to the language."
|
|
msgstr ""
|
|
"Un phénomène intéressant est que la plupart des programmeurs Python "
|
|
"expérimentés reconnaissent l'idiome ``while True`` et ne semblent pas "
|
|
"manquer l'assignation dans la construction de l'expression; seuls les "
|
|
"nouveaux-venus expriment un fort désir d'ajouter ceci au langage."
|
|
|
|
#: ../src/Doc/faq/design.rst:199
|
|
msgid ""
|
|
"There's an alternative way of spelling this that seems attractive but is "
|
|
"generally less robust than the \"while True\" solution::"
|
|
msgstr ""
|
|
"Il y a une manière alternative de faire ça qui semble attrayante mais elle "
|
|
"est généralement moins robuste que la solution ``while True`` ::"
|
|
|
|
#: ../src/Doc/faq/design.rst:207
|
|
msgid ""
|
|
"The problem with this is that if you change your mind about exactly how you "
|
|
"get the next line (e.g. you want to change it into ``sys.stdin.readline()``) "
|
|
"you have to remember to change two places in your program -- the second "
|
|
"occurrence is hidden at the bottom of the loop."
|
|
msgstr ""
|
|
"Le problème avec ceci est que si vous changez d'avis sur la manière dont "
|
|
"vous allez récupérer la prochaine ligne (ex : vous voulez changer en ``sys."
|
|
"stdin.readline()``) vous devez vous souvenir de le changer à deux endroits "
|
|
"dans votre programme -- la deuxième occurrence est cachée en bas de la "
|
|
"boucle."
|
|
|
|
#: ../src/Doc/faq/design.rst:212
|
|
msgid ""
|
|
"The best approach is to use iterators, making it possible to loop through "
|
|
"objects using the ``for`` statement. For example, in the current version of "
|
|
"Python file objects support the iterator protocol, so you can now write "
|
|
"simply::"
|
|
msgstr ""
|
|
"La meilleur approche est d'utiliser les itérateurs, rendant possible de "
|
|
"boucler au travers d'objets en utilisant la déclaration ``for``. Par "
|
|
"exemple, dans la version actuelle de Python, les fichiers objets supportent "
|
|
"le protocole d'itérateur, vous pouvez alors simplement écrire ::"
|
|
|
|
#: ../src/Doc/faq/design.rst:222
|
|
msgid ""
|
|
"Why does Python use methods for some functionality (e.g. list.index()) but "
|
|
"functions for other (e.g. len(list))?"
|
|
msgstr ""
|
|
"Pourquoi Python utilise des méthodes pour certaines fonctionnalités (ex : "
|
|
"list.index()) mais des fonctions pour d'autres (ex : len(list)) ?"
|
|
|
|
#: ../src/Doc/faq/design.rst:224
|
|
#, fuzzy
|
|
msgid ""
|
|
"The major reason is history. Functions were used for those operations that "
|
|
"were generic for a group of types and which were intended to work even for "
|
|
"objects that didn't have methods at all (e.g. tuples). It is also "
|
|
"convenient to have a function that can readily be applied to an amorphous "
|
|
"collection of objects when you use the functional features of Python "
|
|
"(``map()``, ``zip()`` et al)."
|
|
msgstr ""
|
|
"La raison principale est historique. Les fonctions étaient utilisées pour "
|
|
"ces opérations qui étaient génériques pour un groupe de types et qui étaient "
|
|
"censés fonctionner même pour les objets qui n'avaient pas de méthodes du "
|
|
"tout (ex : tuples). C'est aussi pratique d'avoir une fonction qui s'apprête "
|
|
"bien à une collection amorphe d'objets lorsque vous utiliser les "
|
|
"fonctionnalités fonctionnelles de Python (``map()``, ``apply()`` et autres)."
|
|
|
|
#: ../src/Doc/faq/design.rst:230
|
|
msgid ""
|
|
"In fact, implementing ``len()``, ``max()``, ``min()`` as a built-in function "
|
|
"is actually less code than implementing them as methods for each type. One "
|
|
"can quibble about individual cases but it's a part of Python, and it's too "
|
|
"late to make such fundamental changes now. The functions have to remain to "
|
|
"avoid massive code breakage."
|
|
msgstr ""
|
|
"En fait, implémenter ``len()``, ``max()``, ``min()`` en tant que fonction "
|
|
"intégrée produit moins de code que de les implémenter en tant que méthode "
|
|
"pour chaque type. Certains peuvent rouspéter pour des cas individuels mais "
|
|
"ça fait partie de Python et il est trop tard pour faire des changements si "
|
|
"fondamentaux maintenant. Ces fonctions doivent rester pour éviter la casse "
|
|
"massive de code."
|
|
|
|
#: ../src/Doc/faq/design.rst:240
|
|
msgid ""
|
|
"For string operations, Python has moved from external functions (the "
|
|
"``string`` module) to methods. However, ``len()`` is still a function."
|
|
msgstr ""
|
|
"Pour les opérations de chaînes, Python a déplacé les fonctions externes (le "
|
|
"module ``string``) vers des méthodes. Cependant, ``len()`` est toujours une "
|
|
"fonction."
|
|
|
|
#: ../src/Doc/faq/design.rst:245
|
|
msgid "Why is join() a string method instead of a list or tuple method?"
|
|
msgstr ""
|
|
"Pourquoi join() est une méthode de chaîne plutôt qu'une de liste ou de "
|
|
"tuple ?"
|
|
|
|
#: ../src/Doc/faq/design.rst:247
|
|
msgid ""
|
|
"Strings became much more like other standard types starting in Python 1.6, "
|
|
"when methods were added which give the same functionality that has always "
|
|
"been available using the functions of the string module. Most of these new "
|
|
"methods have been widely accepted, but the one which appears to make some "
|
|
"programmers feel uncomfortable is::"
|
|
msgstr ""
|
|
"Les chaînes sont devenues bien plus comme d'autres types standards à partir "
|
|
"de Python 1.6, lorsque les méthodes ont été ajoutées fournissant ainsi les "
|
|
"mêmes fonctionnalités que celles qui étaient déjà disponibles en utilisant "
|
|
"les fonctions du module string. La plupart de ces nouvelles méthodes ont été "
|
|
"largement acceptées, mais celle qui semble rendre certains programmeurs "
|
|
"inconfortables est ::"
|
|
|
|
#: ../src/Doc/faq/design.rst:255
|
|
msgid "which gives the result::"
|
|
msgstr "qui donne le résultat ::"
|
|
|
|
#: ../src/Doc/faq/design.rst:259
|
|
msgid "There are two common arguments against this usage."
|
|
msgstr "Il y a deux arguments fréquents contre cet usage."
|
|
|
|
#: ../src/Doc/faq/design.rst:261
|
|
msgid ""
|
|
"The first runs along the lines of: \"It looks really ugly using a method of "
|
|
"a string literal (string constant)\", to which the answer is that it might, "
|
|
"but a string literal is just a fixed value. If the methods are to be allowed "
|
|
"on names bound to strings there is no logical reason to make them "
|
|
"unavailable on literals."
|
|
msgstr ""
|
|
"Le premier se caractérise par les lignes suivantes : \"C'est vraiment moche "
|
|
"d'utiliser une méthode de chaîne littérale (chaîne constante)\", à laquelle "
|
|
"la réponse est qu'il se peut, mais une chaîne littérale est juste une valeur "
|
|
"fixe. Si la méthode est autorisée sur des noms liés à des chaînes, il n'y a "
|
|
"pas de raison logique à les rendre indisponibles sur des chaînes littérales."
|
|
|
|
#: ../src/Doc/faq/design.rst:267
|
|
msgid ""
|
|
"The second objection is typically cast as: \"I am really telling a sequence "
|
|
"to join its members together with a string constant\". Sadly, you aren't. "
|
|
"For some reason there seems to be much less difficulty with having :meth:"
|
|
"`~str.split` as a string method, since in that case it is easy to see that ::"
|
|
msgstr ""
|
|
"La deuxième objection se réfère typiquement à : \"Je suis réellement en "
|
|
"train de dire à une séquence de joindre ses membres avec une constante de "
|
|
"chaîne\". Malheureusement, vous ne l'êtes pas. Pour quelque raison, il "
|
|
"semble être bien moins difficile d'avoir :meth:`~str.split` en tant que "
|
|
"méthode de chaîne, puisque dans ce cas il est facile de voir que ::"
|
|
|
|
#: ../src/Doc/faq/design.rst:274
|
|
#, fuzzy
|
|
msgid ""
|
|
"is an instruction to a string literal to return the substrings delimited by "
|
|
"the given separator (or, by default, arbitrary runs of white space). In "
|
|
"this case a Unicode string returns a list of Unicode strings, an ASCII "
|
|
"string returns a list of ASCII strings, and everyone is happy."
|
|
msgstr ""
|
|
"est une instruction à une chaîne littérale de retourner les sous-chaînes "
|
|
"délimitées par le séparateur fournit (ou, par défaut, les espaces)."
|
|
|
|
#: ../src/Doc/faq/design.rst:279
|
|
#, fuzzy
|
|
msgid ""
|
|
":meth:`~str.join` is a string method because in using it you are telling the "
|
|
"separator string to iterate over a sequence of strings and insert itself "
|
|
"between adjacent elements. This method can be used with any argument which "
|
|
"obeys the rules for sequence objects, including any new classes you might "
|
|
"define yourself."
|
|
msgstr ""
|
|
":meth:`~str.join` est une méthode de chaîne parce qu'en l'utilisant vous "
|
|
"dites au séparateur de chaîne d'itérer autour d'une séquence de chaînes et "
|
|
"de s'insérer entre les éléments adjacents. Cette méthode peut être utilisée "
|
|
"avec n'importe quel argument qui obéit aux règles d'objets séquence, "
|
|
"incluant n'importe quelles nouvelles classes que vous pourriez définir vous-"
|
|
"même. Des méthodes similaires existent pour des objets bytes et bytearray."
|
|
|
|
# bc8c48cf76c84ee28d8f5af935ed1be1
|
|
#: ../src/Doc/faq/design.rst:284
|
|
msgid ""
|
|
"Because this is a string method it can work for Unicode strings as well as "
|
|
"plain ASCII strings. If ``join()`` were a method of the sequence types then "
|
|
"the sequence types would have to decide which type of string to return "
|
|
"depending on the type of the separator."
|
|
msgstr ""
|
|
|
|
# 782a63ed666f4337b589ba793330c154
|
|
#: ../src/Doc/faq/design.rst:291
|
|
msgid ""
|
|
"If none of these arguments persuade you, then for the moment you can "
|
|
"continue to use the ``join()`` function from the string module, which allows "
|
|
"you to write ::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:298
|
|
msgid "How fast are exceptions?"
|
|
msgstr ""
|
|
|
|
# b6f0277dd5004985a79e89b89ea52fec
|
|
#: ../src/Doc/faq/design.rst:300
|
|
msgid ""
|
|
"A try/except block is extremely efficient if no exceptions are raised. "
|
|
"Actually catching an exception is expensive. In versions of Python prior to "
|
|
"2.0 it was common to use this idiom::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:310
|
|
msgid ""
|
|
"This only made sense when you expected the dict to have the key almost all "
|
|
"the time. If that wasn't the case, you coded it like this::"
|
|
msgstr ""
|
|
|
|
# 84b13a622f3547d993c38485fa698d55
|
|
#: ../src/Doc/faq/design.rst:320
|
|
msgid ""
|
|
"In Python 2.0 and higher, you can code this as ``value = mydict."
|
|
"setdefault(key, getvalue(key))``."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:325
|
|
msgid "Why isn't there a switch or case statement in Python?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:327
|
|
msgid ""
|
|
"You can do this easily enough with a sequence of ``if... elif... elif... "
|
|
"else``. There have been some proposals for switch statement syntax, but "
|
|
"there is no consensus (yet) on whether and how to do range tests. See :pep:"
|
|
"`275` for complete details and the current status."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:332
|
|
msgid ""
|
|
"For cases where you need to choose from a very large number of "
|
|
"possibilities, you can create a dictionary mapping case values to functions "
|
|
"to call. For example::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:346
|
|
msgid ""
|
|
"For calling methods on objects, you can simplify yet further by using the :"
|
|
"func:`getattr` built-in to retrieve methods with a particular name::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:358
|
|
msgid ""
|
|
"It's suggested that you use a prefix for the method names, such as "
|
|
"``visit_`` in this example. Without such a prefix, if values are coming "
|
|
"from an untrusted source, an attacker would be able to call any method on "
|
|
"your object."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:364
|
|
msgid ""
|
|
"Can't you emulate threads in the interpreter instead of relying on an OS-"
|
|
"specific thread implementation?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:366
|
|
msgid ""
|
|
"Answer 1: Unfortunately, the interpreter pushes at least one C stack frame "
|
|
"for each Python stack frame. Also, extensions can call back into Python at "
|
|
"almost random moments. Therefore, a complete threads implementation "
|
|
"requires thread support for C."
|
|
msgstr ""
|
|
|
|
# 90c31368a54d47e599f0c7a62ff060e5
|
|
#: ../src/Doc/faq/design.rst:371
|
|
msgid ""
|
|
"Answer 2: Fortunately, there is `Stackless Python <http://www.stackless."
|
|
"com>`_, which has a completely redesigned interpreter loop that avoids the C "
|
|
"stack."
|
|
msgstr ""
|
|
|
|
# 9d39032c5cef4182b90f76f54e892445
|
|
#: ../src/Doc/faq/design.rst:376
|
|
msgid "Why can't lambda expressions contain statements?"
|
|
msgstr ""
|
|
|
|
# 2ad3f5f006c2486191151cca91d654d6
|
|
#: ../src/Doc/faq/design.rst:378
|
|
msgid ""
|
|
"Python lambda expressions cannot contain statements because Python's "
|
|
"syntactic framework can't handle statements nested inside expressions. "
|
|
"However, in Python, this is not a serious problem. Unlike lambda forms in "
|
|
"other languages, where they add functionality, Python lambdas are only a "
|
|
"shorthand notation if you're too lazy to define a function."
|
|
msgstr ""
|
|
|
|
# 159c73c109504f54bc8287595f3e3650
|
|
#: ../src/Doc/faq/design.rst:384
|
|
msgid ""
|
|
"Functions are already first class objects in Python, and can be declared in "
|
|
"a local scope. Therefore the only advantage of using a lambda instead of a "
|
|
"locally-defined function is that you don't need to invent a name for the "
|
|
"function -- but that's just a local variable to which the function object "
|
|
"(which is exactly the same type of object that a lambda expression yields) "
|
|
"is assigned!"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:392
|
|
msgid "Can Python be compiled to machine code, C or some other language?"
|
|
msgstr ""
|
|
|
|
# 4de1ffd8c7e74c52acedce7311a5a494
|
|
#: ../src/Doc/faq/design.rst:394
|
|
msgid ""
|
|
"Not easily. Python's high level data types, dynamic typing of objects and "
|
|
"run-time invocation of the interpreter (using :func:`eval` or :keyword:"
|
|
"`exec`) together mean that a \"compiled\" Python program would probably "
|
|
"consist mostly of calls into the Python run-time system, even for seemingly "
|
|
"simple operations like ``x+1``."
|
|
msgstr ""
|
|
|
|
# 6688fdbd52584526b8c5e61dbb5cdc7a
|
|
#: ../src/Doc/faq/design.rst:400
|
|
msgid ""
|
|
"Several projects described in the Python newsgroup or at past `Python "
|
|
"conferences <https://www.python.org/community/workshops/>`_ have shown that "
|
|
"this approach is feasible, although the speedups reached so far are only "
|
|
"modest (e.g. 2x). Jython uses the same strategy for compiling to Java "
|
|
"bytecode. (Jim Hugunin has demonstrated that in combination with whole-"
|
|
"program analysis, speedups of 1000x are feasible for small demo programs. "
|
|
"See the proceedings from the `1997 Python conference <http://legacy.python."
|
|
"org/workshops/1997-10/proceedings/>`_ for more information.)"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:409
|
|
msgid ""
|
|
"Internally, Python source code is always translated into a bytecode "
|
|
"representation, and this bytecode is then executed by the Python virtual "
|
|
"machine. In order to avoid the overhead of repeatedly parsing and "
|
|
"translating modules that rarely change, this byte code is written into a "
|
|
"file whose name ends in \".pyc\" whenever a module is parsed. When the "
|
|
"corresponding .py file is changed, it is parsed and translated again and "
|
|
"the .pyc file is rewritten."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:416
|
|
msgid ""
|
|
"There is no performance difference once the .pyc file has been loaded, as "
|
|
"the bytecode read from the .pyc file is exactly the same as the bytecode "
|
|
"created by direct translation. The only difference is that loading code "
|
|
"from a .pyc file is faster than parsing and translating a .py file, so the "
|
|
"presence of precompiled .pyc files improves the start-up time of Python "
|
|
"scripts. If desired, the Lib/compileall.py module can be used to create "
|
|
"valid .pyc files for a given set of modules."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:424
|
|
msgid ""
|
|
"Note that the main script executed by Python, even if its filename ends in ."
|
|
"py, is not compiled to a .pyc file. It is compiled to bytecode, but the "
|
|
"bytecode is not saved to a file. Usually main scripts are quite short, so "
|
|
"this doesn't cost much speed."
|
|
msgstr ""
|
|
|
|
# cad7dbb80cab46a0ac25bd124a5ae308
|
|
#: ../src/Doc/faq/design.rst:431
|
|
msgid ""
|
|
"There are also several programs which make it easier to intermingle Python "
|
|
"and C code in various ways to increase performance. See, for example, "
|
|
"`Cython <http://cython.org/>`_ , `Psyco <http://psyco.sourceforge.net/>`_, "
|
|
"`Pyrex <http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/>`_, `PyInline "
|
|
"<http://pyinline.sourceforge.net/>`_, `Py2Cmod <http://sourceforge.net/"
|
|
"projects/py2cmod/>`_, and `Weave <http://docs.scipy.org/doc/scipy-dev/"
|
|
"reference/tutorial/weave.html>`_."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:441
|
|
msgid "How does Python manage memory?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:443
|
|
msgid ""
|
|
"The details of Python memory management depend on the implementation. The "
|
|
"standard C implementation of Python uses reference counting to detect "
|
|
"inaccessible objects, and another mechanism to collect reference cycles, "
|
|
"periodically executing a cycle detection algorithm which looks for "
|
|
"inaccessible cycles and deletes the objects involved. The :mod:`gc` module "
|
|
"provides functions to perform a garbage collection, obtain debugging "
|
|
"statistics, and tune the collector's parameters."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:451
|
|
msgid ""
|
|
"Jython relies on the Java runtime so the JVM's garbage collector is used. "
|
|
"This difference can cause some subtle porting problems if your Python code "
|
|
"depends on the behavior of the reference counting implementation."
|
|
msgstr ""
|
|
|
|
# 10bafb17f7824b78b845e7dbc318d8db
|
|
#: ../src/Doc/faq/design.rst:457
|
|
msgid ""
|
|
"Sometimes objects get stuck in tracebacks temporarily and hence are not "
|
|
"deallocated when you might expect. Clear the tracebacks with::"
|
|
msgstr ""
|
|
|
|
# 6f33da00d80d46bebfeb3ef2cf98b43a
|
|
#: ../src/Doc/faq/design.rst:464
|
|
msgid ""
|
|
"Tracebacks are used for reporting errors, implementing debuggers and related "
|
|
"things. They contain a portion of the program state extracted during the "
|
|
"handling of an exception (usually the most recent exception)."
|
|
msgstr ""
|
|
|
|
# 3d80990eb0854adc91be5e05e67a9cc5
|
|
#: ../src/Doc/faq/design.rst:468
|
|
msgid ""
|
|
"In the absence of circularities and tracebacks, Python programs do not need "
|
|
"to manage memory explicitly."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:471
|
|
msgid ""
|
|
"Why doesn't Python use a more traditional garbage collection scheme? For "
|
|
"one thing, this is not a C standard feature and hence it's not portable. "
|
|
"(Yes, we know about the Boehm GC library. It has bits of assembler code for "
|
|
"*most* common platforms, not for all of them, and although it is mostly "
|
|
"transparent, it isn't completely transparent; patches are required to get "
|
|
"Python to work with it.)"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:478
|
|
msgid ""
|
|
"Traditional GC also becomes a problem when Python is embedded into other "
|
|
"applications. While in a standalone Python it's fine to replace the "
|
|
"standard malloc() and free() with versions provided by the GC library, an "
|
|
"application embedding Python may want to have its *own* substitute for "
|
|
"malloc() and free(), and may not want Python's. Right now, Python works "
|
|
"with anything that implements malloc() and free() properly."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:485
|
|
msgid ""
|
|
"In Jython, the following code (which is fine in CPython) will probably run "
|
|
"out of file descriptors long before it runs out of memory::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:492
|
|
msgid ""
|
|
"Using the current reference counting and destructor scheme, each new "
|
|
"assignment to f closes the previous file. Using GC, this is not "
|
|
"guaranteed. If you want to write code that will work with any Python "
|
|
"implementation, you should explicitly close the file or use the :keyword:"
|
|
"`with` statement; this will work regardless of GC::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:504
|
|
msgid "Why isn't all memory freed when Python exits?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:506
|
|
msgid ""
|
|
"Objects referenced from the global namespaces of Python modules are not "
|
|
"always deallocated when Python exits. This may happen if there are circular "
|
|
"references. There are also certain bits of memory that are allocated by the "
|
|
"C library that are impossible to free (e.g. a tool like Purify will complain "
|
|
"about these). Python is, however, aggressive about cleaning up memory on "
|
|
"exit and does try to destroy every single object."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:513
|
|
msgid ""
|
|
"If you want to force Python to delete certain things on deallocation use "
|
|
"the :mod:`atexit` module to run a function that will force those deletions."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:518
|
|
msgid "Why are there separate tuple and list data types?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:520
|
|
msgid ""
|
|
"Lists and tuples, while similar in many respects, are generally used in "
|
|
"fundamentally different ways. Tuples can be thought of as being similar to "
|
|
"Pascal records or C structs; they're small collections of related data which "
|
|
"may be of different types which are operated on as a group. For example, a "
|
|
"Cartesian coordinate is appropriately represented as a tuple of two or three "
|
|
"numbers."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:527
|
|
msgid ""
|
|
"Lists, on the other hand, are more like arrays in other languages. They "
|
|
"tend to hold a varying number of objects all of which have the same type and "
|
|
"which are operated on one-by-one. For example, ``os.listdir('.')`` returns "
|
|
"a list of strings representing the files in the current directory. "
|
|
"Functions which operate on this output would generally not break if you "
|
|
"added another file or two to the directory."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:534
|
|
msgid ""
|
|
"Tuples are immutable, meaning that once a tuple has been created, you can't "
|
|
"replace any of its elements with a new value. Lists are mutable, meaning "
|
|
"that you can always change a list's elements. Only immutable elements can "
|
|
"be used as dictionary keys, and hence only tuples and not lists can be used "
|
|
"as keys."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:541
|
|
msgid "How are lists implemented?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:543
|
|
msgid ""
|
|
"Python's lists are really variable-length arrays, not Lisp-style linked "
|
|
"lists. The implementation uses a contiguous array of references to other "
|
|
"objects, and keeps a pointer to this array and the array's length in a list "
|
|
"head structure."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:547
|
|
msgid ""
|
|
"This makes indexing a list ``a[i]`` an operation whose cost is independent "
|
|
"of the size of the list or the value of the index."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:550
|
|
msgid ""
|
|
"When items are appended or inserted, the array of references is resized. "
|
|
"Some cleverness is applied to improve the performance of appending items "
|
|
"repeatedly; when the array must be grown, some extra space is allocated so "
|
|
"the next few times don't require an actual resize."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:557
|
|
msgid "How are dictionaries implemented?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:559
|
|
msgid ""
|
|
"Python's dictionaries are implemented as resizable hash tables. Compared to "
|
|
"B-trees, this gives better performance for lookup (the most common operation "
|
|
"by far) under most circumstances, and the implementation is simpler."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:563
|
|
msgid ""
|
|
"Dictionaries work by computing a hash code for each key stored in the "
|
|
"dictionary using the :func:`hash` built-in function. The hash code varies "
|
|
"widely depending on the key; for example, \"Python\" hashes to -539294296 "
|
|
"while \"python\", a string that differs by a single bit, hashes to "
|
|
"1142331976. The hash code is then used to calculate a location in an "
|
|
"internal array where the value will be stored. Assuming that you're storing "
|
|
"keys that all have different hash values, this means that dictionaries take "
|
|
"constant time -- O(1), in computer science notation -- to retrieve a key. "
|
|
"It also means that no sorted order of the keys is maintained, and traversing "
|
|
"the array as the ``.keys()`` and ``.items()`` do will output the "
|
|
"dictionary's content in some arbitrary jumbled order."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:576
|
|
msgid "Why must dictionary keys be immutable?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:578
|
|
msgid ""
|
|
"The hash table implementation of dictionaries uses a hash value calculated "
|
|
"from the key value to find the key. If the key were a mutable object, its "
|
|
"value could change, and thus its hash could also change. But since whoever "
|
|
"changes the key object can't tell that it was being used as a dictionary "
|
|
"key, it can't move the entry around in the dictionary. Then, when you try "
|
|
"to look up the same object in the dictionary it won't be found because its "
|
|
"hash value is different. If you tried to look up the old value it wouldn't "
|
|
"be found either, because the value of the object found in that hash bin "
|
|
"would be different."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:587
|
|
msgid ""
|
|
"If you want a dictionary indexed with a list, simply convert the list to a "
|
|
"tuple first; the function ``tuple(L)`` creates a tuple with the same entries "
|
|
"as the list ``L``. Tuples are immutable and can therefore be used as "
|
|
"dictionary keys."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:591
|
|
msgid "Some unacceptable solutions that have been proposed:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:593
|
|
msgid ""
|
|
"Hash lists by their address (object ID). This doesn't work because if you "
|
|
"construct a new list with the same value it won't be found; e.g.::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:599
|
|
msgid ""
|
|
"would raise a KeyError exception because the id of the ``[1, 2]`` used in "
|
|
"the second line differs from that in the first line. In other words, "
|
|
"dictionary keys should be compared using ``==``, not using :keyword:`is`."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:603
|
|
msgid ""
|
|
"Make a copy when using a list as a key. This doesn't work because the list, "
|
|
"being a mutable object, could contain a reference to itself, and then the "
|
|
"copying code would run into an infinite loop."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:607
|
|
msgid ""
|
|
"Allow lists as keys but tell the user not to modify them. This would allow "
|
|
"a class of hard-to-track bugs in programs when you forgot or modified a list "
|
|
"by accident. It also invalidates an important invariant of dictionaries: "
|
|
"every value in ``d.keys()`` is usable as a key of the dictionary."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:612
|
|
msgid ""
|
|
"Mark lists as read-only once they are used as a dictionary key. The problem "
|
|
"is that it's not just the top-level object that could change its value; you "
|
|
"could use a tuple containing a list as a key. Entering anything as a key "
|
|
"into a dictionary would require marking all objects reachable from there as "
|
|
"read-only -- and again, self-referential objects could cause an infinite "
|
|
"loop."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:618
|
|
msgid ""
|
|
"There is a trick to get around this if you need to, but use it at your own "
|
|
"risk: You can wrap a mutable structure inside a class instance which has "
|
|
"both a :meth:`__eq__` and a :meth:`__hash__` method. You must then make "
|
|
"sure that the hash value for all such wrapper objects that reside in a "
|
|
"dictionary (or other hash based structure), remain fixed while the object is "
|
|
"in the dictionary (or other structure). ::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:640
|
|
msgid ""
|
|
"Note that the hash computation is complicated by the possibility that some "
|
|
"members of the list may be unhashable and also by the possibility of "
|
|
"arithmetic overflow."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:644
|
|
msgid ""
|
|
"Furthermore it must always be the case that if ``o1 == o2`` (ie ``o1."
|
|
"__eq__(o2) is True``) then ``hash(o1) == hash(o2)`` (ie, ``o1.__hash__() == "
|
|
"o2.__hash__()``), regardless of whether the object is in a dictionary or "
|
|
"not. If you fail to meet these restrictions dictionaries and other hash "
|
|
"based structures will misbehave."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:649
|
|
msgid ""
|
|
"In the case of ListWrapper, whenever the wrapper object is in a dictionary "
|
|
"the wrapped list must not change to avoid anomalies. Don't do this unless "
|
|
"you are prepared to think hard about the requirements and the consequences "
|
|
"of not meeting them correctly. Consider yourself warned."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:656
|
|
msgid "Why doesn't list.sort() return the sorted list?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:658
|
|
msgid ""
|
|
"In situations where performance matters, making a copy of the list just to "
|
|
"sort it would be wasteful. Therefore, :meth:`list.sort` sorts the list in "
|
|
"place. In order to remind you of that fact, it does not return the sorted "
|
|
"list. This way, you won't be fooled into accidentally overwriting a list "
|
|
"when you need a sorted copy but also need to keep the unsorted version "
|
|
"around."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:664
|
|
msgid ""
|
|
"In Python 2.4 a new built-in function -- :func:`sorted` -- has been added. "
|
|
"This function creates a new list from a provided iterable, sorts it and "
|
|
"returns it. For example, here's how to iterate over the keys of a "
|
|
"dictionary in sorted order::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:674
|
|
msgid "How do you specify and enforce an interface spec in Python?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:676
|
|
msgid ""
|
|
"An interface specification for a module as provided by languages such as C++ "
|
|
"and Java describes the prototypes for the methods and functions of the "
|
|
"module. Many feel that compile-time enforcement of interface specifications "
|
|
"helps in the construction of large programs."
|
|
msgstr ""
|
|
|
|
# d2ba30372839470fb58835ecfbd8cfe3
|
|
#: ../src/Doc/faq/design.rst:681
|
|
msgid ""
|
|
"Python 2.6 adds an :mod:`abc` module that lets you define Abstract Base "
|
|
"Classes (ABCs). You can then use :func:`isinstance` and :func:`issubclass` "
|
|
"to check whether an instance or a class implements a particular ABC. The :"
|
|
"mod:`collections` module defines a set of useful ABCs such as :class:"
|
|
"`~collections.Iterable`, :class:`~collections.Container`, and :class:"
|
|
"`~collections.MutableMapping`."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:688
|
|
msgid ""
|
|
"For Python, many of the advantages of interface specifications can be "
|
|
"obtained by an appropriate test discipline for components. There is also a "
|
|
"tool, PyChecker, which can be used to find problems due to subclassing."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:692
|
|
msgid ""
|
|
"A good test suite for a module can both provide a regression test and serve "
|
|
"as a module interface specification and a set of examples. Many Python "
|
|
"modules can be run as a script to provide a simple \"self test.\" Even "
|
|
"modules which use complex external interfaces can often be tested in "
|
|
"isolation using trivial \"stub\" emulations of the external interface. The :"
|
|
"mod:`doctest` and :mod:`unittest` modules or third-party test frameworks can "
|
|
"be used to construct exhaustive test suites that exercise every line of code "
|
|
"in a module."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:700
|
|
msgid ""
|
|
"An appropriate testing discipline can help build large complex applications "
|
|
"in Python as well as having interface specifications would. In fact, it can "
|
|
"be better because an interface specification cannot test certain properties "
|
|
"of a program. For example, the :meth:`append` method is expected to add new "
|
|
"elements to the end of some internal list; an interface specification cannot "
|
|
"test that your :meth:`append` implementation will actually do this "
|
|
"correctly, but it's trivial to check this property in a test suite."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:708
|
|
msgid ""
|
|
"Writing test suites is very helpful, and you might want to design your code "
|
|
"with an eye to making it easily tested. One increasingly popular technique, "
|
|
"test-directed development, calls for writing parts of the test suite first, "
|
|
"before you write any of the actual code. Of course Python allows you to be "
|
|
"sloppy and not write test cases at all."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:716
|
|
msgid "Why is there no goto?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:718
|
|
msgid ""
|
|
"You can use exceptions to provide a \"structured goto\" that even works "
|
|
"across function calls. Many feel that exceptions can conveniently emulate "
|
|
"all reasonable uses of the \"go\" or \"goto\" constructs of C, Fortran, and "
|
|
"other languages. For example::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:733
|
|
msgid ""
|
|
"This doesn't allow you to jump into the middle of a loop, but that's usually "
|
|
"considered an abuse of goto anyway. Use sparingly."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:738
|
|
msgid "Why can't raw strings (r-strings) end with a backslash?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:740
|
|
msgid ""
|
|
"More precisely, they can't end with an odd number of backslashes: the "
|
|
"unpaired backslash at the end escapes the closing quote character, leaving "
|
|
"an unterminated string."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:744
|
|
msgid ""
|
|
"Raw strings were designed to ease creating input for processors (chiefly "
|
|
"regular expression engines) that want to do their own backslash escape "
|
|
"processing. Such processors consider an unmatched trailing backslash to be "
|
|
"an error anyway, so raw strings disallow that. In return, they allow you to "
|
|
"pass on the string quote character by escaping it with a backslash. These "
|
|
"rules work well when r-strings are used for their intended purpose."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:751
|
|
msgid ""
|
|
"If you're trying to build Windows pathnames, note that all Windows system "
|
|
"calls accept forward slashes too::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:756
|
|
msgid ""
|
|
"If you're trying to build a pathname for a DOS command, try e.g. one of ::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:764
|
|
msgid "Why doesn't Python have a \"with\" statement for attribute assignments?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:766
|
|
msgid ""
|
|
"Python has a 'with' statement that wraps the execution of a block, calling "
|
|
"code on the entrance and exit from the block. Some language have a "
|
|
"construct that looks like this::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:774
|
|
msgid "In Python, such a construct would be ambiguous."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:776
|
|
msgid ""
|
|
"Other languages, such as Object Pascal, Delphi, and C++, use static types, "
|
|
"so it's possible to know, in an unambiguous way, what member is being "
|
|
"assigned to. This is the main point of static typing -- the compiler "
|
|
"*always* knows the scope of every variable at compile time."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:781
|
|
msgid ""
|
|
"Python uses dynamic types. It is impossible to know in advance which "
|
|
"attribute will be referenced at runtime. Member attributes may be added or "
|
|
"removed from objects on the fly. This makes it impossible to know, from a "
|
|
"simple reading, what attribute is being referenced: a local one, a global "
|
|
"one, or a member attribute?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:787
|
|
msgid "For instance, take the following incomplete snippet::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:793
|
|
msgid ""
|
|
"The snippet assumes that \"a\" must have a member attribute called \"x\". "
|
|
"However, there is nothing in Python that tells the interpreter this. What "
|
|
"should happen if \"a\" is, let us say, an integer? If there is a global "
|
|
"variable named \"x\", will it be used inside the with block? As you see, "
|
|
"the dynamic nature of Python makes such choices much harder."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:799
|
|
msgid ""
|
|
"The primary benefit of \"with\" and similar language features (reduction of "
|
|
"code volume) can, however, easily be achieved in Python by assignment. "
|
|
"Instead of::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:806
|
|
msgid "write this::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:813
|
|
msgid ""
|
|
"This also has the side-effect of increasing execution speed because name "
|
|
"bindings are resolved at run-time in Python, and the second version only "
|
|
"needs to perform the resolution once."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:819
|
|
msgid "Why are colons required for the if/while/def/class statements?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:821
|
|
msgid ""
|
|
"The colon is required primarily to enhance readability (one of the results "
|
|
"of the experimental ABC language). Consider this::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:827
|
|
msgid "versus ::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:832
|
|
msgid ""
|
|
"Notice how the second one is slightly easier to read. Notice further how a "
|
|
"colon sets off the example in this FAQ answer; it's a standard usage in "
|
|
"English."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:835
|
|
msgid ""
|
|
"Another minor reason is that the colon makes it easier for editors with "
|
|
"syntax highlighting; they can look for colons to decide when indentation "
|
|
"needs to be increased instead of having to do a more elaborate parsing of "
|
|
"the program text."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:841
|
|
msgid "Why does Python allow commas at the end of lists and tuples?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:843
|
|
msgid ""
|
|
"Python lets you add a trailing comma at the end of lists, tuples, and "
|
|
"dictionaries::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:854
|
|
msgid "There are several reasons to allow this."
|
|
msgstr ""
|
|
|
|
# 298742dc20444d93965e2fca2825408f
|
|
#: ../src/Doc/faq/design.rst:856
|
|
msgid ""
|
|
"When you have a literal value for a list, tuple, or dictionary spread across "
|
|
"multiple lines, it's easier to add more elements because you don't have to "
|
|
"remember to add a comma to the previous line. The lines can also be "
|
|
"reordered without creating a syntax error."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:861
|
|
msgid ""
|
|
"Accidentally omitting the comma can lead to errors that are hard to "
|
|
"diagnose. For example::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:871
|
|
msgid ""
|
|
"This list looks like it has four elements, but it actually contains three: "
|
|
"\"fee\", \"fiefoo\" and \"fum\". Always adding the comma avoids this source "
|
|
"of error."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/design.rst:874
|
|
msgid ""
|
|
"Allowing the trailing comma may also make programmatic code generation "
|
|
"easier."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:3
|
|
msgid "Extending/Embedding FAQ"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:13
|
|
msgid "Can I create my own functions in C?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:15
|
|
msgid ""
|
|
"Yes, you can create built-in modules containing functions, variables, "
|
|
"exceptions and even new types in C. This is explained in the document :ref:"
|
|
"`extending-index`."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:19
|
|
msgid "Most intermediate or advanced Python books will also cover this topic."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:23
|
|
msgid "Can I create my own functions in C++?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:25
|
|
msgid ""
|
|
"Yes, using the C compatibility features found in C++. Place ``extern \"C"
|
|
"\" { ... }`` around the Python include files and put ``extern \"C\"`` before "
|
|
"each function that is going to be called by the Python interpreter. Global "
|
|
"or static C++ objects with constructors are probably not a good idea."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:34
|
|
msgid "Writing C is hard; are there any alternatives?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:36
|
|
msgid ""
|
|
"There are a number of alternatives to writing your own C extensions, "
|
|
"depending on what you're trying to do."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:41
|
|
msgid ""
|
|
"If you need more speed, `Psyco <http://psyco.sourceforge.net/>`_ generates "
|
|
"x86 assembly code from Python bytecode. You can use Psyco to compile the "
|
|
"most time-critical functions in your code, and gain a significant "
|
|
"improvement with very little effort, as long as you're running on a machine "
|
|
"with an x86-compatible processor."
|
|
msgstr ""
|
|
|
|
# c2b7327575d34876a1809d21e31d12cb
|
|
#: ../src/Doc/faq/extending.rst:47
|
|
msgid ""
|
|
"`Cython <http://cython.org>`_ and its relative `Pyrex <http://www.cosc."
|
|
"canterbury.ac.nz/greg.ewing/python/Pyrex/>`_ are compilers that accept a "
|
|
"slightly modified form of Python and generate the corresponding C code. "
|
|
"Pyrex makes it possible to write an extension without having to learn "
|
|
"Python's C API."
|
|
msgstr ""
|
|
|
|
# f8a33d9aaba344ff97b0da6af3125b8f
|
|
#: ../src/Doc/faq/extending.rst:53
|
|
msgid ""
|
|
"If you need to interface to some C or C++ library for which no Python "
|
|
"extension currently exists, you can try wrapping the library's data types "
|
|
"and functions with a tool such as `SWIG <http://www.swig.org>`_. `SIP "
|
|
"<http://www.riverbankcomputing.co.uk/software/sip/intro>`__, `CXX <http://"
|
|
"cxx.sourceforge.net/>`_ `Boost <http://www.boost.org/libs/python/doc/index."
|
|
"html>`_, or `Weave <http://docs.scipy.org/doc/scipy-dev/reference/tutorial/"
|
|
"weave.html>`_ are also alternatives for wrapping C++ libraries."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:64
|
|
msgid "How can I execute arbitrary Python statements from C?"
|
|
msgstr ""
|
|
|
|
# 18b0e3c64e884142b76368d196969d3d
|
|
#: ../src/Doc/faq/extending.rst:66
|
|
msgid ""
|
|
"The highest-level function to do this is :c:func:`PyRun_SimpleString` which "
|
|
"takes a single string argument to be executed in the context of the module "
|
|
"``__main__`` and returns 0 for success and -1 when an exception occurred "
|
|
"(including ``SyntaxError``). If you want more control, use :c:func:"
|
|
"`PyRun_String`; see the source for :c:func:`PyRun_SimpleString` in ``Python/"
|
|
"pythonrun.c``."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:75
|
|
msgid "How can I evaluate an arbitrary Python expression from C?"
|
|
msgstr ""
|
|
|
|
# 4da2349aa63d4260a91f85be17bc553d
|
|
#: ../src/Doc/faq/extending.rst:77
|
|
msgid ""
|
|
"Call the function :c:func:`PyRun_String` from the previous question with the "
|
|
"start symbol :c:data:`Py_eval_input`; it parses an expression, evaluates it "
|
|
"and returns its value."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:83
|
|
msgid "How do I extract C values from a Python object?"
|
|
msgstr ""
|
|
|
|
# bf6d1f0de5d5498cb6d9c72ec2c0f291
|
|
#: ../src/Doc/faq/extending.rst:85
|
|
msgid ""
|
|
"That depends on the object's type. If it's a tuple, :c:func:`PyTuple_Size` "
|
|
"returns its length and :c:func:`PyTuple_GetItem` returns the item at a "
|
|
"specified index. Lists have similar functions, :c:func:`PyListSize` and :c:"
|
|
"func:`PyList_GetItem`."
|
|
msgstr ""
|
|
|
|
# 6111c83f34a944b299dc2b7f938f8f58
|
|
#: ../src/Doc/faq/extending.rst:90
|
|
msgid ""
|
|
"For strings, :c:func:`PyString_Size` returns its length and :c:func:"
|
|
"`PyString_AsString` a pointer to its value. Note that Python strings may "
|
|
"contain null bytes so C's :c:func:`strlen` should not be used."
|
|
msgstr ""
|
|
|
|
# efea875e83da494da9c6994eb907bd06
|
|
#: ../src/Doc/faq/extending.rst:94
|
|
msgid ""
|
|
"To test the type of an object, first make sure it isn't *NULL*, and then "
|
|
"use :c:func:`PyString_Check`, :c:func:`PyTuple_Check`, :c:func:"
|
|
"`PyList_Check`, etc."
|
|
msgstr ""
|
|
|
|
# d68f7b2e96c84902a81aca0e5e3c0623
|
|
#: ../src/Doc/faq/extending.rst:97
|
|
msgid ""
|
|
"There is also a high-level API to Python objects which is provided by the so-"
|
|
"called 'abstract' interface -- read ``Include/abstract.h`` for further "
|
|
"details. It allows interfacing with any kind of Python sequence using calls "
|
|
"like :c:func:`PySequence_Length`, :c:func:`PySequence_GetItem`, etc.) as "
|
|
"well as many other useful protocols."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:105
|
|
msgid "How do I use Py_BuildValue() to create a tuple of arbitrary length?"
|
|
msgstr ""
|
|
|
|
# 65e3b87a7f9244f69b0940a5c95ed4c9
|
|
#: ../src/Doc/faq/extending.rst:107
|
|
msgid ""
|
|
"You can't. Use ``t = PyTuple_New(n)`` instead, and fill it with objects "
|
|
"using ``PyTuple_SetItem(t, i, o)`` -- note that this \"eats\" a reference "
|
|
"count of ``o``, so you have to :c:func:`Py_INCREF` it. Lists have similar "
|
|
"functions ``PyList_New(n)`` and ``PyList_SetItem(l, i, o)``. Note that you "
|
|
"*must* set all the tuple items to some value before you pass the tuple to "
|
|
"Python code -- ``PyTuple_New(n)`` initializes them to NULL, which isn't a "
|
|
"valid Python value."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:116
|
|
msgid "How do I call an object's method from C?"
|
|
msgstr ""
|
|
|
|
# df0a0e00b90e4282a8bea227ff1b10ca
|
|
#: ../src/Doc/faq/extending.rst:118
|
|
msgid ""
|
|
"The :c:func:`PyObject_CallMethod` function can be used to call an arbitrary "
|
|
"method of an object. The parameters are the object, the name of the method "
|
|
"to call, a format string like that used with :c:func:`Py_BuildValue`, and "
|
|
"the argument values::"
|
|
msgstr ""
|
|
|
|
# b219b7268bfc44069c09cf32040d168d
|
|
#: ../src/Doc/faq/extending.rst:127
|
|
msgid ""
|
|
"This works for any object that has methods -- whether built-in or user-"
|
|
"defined. You are responsible for eventually :c:func:`Py_DECREF`\\ 'ing the "
|
|
"return value."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:130
|
|
msgid ""
|
|
"To call, e.g., a file object's \"seek\" method with arguments 10, 0 "
|
|
"(assuming the file object pointer is \"f\")::"
|
|
msgstr ""
|
|
|
|
# 45739a85a41845659ac0d8e44d22aab8
|
|
#: ../src/Doc/faq/extending.rst:141
|
|
msgid ""
|
|
"Note that since :c:func:`PyObject_CallObject` *always* wants a tuple for the "
|
|
"argument list, to call a function without arguments, pass \"()\" for the "
|
|
"format, and to call a function with one argument, surround the argument in "
|
|
"parentheses, e.g. \"(i)\"."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:148
|
|
msgid ""
|
|
"How do I catch the output from PyErr_Print() (or anything that prints to "
|
|
"stdout/stderr)?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:150
|
|
msgid ""
|
|
"In Python code, define an object that supports the ``write()`` method. "
|
|
"Assign this object to :data:`sys.stdout` and :data:`sys.stderr`. Call "
|
|
"print_error, or just allow the standard traceback mechanism to work. Then, "
|
|
"the output will go wherever your ``write()`` method sends it."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:155
|
|
msgid ""
|
|
"The easiest way to do this is to use the StringIO class in the standard "
|
|
"library."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:157
|
|
msgid "Sample code and use for catching stdout:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:175
|
|
msgid "How do I access a module written in Python from C?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:177
|
|
msgid "You can get a pointer to the module object as follows::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:181
|
|
msgid ""
|
|
"If the module hasn't been imported yet (i.e. it is not yet present in :data:"
|
|
"`sys.modules`), this initializes the module; otherwise it simply returns the "
|
|
"value of ``sys.modules[\"<modulename>\"]``. Note that it doesn't enter the "
|
|
"module into any namespace -- it only ensures it has been initialized and is "
|
|
"stored in :data:`sys.modules`."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:187
|
|
msgid ""
|
|
"You can then access the module's attributes (i.e. any name defined in the "
|
|
"module) as follows::"
|
|
msgstr ""
|
|
|
|
# 646b1887089947edac480d122919c21a
|
|
#: ../src/Doc/faq/extending.rst:192
|
|
msgid ""
|
|
"Calling :c:func:`PyObject_SetAttrString` to assign to variables in the "
|
|
"module also works."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:197
|
|
msgid "How do I interface to C++ objects from Python?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:199
|
|
msgid ""
|
|
"Depending on your requirements, there are many approaches. To do this "
|
|
"manually, begin by reading :ref:`the \"Extending and Embedding\" document "
|
|
"<extending-index>`. Realize that for the Python run-time system, there "
|
|
"isn't a whole lot of difference between C and C++ -- so the strategy of "
|
|
"building a new Python type around a C structure (pointer) type will also "
|
|
"work for C++ objects."
|
|
msgstr ""
|
|
|
|
# 79545e2b1466479284f3c186af5c4e7a
|
|
#: ../src/Doc/faq/extending.rst:205
|
|
msgid "For C++ libraries, see :ref:`c-wrapper-software`."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:209
|
|
msgid "I added a module using the Setup file and the make fails; why?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:211
|
|
msgid ""
|
|
"Setup must end in a newline, if there is no newline there, the build process "
|
|
"fails. (Fixing this requires some ugly shell script hackery, and this bug "
|
|
"is so minor that it doesn't seem worth the effort.)"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:217
|
|
msgid "How do I debug an extension?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:219
|
|
msgid ""
|
|
"When using GDB with dynamically loaded extensions, you can't set a "
|
|
"breakpoint in your extension until your extension is loaded."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:222
|
|
msgid "In your ``.gdbinit`` file (or interactively), add the command::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:226
|
|
msgid "Then, when you run GDB::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:236
|
|
msgid ""
|
|
"I want to compile a Python module on my Linux system, but some files are "
|
|
"missing. Why?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:238
|
|
msgid ""
|
|
"Most packaged versions of Python don't include the :file:`/usr/lib/python2."
|
|
"{x}/config/` directory, which contains various files required for compiling "
|
|
"Python extensions."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:242
|
|
msgid "For Red Hat, install the python-devel RPM to get the necessary files."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:244
|
|
msgid "For Debian, run ``apt-get install python-dev``."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:248
|
|
msgid ""
|
|
"What does \"SystemError: _PyImport_FixupExtension: module yourmodule not "
|
|
"loaded\" mean?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:250
|
|
msgid ""
|
|
"This means that you have created an extension module named \"yourmodule\", "
|
|
"but your module init function does not initialize with that name."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:253
|
|
msgid "Every module init function will have a line similar to::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:257
|
|
msgid ""
|
|
"If the string passed to this function is not the same name as your extension "
|
|
"module, the :exc:`SystemError` exception will be raised."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:262
|
|
msgid "How do I tell \"incomplete input\" from \"invalid input\"?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:264
|
|
msgid ""
|
|
"Sometimes you want to emulate the Python interactive interpreter's behavior, "
|
|
"where it gives you a continuation prompt when the input is incomplete (e.g. "
|
|
"you typed the start of an \"if\" statement or you didn't close your "
|
|
"parentheses or triple string quotes), but it gives you a syntax error "
|
|
"message immediately when the input is invalid."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:270
|
|
msgid ""
|
|
"In Python you can use the :mod:`codeop` module, which approximates the "
|
|
"parser's behavior sufficiently. IDLE uses this, for example."
|
|
msgstr ""
|
|
|
|
# 19a4a0d28eec4133a082ff7797453944
|
|
#: ../src/Doc/faq/extending.rst:273
|
|
msgid ""
|
|
"The easiest way to do it in C is to call :c:func:`PyRun_InteractiveLoop` "
|
|
"(perhaps in a separate thread) and let the Python interpreter handle the "
|
|
"input for you. You can also set the :c:func:`PyOS_ReadlineFunctionPointer` "
|
|
"to point at your custom input function. See ``Modules/readline.c`` and "
|
|
"``Parser/myreadline.c`` for more hints."
|
|
msgstr ""
|
|
|
|
# 77f9464418f243e29c3907a9a12ab26a
|
|
#: ../src/Doc/faq/extending.rst:279
|
|
msgid ""
|
|
"However sometimes you have to run the embedded Python interpreter in the "
|
|
"same thread as your rest application and you can't allow the :c:func:"
|
|
"`PyRun_InteractiveLoop` to stop while waiting for user input. The one "
|
|
"solution then is to call :c:func:`PyParser_ParseString` and test for ``e."
|
|
"error`` equal to ``E_EOF``, which means the input is incomplete). Here's a "
|
|
"sample code fragment, untested, inspired by code from Alex Farber::"
|
|
msgstr ""
|
|
|
|
# 2c15d7c7e14a406d9987caf0f7289897
|
|
#: ../src/Doc/faq/extending.rst:312
|
|
msgid ""
|
|
"Another solution is trying to compile the received string with :c:func:"
|
|
"`Py_CompileString`. If it compiles without errors, try to execute the "
|
|
"returned code object by calling :c:func:`PyEval_EvalCode`. Otherwise save "
|
|
"the input for later. If the compilation fails, find out if it's an error or "
|
|
"just more input is required - by extracting the message string from the "
|
|
"exception tuple and comparing it to the string \"unexpected EOF while parsing"
|
|
"\". Here is a complete example using the GNU readline library (you may want "
|
|
"to ignore **SIGINT** while calling readline())::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:433
|
|
msgid "How do I find undefined g++ symbols __builtin_new or __pure_virtual?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:435
|
|
msgid ""
|
|
"To dynamically load g++ extension modules, you must recompile Python, relink "
|
|
"it using g++ (change LINKCC in the Python Modules Makefile), and link your "
|
|
"extension module using g++ (e.g., ``g++ -shared -o mymodule.so mymodule.o``)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:441
|
|
msgid ""
|
|
"Can I create an object class with some methods implemented in C and others "
|
|
"in Python (e.g. through inheritance)?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:443
|
|
msgid ""
|
|
"In Python 2.2, you can inherit from built-in classes such as :class:`int`, :"
|
|
"class:`list`, :class:`dict`, etc."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:446
|
|
msgid ""
|
|
"The Boost Python Library (BPL, http://www.boost.org/libs/python/doc/index."
|
|
"html) provides a way of doing this from C++ (i.e. you can inherit from an "
|
|
"extension class written in C++ using the BPL)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:452
|
|
msgid ""
|
|
"When importing module X, why do I get \"undefined symbol: PyUnicodeUCS2*\"?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:454
|
|
msgid ""
|
|
"You are using a version of Python that uses a 4-byte representation for "
|
|
"Unicode characters, but some C extension module you are importing was "
|
|
"compiled using a Python that uses a 2-byte representation for Unicode "
|
|
"characters (the default)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:458
|
|
msgid ""
|
|
"If instead the name of the undefined symbol starts with ``PyUnicodeUCS4``, "
|
|
"the problem is the reverse: Python was built using 2-byte Unicode "
|
|
"characters, and the extension module was compiled using a Python with 4-byte "
|
|
"Unicode characters."
|
|
msgstr ""
|
|
|
|
# 886cf89f005a426da807866a9f4743bd
|
|
#: ../src/Doc/faq/extending.rst:462
|
|
msgid ""
|
|
"This can easily occur when using pre-built extension packages. RedHat Linux "
|
|
"7.x, in particular, provided a \"python2\" binary that is compiled with 4-"
|
|
"byte Unicode. This only causes the link failure if the extension uses any "
|
|
"of the ``PyUnicode_*()`` functions. It is also a problem if an extension "
|
|
"uses any of the Unicode-related format specifiers for :c:func:"
|
|
"`Py_BuildValue` (or similar) or parameter specifications for :c:func:"
|
|
"`PyArg_ParseTuple`."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:469
|
|
msgid ""
|
|
"You can check the size of the Unicode character a Python interpreter is "
|
|
"using by checking the value of sys.maxunicode:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/extending.rst:478
|
|
msgid ""
|
|
"The only way to solve this problem is to use extension modules compiled with "
|
|
"a Python binary built using the same size for Unicode characters."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:5
|
|
msgid "General Python FAQ"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:13
|
|
msgid "General Information"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:16 ../src/Doc/faq/installed.rst:6
|
|
msgid "What is Python?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:18
|
|
msgid ""
|
|
"Python is an interpreted, interactive, object-oriented programming "
|
|
"language. It incorporates modules, exceptions, dynamic typing, very high "
|
|
"level dynamic data types, and classes. Python combines remarkable power "
|
|
"with very clear syntax. It has interfaces to many system calls and "
|
|
"libraries, as well as to various window systems, and is extensible in C or C+"
|
|
"+. It is also usable as an extension language for applications that need a "
|
|
"programmable interface. Finally, Python is portable: it runs on many Unix "
|
|
"variants, on the Mac, and on PCs under MS-DOS, Windows, Windows NT, and OS/2."
|
|
msgstr ""
|
|
|
|
# 63e8e9a6b18f4b9db21bd43a83364a82
|
|
#: ../src/Doc/faq/general.rst:27
|
|
msgid ""
|
|
"To find out more, start with :ref:`tutorial-index`. The `Beginner's Guide "
|
|
"to Python <https://wiki.python.org/moin/BeginnersGuide>`_ links to other "
|
|
"introductory tutorials and resources for learning Python."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:33
|
|
msgid "What is the Python Software Foundation?"
|
|
msgstr ""
|
|
|
|
# ec2ca6254b3946ba877cf79f65551b32
|
|
#: ../src/Doc/faq/general.rst:35
|
|
msgid ""
|
|
"The Python Software Foundation is an independent non-profit organization "
|
|
"that holds the copyright on Python versions 2.1 and newer. The PSF's "
|
|
"mission is to advance open source technology related to the Python "
|
|
"programming language and to publicize the use of Python. The PSF's home "
|
|
"page is at https://www.python.org/psf/."
|
|
msgstr ""
|
|
|
|
# 18003a9ceee54963bce2fbdbdebf0117
|
|
#: ../src/Doc/faq/general.rst:41
|
|
msgid ""
|
|
"Donations to the PSF are tax-exempt in the US. If you use Python and find "
|
|
"it helpful, please contribute via `the PSF donation page <https://www.python."
|
|
"org/psf/donations/>`_."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:47
|
|
msgid "Are there copyright restrictions on the use of Python?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:49
|
|
msgid ""
|
|
"You can do anything you want with the source, as long as you leave the "
|
|
"copyrights in and display those copyrights in any documentation about Python "
|
|
"that you produce. If you honor the copyright rules, it's OK to use Python "
|
|
"for commercial use, to sell copies of Python in source or binary form "
|
|
"(modified or unmodified), or to sell products that incorporate Python in "
|
|
"some form. We would still like to know about all commercial use of Python, "
|
|
"of course."
|
|
msgstr ""
|
|
|
|
# ab79876ebb054c1987be6f2e64c52aa1
|
|
#: ../src/Doc/faq/general.rst:56
|
|
msgid ""
|
|
"See `the PSF license page <https://docs.python.org/3/license/>`_ to find "
|
|
"further explanations and a link to the full text of the license."
|
|
msgstr ""
|
|
|
|
# 4ef579790a7041738f2cb822de158058
|
|
#: ../src/Doc/faq/general.rst:59
|
|
msgid ""
|
|
"The Python logo is trademarked, and in certain cases permission is required "
|
|
"to use it. Consult `the Trademark Usage Policy <https://www.python.org/psf/"
|
|
"trademarks/>`__ for more information."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:65
|
|
msgid "Why was Python created in the first place?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:67
|
|
msgid ""
|
|
"Here's a *very* brief summary of what started it all, written by Guido van "
|
|
"Rossum:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:70
|
|
msgid ""
|
|
"I had extensive experience with implementing an interpreted language in the "
|
|
"ABC group at CWI, and from working with this group I had learned a lot about "
|
|
"language design. This is the origin of many Python features, including the "
|
|
"use of indentation for statement grouping and the inclusion of very-high-"
|
|
"level data types (although the details are all different in Python)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:77
|
|
msgid ""
|
|
"I had a number of gripes about the ABC language, but also liked many of its "
|
|
"features. It was impossible to extend the ABC language (or its "
|
|
"implementation) to remedy my complaints -- in fact its lack of extensibility "
|
|
"was one of its biggest problems. I had some experience with using Modula-2+ "
|
|
"and talked with the designers of Modula-3 and read the Modula-3 report. "
|
|
"Modula-3 is the origin of the syntax and semantics used for exceptions, and "
|
|
"some other Python features."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:85
|
|
msgid ""
|
|
"I was working in the Amoeba distributed operating system group at CWI. We "
|
|
"needed a better way to do system administration than by writing either C "
|
|
"programs or Bourne shell scripts, since Amoeba had its own system call "
|
|
"interface which wasn't easily accessible from the Bourne shell. My "
|
|
"experience with error handling in Amoeba made me acutely aware of the "
|
|
"importance of exceptions as a programming language feature."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:92
|
|
msgid ""
|
|
"It occurred to me that a scripting language with a syntax like ABC but with "
|
|
"access to the Amoeba system calls would fill the need. I realized that it "
|
|
"would be foolish to write an Amoeba-specific language, so I decided that I "
|
|
"needed a language that was generally extensible."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:97
|
|
msgid ""
|
|
"During the 1989 Christmas holidays, I had a lot of time on my hand, so I "
|
|
"decided to give it a try. During the next year, while still mostly working "
|
|
"on it in my own time, Python was used in the Amoeba project with increasing "
|
|
"success, and the feedback from colleagues made me add many early "
|
|
"improvements."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:103
|
|
msgid ""
|
|
"In February 1991, after just over a year of development, I decided to post "
|
|
"to USENET. The rest is in the ``Misc/HISTORY`` file."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:108
|
|
msgid "What is Python good for?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:110
|
|
msgid ""
|
|
"Python is a high-level general-purpose programming language that can be "
|
|
"applied to many different classes of problems."
|
|
msgstr ""
|
|
|
|
# 32939d2b72fc4bb4a6b00b85cb83e68a
|
|
#: ../src/Doc/faq/general.rst:113
|
|
msgid ""
|
|
"The language comes with a large standard library that covers areas such as "
|
|
"string processing (regular expressions, Unicode, calculating differences "
|
|
"between files), Internet protocols (HTTP, FTP, SMTP, XML-RPC, POP, IMAP, CGI "
|
|
"programming), software engineering (unit testing, logging, profiling, "
|
|
"parsing Python code), and operating system interfaces (system calls, "
|
|
"filesystems, TCP/IP sockets). Look at the table of contents for :ref:"
|
|
"`library-index` to get an idea of what's available. A wide variety of third-"
|
|
"party extensions are also available. Consult `the Python Package Index "
|
|
"<https://pypi.python.org/pypi>`_ to find packages of interest to you."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:125
|
|
msgid "How does the Python version numbering scheme work?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:127
|
|
msgid ""
|
|
"Python versions are numbered A.B.C or A.B. A is the major version number -- "
|
|
"it is only incremented for really major changes in the language. B is the "
|
|
"minor version number, incremented for less earth-shattering changes. C is "
|
|
"the micro-level -- it is incremented for each bugfix release. See :pep:`6` "
|
|
"for more information about bugfix releases."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:133
|
|
msgid ""
|
|
"Not all releases are bugfix releases. In the run-up to a new major release, "
|
|
"a series of development releases are made, denoted as alpha, beta, or "
|
|
"release candidate. Alphas are early releases in which interfaces aren't yet "
|
|
"finalized; it's not unexpected to see an interface change between two alpha "
|
|
"releases. Betas are more stable, preserving existing interfaces but possibly "
|
|
"adding new modules, and release candidates are frozen, making no changes "
|
|
"except as needed to fix critical bugs."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:141
|
|
msgid ""
|
|
"Alpha, beta and release candidate versions have an additional suffix. The "
|
|
"suffix for an alpha version is \"aN\" for some small number N, the suffix "
|
|
"for a beta version is \"bN\" for some small number N, and the suffix for a "
|
|
"release candidate version is \"cN\" for some small number N. In other "
|
|
"words, all versions labeled 2.0aN precede the versions labeled 2.0bN, which "
|
|
"precede versions labeled 2.0cN, and *those* precede 2.0."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:148
|
|
msgid ""
|
|
"You may also find version numbers with a \"+\" suffix, e.g. \"2.2+\". These "
|
|
"are unreleased versions, built directly from the Subversion trunk. In "
|
|
"practice, after a final minor release is made, the Subversion trunk is "
|
|
"incremented to the next minor version, which becomes the \"a0\" version, e."
|
|
"g. \"2.4a0\"."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:154
|
|
msgid ""
|
|
"See also the documentation for ``sys.version``, ``sys.hexversion``, and "
|
|
"``sys.version_info``."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:159
|
|
msgid "How do I obtain a copy of the Python source?"
|
|
msgstr ""
|
|
|
|
# 8244dbe42fc049a0ab12d53e5d9c254c
|
|
#: ../src/Doc/faq/general.rst:161
|
|
msgid ""
|
|
"The latest Python source distribution is always available from python.org, "
|
|
"at https://www.python.org/download/. The latest development sources can be "
|
|
"obtained via anonymous Mercurial access at https://hg.python.org/cpython."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:165
|
|
msgid ""
|
|
"The source distribution is a gzipped tar file containing the complete C "
|
|
"source, Sphinx-formatted documentation, Python library modules, example "
|
|
"programs, and several useful pieces of freely distributable software. The "
|
|
"source will compile and run out of the box on most UNIX platforms."
|
|
msgstr ""
|
|
|
|
# 20df971777764e7b86d2945158f49983
|
|
#: ../src/Doc/faq/general.rst:170
|
|
msgid ""
|
|
"Consult the `Getting Started section of the Python Developer's Guide "
|
|
"<https://docs.python.org/devguide/setup.html>`__ for more information on "
|
|
"getting the source code and compiling it."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:176
|
|
msgid "How do I get documentation on Python?"
|
|
msgstr ""
|
|
|
|
# aabba0b407c94dbfbdee69fe5d724e98
|
|
#: ../src/Doc/faq/general.rst:180
|
|
msgid ""
|
|
"The standard documentation for the current stable version of Python is "
|
|
"available at https://docs.python.org/3/. PDF, plain text, and downloadable "
|
|
"HTML versions are also available at https://docs.python.org/3/download.html."
|
|
msgstr ""
|
|
|
|
# 7ad68c3fd07643b89f4ddc9e8b2f19da
|
|
#: ../src/Doc/faq/general.rst:184
|
|
msgid ""
|
|
"The documentation is written in reStructuredText and processed by `the "
|
|
"Sphinx documentation tool <http://sphinx-doc.org/>`__. The reStructuredText "
|
|
"source for the documentation is part of the Python source distribution."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:190
|
|
msgid "I've never programmed before. Is there a Python tutorial?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:192
|
|
msgid ""
|
|
"There are numerous tutorials and books available. The standard "
|
|
"documentation includes :ref:`tutorial-index`."
|
|
msgstr ""
|
|
|
|
# 9d362d25da7849299fb790b4cbada6ea
|
|
#: ../src/Doc/faq/general.rst:195
|
|
msgid ""
|
|
"Consult `the Beginner's Guide <https://wiki.python.org/moin/"
|
|
"BeginnersGuide>`_ to find information for beginning Python programmers, "
|
|
"including lists of tutorials."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:200
|
|
msgid "Is there a newsgroup or mailing list devoted to Python?"
|
|
msgstr ""
|
|
|
|
# 69aa419ee8944e968f24d49782564a4c
|
|
#: ../src/Doc/faq/general.rst:202
|
|
msgid ""
|
|
"There is a newsgroup, :newsgroup:`comp.lang.python`, and a mailing list, "
|
|
"`python-list <https://mail.python.org/mailman/listinfo/python-list>`_. The "
|
|
"newsgroup and mailing list are gatewayed into each other -- if you can read "
|
|
"news it's unnecessary to subscribe to the mailing list. :newsgroup:`comp."
|
|
"lang.python` is high-traffic, receiving hundreds of postings every day, and "
|
|
"Usenet readers are often more able to cope with this volume."
|
|
msgstr ""
|
|
|
|
# bd61630ca8134e02b7b48084e3bb82ef
|
|
#: ../src/Doc/faq/general.rst:209
|
|
msgid ""
|
|
"Announcements of new software releases and events can be found in comp.lang."
|
|
"python.announce, a low-traffic moderated list that receives about five "
|
|
"postings per day. It's available as `the python-announce mailing list "
|
|
"<https://mail.python.org/mailman/listinfo/python-announce-list>`_."
|
|
msgstr ""
|
|
|
|
# efd356343245403bbf90a2e75a311b9d
|
|
#: ../src/Doc/faq/general.rst:214
|
|
msgid ""
|
|
"More info about other mailing lists and newsgroups can be found at https://"
|
|
"www.python.org/community/lists/."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:219
|
|
msgid "How do I get a beta test version of Python?"
|
|
msgstr ""
|
|
|
|
# 88e49a54a28b4d23b72785e0822d2d5c
|
|
#: ../src/Doc/faq/general.rst:221
|
|
msgid ""
|
|
"Alpha and beta releases are available from https://www.python.org/"
|
|
"download/. All releases are announced on the comp.lang.python and comp.lang."
|
|
"python.announce newsgroups and on the Python home page at https://www.python."
|
|
"org/; an RSS feed of news is available."
|
|
msgstr ""
|
|
|
|
# 3cb6d776ab10410695dcadb9175bd162
|
|
#: ../src/Doc/faq/general.rst:226
|
|
msgid ""
|
|
"You can also access the development version of Python through Mercurial. "
|
|
"See https://docs.python.org/devguide/faq.html for details."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:231
|
|
msgid "How do I submit bug reports and patches for Python?"
|
|
msgstr ""
|
|
|
|
# ed60ae55f0674edb86d3e460cd36c7c0
|
|
#: ../src/Doc/faq/general.rst:233
|
|
msgid ""
|
|
"To report a bug or submit a patch, please use the Roundup installation at "
|
|
"https://bugs.python.org/."
|
|
msgstr ""
|
|
|
|
# 5c0e33af23cd453eb13c61e0024c5ccf
|
|
#: ../src/Doc/faq/general.rst:236
|
|
msgid ""
|
|
"You must have a Roundup account to report bugs; this makes it possible for "
|
|
"us to contact you if we have follow-up questions. It will also enable "
|
|
"Roundup to send you updates as we act on your bug. If you had previously "
|
|
"used SourceForge to report bugs to Python, you can obtain your Roundup "
|
|
"password through Roundup's `password reset procedure <https://bugs.python."
|
|
"org/user?@template=forgotten>`_."
|
|
msgstr ""
|
|
|
|
# e087c76f6e88484bae2328bbb47d563f
|
|
#: ../src/Doc/faq/general.rst:242
|
|
msgid ""
|
|
"For more information on how Python is developed, consult `the Python "
|
|
"Developer's Guide <https://docs.python.org/devguide/>`_."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:247
|
|
msgid "Are there any published articles about Python that I can reference?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:249
|
|
msgid "It's probably best to cite your favorite book about Python."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:251
|
|
msgid ""
|
|
"The very first article about Python was written in 1991 and is now quite "
|
|
"outdated."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:254
|
|
msgid ""
|
|
"Guido van Rossum and Jelke de Boer, \"Interactively Testing Remote Servers "
|
|
"Using the Python Programming Language\", CWI Quarterly, Volume 4, Issue 4 "
|
|
"(December 1991), Amsterdam, pp 283-303."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:260
|
|
msgid "Are there any books on Python?"
|
|
msgstr ""
|
|
|
|
# d98bb043ee1a430e86dd7fbf76516b2b
|
|
#: ../src/Doc/faq/general.rst:262
|
|
msgid ""
|
|
"Yes, there are many, and more are being published. See the python.org wiki "
|
|
"at https://wiki.python.org/moin/PythonBooks for a list."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:265
|
|
msgid ""
|
|
"You can also search online bookstores for \"Python\" and filter out the "
|
|
"Monty Python references; or perhaps search for \"Python\" and \"language\"."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:270
|
|
msgid "Where in the world is www.python.org located?"
|
|
msgstr ""
|
|
|
|
# e7e802e7ba9340c5be665ea44fb2c1db
|
|
#: ../src/Doc/faq/general.rst:272
|
|
msgid ""
|
|
"The Python project's infrastructure is located all over the world. `www."
|
|
"python.org <https://www.python.org>`_ is graciously hosted by `Rackspace "
|
|
"<http://www.rackspace.com>`_, with CDN caching provided by `Fastly <https://"
|
|
"www.fastly.com>`_. `Upfront Systems <http://www.upfrontsystems.co.za>`_ "
|
|
"hosts `bugs.python.org <https://bugs.python.org>`_. Many other Python "
|
|
"services like `the Wiki <https://wiki.python.org>`_ are hosted by `Oregon "
|
|
"State University Open Source Lab <https://osuosl.org>`_."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:283
|
|
msgid "Why is it called Python?"
|
|
msgstr ""
|
|
|
|
# 48f7399a35da4567b45a33f0aa99e468
|
|
#: ../src/Doc/faq/general.rst:285
|
|
msgid ""
|
|
"When he began implementing Python, Guido van Rossum was also reading the "
|
|
"published scripts from `\"Monty Python's Flying Circus\" <http://en."
|
|
"wikipedia.org/wiki/Monty_Python>`__, a BBC comedy series from the 1970s. "
|
|
"Van Rossum thought he needed a name that was short, unique, and slightly "
|
|
"mysterious, so he decided to call the language Python."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:293
|
|
msgid "Do I have to like \"Monty Python's Flying Circus\"?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:295
|
|
msgid "No, but it helps. :)"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:299
|
|
msgid "Python in the real world"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:302
|
|
msgid "How stable is Python?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:304
|
|
msgid ""
|
|
"Very stable. New, stable releases have been coming out roughly every 6 to "
|
|
"18 months since 1991, and this seems likely to continue. Currently there "
|
|
"are usually around 18 months between major releases."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:308
|
|
msgid ""
|
|
"The developers issue \"bugfix\" releases of older versions, so the stability "
|
|
"of existing releases gradually improves. Bugfix releases, indicated by a "
|
|
"third component of the version number (e.g. 2.5.3, 2.6.2), are managed for "
|
|
"stability; only fixes for known problems are included in a bugfix release, "
|
|
"and it's guaranteed that interfaces will remain the same throughout a series "
|
|
"of bugfix releases."
|
|
msgstr ""
|
|
|
|
# 6409cf921b94468b9112bcff9c7c3e81
|
|
#: ../src/Doc/faq/general.rst:315
|
|
msgid ""
|
|
"The latest stable releases can always be found on the `Python download page "
|
|
"<https://www.python.org/download/>`_. There are two recommended production-"
|
|
"ready versions at this point in time, because at the moment there are two "
|
|
"branches of stable releases: 2.x and 3.x. Python 3.x may be less useful "
|
|
"than 2.x, since currently there is more third party software available for "
|
|
"Python 2 than for Python 3. Python 2 code will generally not run unchanged "
|
|
"in Python 3."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:324
|
|
msgid "How many people are using Python?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:326
|
|
msgid ""
|
|
"There are probably tens of thousands of users, though it's difficult to "
|
|
"obtain an exact count."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:329
|
|
msgid ""
|
|
"Python is available for free download, so there are no sales figures, and "
|
|
"it's available from many different sites and packaged with many Linux "
|
|
"distributions, so download statistics don't tell the whole story either."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:333
|
|
msgid ""
|
|
"The comp.lang.python newsgroup is very active, but not all Python users post "
|
|
"to the group or even read it."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:338
|
|
msgid "Have any significant projects been done in Python?"
|
|
msgstr ""
|
|
|
|
# 01bba32172234741a35c9e66d0a2d7a7
|
|
#: ../src/Doc/faq/general.rst:340
|
|
msgid ""
|
|
"See https://www.python.org/about/success for a list of projects that use "
|
|
"Python. Consulting the proceedings for `past Python conferences <https://www."
|
|
"python.org/community/workshops/>`_ will reveal contributions from many "
|
|
"different companies and organizations."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:345
|
|
msgid ""
|
|
"High-profile Python projects include `the Mailman mailing list manager "
|
|
"<http://www.list.org>`_ and `the Zope application server <http://www.zope."
|
|
"org>`_. Several Linux distributions, most notably `Red Hat <http://www."
|
|
"redhat.com>`_, have written part or all of their installer and system "
|
|
"administration software in Python. Companies that use Python internally "
|
|
"include Google, Yahoo, and Lucasfilm Ltd."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:354
|
|
msgid "What new developments are expected for Python in the future?"
|
|
msgstr ""
|
|
|
|
# 796e3ce370e74b50a690431583e0b159
|
|
#: ../src/Doc/faq/general.rst:356
|
|
msgid ""
|
|
"See https://www.python.org/dev/peps/ for the Python Enhancement Proposals "
|
|
"(PEPs). PEPs are design documents describing a suggested new feature for "
|
|
"Python, providing a concise technical specification and a rationale. Look "
|
|
"for a PEP titled \"Python X.Y Release Schedule\", where X.Y is a version "
|
|
"that hasn't been publicly released yet."
|
|
msgstr ""
|
|
|
|
# 114b11a02f77445ca2b8a00fa65e64ce
|
|
#: ../src/Doc/faq/general.rst:362
|
|
msgid ""
|
|
"New development is discussed on `the python-dev mailing list <https://mail."
|
|
"python.org/mailman/listinfo/python-dev/>`_."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:367
|
|
msgid "Is it reasonable to propose incompatible changes to Python?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:369
|
|
msgid ""
|
|
"In general, no. There are already millions of lines of Python code around "
|
|
"the world, so any change in the language that invalidates more than a very "
|
|
"small fraction of existing programs has to be frowned upon. Even if you can "
|
|
"provide a conversion program, there's still the problem of updating all "
|
|
"documentation; many books have been written about Python, and we don't want "
|
|
"to invalidate them all at a single stroke."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:376
|
|
msgid ""
|
|
"Providing a gradual upgrade path is necessary if a feature has to be "
|
|
"changed. :pep:`5` describes the procedure followed for introducing backward-"
|
|
"incompatible changes while minimizing disruption for users."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:382
|
|
msgid "Is Python a good language for beginning programmers?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:384 ../src/Doc/faq/library.rst:764
|
|
#: ../src/Doc/faq/programming.rst:17 ../src/Doc/faq/programming.rst:60
|
|
msgid "Yes."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:386
|
|
msgid ""
|
|
"It is still common to start students with a procedural and statically typed "
|
|
"language such as Pascal, C, or a subset of C++ or Java. Students may be "
|
|
"better served by learning Python as their first language. Python has a very "
|
|
"simple and consistent syntax and a large standard library and, most "
|
|
"importantly, using Python in a beginning programming course lets students "
|
|
"concentrate on important programming skills such as problem decomposition "
|
|
"and data type design. With Python, students can be quickly introduced to "
|
|
"basic concepts such as loops and procedures. They can probably even work "
|
|
"with user-defined objects in their very first course."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:396
|
|
msgid ""
|
|
"For a student who has never programmed before, using a statically typed "
|
|
"language seems unnatural. It presents additional complexity that the "
|
|
"student must master and slows the pace of the course. The students are "
|
|
"trying to learn to think like a computer, decompose problems, design "
|
|
"consistent interfaces, and encapsulate data. While learning to use a "
|
|
"statically typed language is important in the long term, it is not "
|
|
"necessarily the best topic to address in the students' first programming "
|
|
"course."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:404
|
|
msgid ""
|
|
"Many other aspects of Python make it a good first language. Like Java, "
|
|
"Python has a large standard library so that students can be assigned "
|
|
"programming projects very early in the course that *do* something. "
|
|
"Assignments aren't restricted to the standard four-function calculator and "
|
|
"check balancing programs. By using the standard library, students can gain "
|
|
"the satisfaction of working on realistic applications as they learn the "
|
|
"fundamentals of programming. Using the standard library also teaches "
|
|
"students about code reuse. Third-party modules such as PyGame are also "
|
|
"helpful in extending the students' reach."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:413
|
|
msgid ""
|
|
"Python's interactive interpreter enables students to test language features "
|
|
"while they're programming. They can keep a window with the interpreter "
|
|
"running while they enter their program's source in another window. If they "
|
|
"can't remember the methods for a list, they can do something like this::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:439
|
|
msgid ""
|
|
"With the interpreter, documentation is never far from the student as he's "
|
|
"programming."
|
|
msgstr ""
|
|
|
|
# f94af7923ed745f58ebf8abde3518df3
|
|
#: ../src/Doc/faq/general.rst:442
|
|
msgid ""
|
|
"There are also good IDEs for Python. IDLE is a cross-platform IDE for "
|
|
"Python that is written in Python using Tkinter. PythonWin is a Windows-"
|
|
"specific IDE. Emacs users will be happy to know that there is a very good "
|
|
"Python mode for Emacs. All of these programming environments provide syntax "
|
|
"highlighting, auto-indenting, and access to the interactive interpreter "
|
|
"while coding. Consult `the Python wiki <https://wiki.python.org/moin/"
|
|
"PythonEditors>`_ for a full list of Python editing environments."
|
|
msgstr ""
|
|
|
|
# 15764eb4a94e46bfa76e857e01d5e9e5
|
|
#: ../src/Doc/faq/general.rst:450
|
|
msgid ""
|
|
"If you want to discuss Python's use in education, you may be interested in "
|
|
"joining `the edu-sig mailing list <https://www.python.org/community/sigs/"
|
|
"current/edu-sig>`_."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:456
|
|
msgid "Upgrading Python"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:459
|
|
msgid "What is this bsddb185 module my application keeps complaining about?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:463
|
|
msgid ""
|
|
"Starting with Python2.3, the distribution includes the `PyBSDDB package "
|
|
"<http://pybsddb.sf.net/>` as a replacement for the old bsddb module. It "
|
|
"includes functions which provide backward compatibility at the API level, "
|
|
"but requires a newer version of the underlying `Berkeley DB <http://www."
|
|
"sleepycat.com>`_ library. Files created with the older bsddb module can't "
|
|
"be opened directly using the new module."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:470
|
|
msgid ""
|
|
"Using your old version of Python and a pair of scripts which are part of "
|
|
"Python 2.3 (db2pickle.py and pickle2db.py, in the Tools/scripts directory) "
|
|
"you can convert your old database files to the new format. Using your old "
|
|
"Python version, run the db2pickle.py script to convert it to a pickle, e.g.::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:477
|
|
msgid "Rename your database file::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:481
|
|
msgid "Now convert the pickle file to a new format database::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/general.rst:485
|
|
msgid ""
|
|
"The precise commands you use will vary depending on the particulars of your "
|
|
"installation. For full details about operation of these two scripts check "
|
|
"the doc string at the start of each one."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:5
|
|
msgid "Graphic User Interface FAQ"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:12
|
|
msgid "What platform-independent GUI toolkits exist for Python?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:14
|
|
msgid "Depending on what platform(s) you are aiming at, there are several."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:19
|
|
msgid "Tkinter"
|
|
msgstr ""
|
|
|
|
# 69a9b8750ffc4acfb580f6a4a9dd3038
|
|
#: ../src/Doc/faq/gui.rst:21
|
|
msgid ""
|
|
"Standard builds of Python include an object-oriented interface to the Tcl/Tk "
|
|
"widget set, called Tkinter. This is probably the easiest to install and "
|
|
"use. For more info about Tk, including pointers to the source, see the Tcl/"
|
|
"Tk home page at http://www.tcl.tk. Tcl/Tk is fully portable to the Mac OS "
|
|
"X, Windows, and Unix platforms."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:28
|
|
msgid "wxWidgets"
|
|
msgstr ""
|
|
|
|
# 954a564ac8da44b99a250d54e9dc373f
|
|
#: ../src/Doc/faq/gui.rst:30
|
|
msgid ""
|
|
"wxWidgets (http://www.wxwidgets.org) is a free, portable GUI class library "
|
|
"written in C++ that provides a native look and feel on a number of "
|
|
"platforms, with Windows, Mac OS X, GTK, X11, all listed as current stable "
|
|
"targets. Language bindings are available for a number of languages "
|
|
"including Python, Perl, Ruby, etc."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:36
|
|
msgid ""
|
|
"wxPython (http://www.wxpython.org) is the Python binding for wxwidgets. "
|
|
"While it often lags slightly behind the official wxWidgets releases, it also "
|
|
"offers a number of features via pure Python extensions that are not "
|
|
"available in other language bindings. There is an active wxPython user and "
|
|
"developer community."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:42
|
|
msgid ""
|
|
"Both wxWidgets and wxPython are free, open source, software with permissive "
|
|
"licences that allow their use in commercial products as well as in freeware "
|
|
"or shareware."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:48
|
|
msgid "Qt"
|
|
msgstr ""
|
|
|
|
# 2e5cdcfa960a4522b7ce1e4d3b0d2d6f
|
|
#: ../src/Doc/faq/gui.rst:50
|
|
msgid ""
|
|
"There are bindings available for the Qt toolkit (using either `PyQt <http://"
|
|
"www.riverbankcomputing.co.uk/software/pyqt/intro>`_ or `PySide <http://www."
|
|
"pyside.org/>`_) and for KDE (`PyKDE <https://techbase.kde.org/Development/"
|
|
"Languages/Python>`__). PyQt is currently more mature than PySide, but you "
|
|
"must buy a PyQt license from `Riverbank Computing <http://www."
|
|
"riverbankcomputing.co.uk/software/pyqt/license>`_ if you want to write "
|
|
"proprietary applications. PySide is free for all applications."
|
|
msgstr ""
|
|
|
|
# bfe2898e8b9949bb84794a0777ebf205
|
|
#: ../src/Doc/faq/gui.rst:57
|
|
msgid ""
|
|
"Qt 4.5 upwards is licensed under the LGPL license; also, commercial licenses "
|
|
"are available from `The Qt Company <http://www.qt.io/licensing/>`_."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:61
|
|
msgid "Gtk+"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:63
|
|
msgid ""
|
|
"PyGtk bindings for the `Gtk+ toolkit <http://www.gtk.org>`_ have been "
|
|
"implemented by James Henstridge; see <http://www.pygtk.org>."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:67
|
|
msgid "FLTK"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:69
|
|
msgid ""
|
|
"Python bindings for `the FLTK toolkit <http://www.fltk.org>`_, a simple yet "
|
|
"powerful and mature cross-platform windowing system, are available from `the "
|
|
"PyFLTK project <http://pyfltk.sourceforge.net>`_."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:75
|
|
msgid "FOX"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:77
|
|
msgid ""
|
|
"A wrapper for `the FOX toolkit <http://www.fox-toolkit.org/>`_ called `FXpy "
|
|
"<http://fxpy.sourceforge.net/>`_ is available. FOX supports both Unix "
|
|
"variants and Windows."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:83
|
|
msgid "OpenGL"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:85
|
|
msgid "For OpenGL bindings, see `PyOpenGL <http://pyopengl.sourceforge.net>`_."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:89
|
|
msgid "What platform-specific GUI toolkits exist for Python?"
|
|
msgstr ""
|
|
|
|
# 7690fb7f0f05419fb4ae7082c765219c
|
|
#: ../src/Doc/faq/gui.rst:91
|
|
msgid ""
|
|
"By installing the `PyObjc Objective-C bridge <https://pythonhosted.org/"
|
|
"pyobjc/>`_, Python programs can use Mac OS X's Cocoa libraries."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:95
|
|
msgid ""
|
|
":ref:`Pythonwin <windows-faq>` by Mark Hammond includes an interface to the "
|
|
"Microsoft Foundation Classes and a Python programming environment that's "
|
|
"written mostly in Python using the MFC classes."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:101
|
|
msgid "Tkinter questions"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:104
|
|
msgid "How do I freeze Tkinter applications?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:106
|
|
msgid ""
|
|
"Freeze is a tool to create stand-alone applications. When freezing Tkinter "
|
|
"applications, the applications will not be truly stand-alone, as the "
|
|
"application will still need the Tcl and Tk libraries."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:110
|
|
msgid ""
|
|
"One solution is to ship the application with the Tcl and Tk libraries, and "
|
|
"point to them at run-time using the :envvar:`TCL_LIBRARY` and :envvar:"
|
|
"`TK_LIBRARY` environment variables."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:114
|
|
msgid ""
|
|
"To get truly stand-alone applications, the Tcl scripts that form the library "
|
|
"have to be integrated into the application as well. One tool supporting that "
|
|
"is SAM (stand-alone modules), which is part of the Tix distribution (http://"
|
|
"tix.sourceforge.net/)."
|
|
msgstr ""
|
|
|
|
# 305a161b8df040a5977ca7cfe21f949b
|
|
#: ../src/Doc/faq/gui.rst:119
|
|
msgid ""
|
|
"Build Tix with SAM enabled, perform the appropriate call to :c:func:"
|
|
"`Tclsam_init`, etc. inside Python's :file:`Modules/tkappinit.c`, and link "
|
|
"with libtclsam and libtksam (you might include the Tix libraries as well)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:126
|
|
msgid "Can I have Tk events handled while waiting for I/O?"
|
|
msgstr ""
|
|
|
|
# 29d3a0c48fc8439492bc34338ead5dbd
|
|
#: ../src/Doc/faq/gui.rst:128
|
|
msgid ""
|
|
"Yes, and you don't even need threads! But you'll have to restructure your I/"
|
|
"O code a bit. Tk has the equivalent of Xt's :c:func:`XtAddInput()` call, "
|
|
"which allows you to register a callback function which will be called from "
|
|
"the Tk mainloop when I/O is possible on a file descriptor. Here's what you "
|
|
"need::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:136
|
|
msgid ""
|
|
"The file may be a Python file or socket object (actually, anything with a "
|
|
"fileno() method), or an integer file descriptor. The mask is one of the "
|
|
"constants tkinter.READABLE or tkinter.WRITABLE. The callback is called as "
|
|
"follows::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:143
|
|
msgid "You must unregister the callback when you're done, using ::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:147
|
|
msgid ""
|
|
"Note: since you don't know *how many bytes* are available for reading, you "
|
|
"can't use the Python file object's read or readline methods, since these "
|
|
"will insist on reading a predefined number of bytes. For sockets, the :meth:"
|
|
"`recv` or :meth:`recvfrom` methods will work fine; for other files, use ``os."
|
|
"read(file.fileno(), maxbytecount)``."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:155
|
|
msgid "I can't get key bindings to work in Tkinter: why?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:157
|
|
msgid ""
|
|
"An often-heard complaint is that event handlers bound to events with the :"
|
|
"meth:`bind` method don't get handled even when the appropriate key is "
|
|
"pressed."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/gui.rst:160
|
|
msgid ""
|
|
"The most common cause is that the widget to which the binding applies "
|
|
"doesn't have \"keyboard focus\". Check out the Tk documentation for the "
|
|
"focus command. Usually a widget is given the keyboard focus by clicking in "
|
|
"it (but not for labels; see the takefocus option)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/index.rst:5
|
|
msgid "Python Frequently Asked Questions"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/installed.rst:3
|
|
msgid "\"Why is Python Installed on my Computer?\" FAQ"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/installed.rst:8
|
|
msgid ""
|
|
"Python is a programming language. It's used for many different "
|
|
"applications. It's used in some high schools and colleges as an introductory "
|
|
"programming language because Python is easy to learn, but it's also used by "
|
|
"professional software developers at places such as Google, NASA, and "
|
|
"Lucasfilm Ltd."
|
|
msgstr ""
|
|
|
|
# 8402e288ce5b4bfcbc76e19a194c0919
|
|
#: ../src/Doc/faq/installed.rst:13
|
|
msgid ""
|
|
"If you wish to learn more about Python, start with the `Beginner's Guide to "
|
|
"Python <https://wiki.python.org/moin/BeginnersGuide>`_."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/installed.rst:18
|
|
msgid "Why is Python installed on my machine?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/installed.rst:20
|
|
msgid ""
|
|
"If you find Python installed on your system but don't remember installing "
|
|
"it, there are several possible ways it could have gotten there."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/installed.rst:23
|
|
msgid ""
|
|
"Perhaps another user on the computer wanted to learn programming and "
|
|
"installed it; you'll have to figure out who's been using the machine and "
|
|
"might have installed it."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/installed.rst:26
|
|
msgid ""
|
|
"A third-party application installed on the machine might have been written "
|
|
"in Python and included a Python installation. For a home computer, the most "
|
|
"common such application is `PySol <http://pysolfc.sourceforge.net/>`_, a "
|
|
"solitaire game that includes over 1000 different games and variations."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/installed.rst:30
|
|
msgid ""
|
|
"Some Windows machines also have Python installed. At this writing we're "
|
|
"aware of computers from Hewlett-Packard and Compaq that include Python. "
|
|
"Apparently some of HP/Compaq's administrative tools are written in Python."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/installed.rst:33
|
|
msgid ""
|
|
"All Apple computers running Mac OS X have Python installed; it's included in "
|
|
"the base installation."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/installed.rst:38
|
|
msgid "Can I delete Python?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/installed.rst:40
|
|
msgid "That depends on where Python came from."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/installed.rst:42
|
|
msgid ""
|
|
"If someone installed it deliberately, you can remove it without hurting "
|
|
"anything. On Windows, use the Add/Remove Programs icon in the Control Panel."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/installed.rst:45
|
|
msgid ""
|
|
"If Python was installed by a third-party application, you can also remove "
|
|
"it, but that application will no longer work. You should use that "
|
|
"application's uninstaller rather than removing Python directly."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/installed.rst:49
|
|
msgid ""
|
|
"If Python came with your operating system, removing it is not recommended. "
|
|
"If you remove it, whatever tools were written in Python will no longer run, "
|
|
"and some of them might be important to you. Reinstalling the whole system "
|
|
"would then be required to fix things again."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:5
|
|
msgid "Library and Extension FAQ"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:12
|
|
msgid "General Library Questions"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:15
|
|
msgid "How do I find a module or application to perform task X?"
|
|
msgstr ""
|
|
|
|
# bc3737a59e9446b1aa99fa07fc18d033
|
|
#: ../src/Doc/faq/library.rst:17
|
|
msgid ""
|
|
"Check :ref:`the Library Reference <library-index>` to see if there's a "
|
|
"relevant standard library module. (Eventually you'll learn what's in the "
|
|
"standard library and will be able to skip this step.)"
|
|
msgstr ""
|
|
|
|
# 05aa2fcc1b844bd49c6b388e40f08923
|
|
#: ../src/Doc/faq/library.rst:21
|
|
msgid ""
|
|
"For third-party packages, search the `Python Package Index <https://pypi."
|
|
"python.org/pypi>`_ or try `Google <https://www.google.com>`_ or another Web "
|
|
"search engine. Searching for \"Python\" plus a keyword or two for your "
|
|
"topic of interest will usually find something helpful."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:28
|
|
msgid "Where is the math.py (socket.py, regex.py, etc.) source file?"
|
|
msgstr ""
|
|
|
|
# a85fce27be314446b1f02cbc9f6d5a3a
|
|
#: ../src/Doc/faq/library.rst:30
|
|
msgid ""
|
|
"If you can't find a source file for a module it may be a built-in or "
|
|
"dynamically loaded module implemented in C, C++ or other compiled language. "
|
|
"In this case you may not have the source file or it may be something like :"
|
|
"file:`mathmodule.c`, somewhere in a C source directory (not on the Python "
|
|
"Path)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:35
|
|
msgid "There are (at least) three kinds of modules in Python:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:37
|
|
msgid "modules written in Python (.py);"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:38
|
|
msgid ""
|
|
"modules written in C and dynamically loaded (.dll, .pyd, .so, .sl, etc);"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:39
|
|
msgid ""
|
|
"modules written in C and linked with the interpreter; to get a list of "
|
|
"these, type::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:47
|
|
msgid "How do I make a Python script executable on Unix?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:49
|
|
msgid ""
|
|
"You need to do two things: the script file's mode must be executable and the "
|
|
"first line must begin with ``#!`` followed by the path of the Python "
|
|
"interpreter."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:53
|
|
msgid ""
|
|
"The first is done by executing ``chmod +x scriptfile`` or perhaps ``chmod "
|
|
"755 scriptfile``."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:56
|
|
msgid ""
|
|
"The second can be done in a number of ways. The most straightforward way is "
|
|
"to write ::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:61
|
|
msgid ""
|
|
"as the very first line of your file, using the pathname for where the Python "
|
|
"interpreter is installed on your platform."
|
|
msgstr ""
|
|
|
|
# 0a01ff692448441bb8c810e2376a53ec
|
|
#: ../src/Doc/faq/library.rst:64
|
|
msgid ""
|
|
"If you would like the script to be independent of where the Python "
|
|
"interpreter lives, you can use the :program:`env` program. Almost all Unix "
|
|
"variants support the following, assuming the Python interpreter is in a "
|
|
"directory on the user's :envvar:`PATH`::"
|
|
msgstr ""
|
|
|
|
# 5bb64238d1004d68afe1fc24428456e1
|
|
#: ../src/Doc/faq/library.rst:71
|
|
msgid ""
|
|
"*Don't* do this for CGI scripts. The :envvar:`PATH` variable for CGI "
|
|
"scripts is often very minimal, so you need to use the actual absolute "
|
|
"pathname of the interpreter."
|
|
msgstr ""
|
|
|
|
# 11c70aaee9f04c3ab6268f31f16ca1a9
|
|
#: ../src/Doc/faq/library.rst:75
|
|
msgid ""
|
|
"Occasionally, a user's environment is so full that the :program:`/usr/bin/"
|
|
"env` program fails; or there's no env program at all. In that case, you can "
|
|
"try the following hack (due to Alex Rezinsky)::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:84
|
|
msgid ""
|
|
"The minor disadvantage is that this defines the script's __doc__ string. "
|
|
"However, you can fix that by adding ::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:92
|
|
msgid "Is there a curses/termcap package for Python?"
|
|
msgstr ""
|
|
|
|
# f3b0852cce544578bf376fed21906a0b
|
|
#: ../src/Doc/faq/library.rst:96
|
|
msgid ""
|
|
"For Unix variants the standard Python source distribution comes with a "
|
|
"curses module in the :source:`Modules` subdirectory, though it's not "
|
|
"compiled by default. (Note that this is not available in the Windows "
|
|
"distribution -- there is no curses module for Windows.)"
|
|
msgstr ""
|
|
|
|
# aa5a87f13faa48da950fd7339da90add
|
|
#: ../src/Doc/faq/library.rst:101
|
|
msgid ""
|
|
"The :mod:`curses` module supports basic curses features as well as many "
|
|
"additional functions from ncurses and SYSV curses such as colour, "
|
|
"alternative character set support, pads, and mouse support. This means the "
|
|
"module isn't compatible with operating systems that only have BSD curses, "
|
|
"but there don't seem to be any currently maintained OSes that fall into this "
|
|
"category."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:107
|
|
msgid ""
|
|
"For Windows: use `the consolelib module <http://effbot.org/zone/console-"
|
|
"index.htm>`_."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:112
|
|
msgid "Is there an equivalent to C's onexit() in Python?"
|
|
msgstr ""
|
|
|
|
# 5e5d2c69ded348f5a7e91e468c340bea
|
|
#: ../src/Doc/faq/library.rst:114
|
|
msgid ""
|
|
"The :mod:`atexit` module provides a register function that is similar to "
|
|
"C's :c:func:`onexit`."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:119
|
|
msgid "Why don't my signal handlers work?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:121
|
|
msgid ""
|
|
"The most common problem is that the signal handler is declared with the "
|
|
"wrong argument list. It is called as ::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:126
|
|
msgid "so it should be declared with two arguments::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:133
|
|
msgid "Common tasks"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:136
|
|
msgid "How do I test a Python program or component?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:138
|
|
msgid ""
|
|
"Python comes with two testing frameworks. The :mod:`doctest` module finds "
|
|
"examples in the docstrings for a module and runs them, comparing the output "
|
|
"with the expected output given in the docstring."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:142
|
|
msgid ""
|
|
"The :mod:`unittest` module is a fancier testing framework modelled on Java "
|
|
"and Smalltalk testing frameworks."
|
|
msgstr ""
|
|
|
|
# 4657b944660745599833f9be205984ef
|
|
#: ../src/Doc/faq/library.rst:145
|
|
msgid ""
|
|
"To make testing easier, you should use good modular design in your program. "
|
|
"Your program should have almost all functionality encapsulated in either "
|
|
"functions or class methods -- and this sometimes has the surprising and "
|
|
"delightful effect of making the program run faster (because local variable "
|
|
"accesses are faster than global accesses). Furthermore the program should "
|
|
"avoid depending on mutating global variables, since this makes testing much "
|
|
"more difficult to do."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:153
|
|
msgid "The \"global main logic\" of your program may be as simple as ::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:158
|
|
msgid "at the bottom of the main module of your program."
|
|
msgstr ""
|
|
|
|
# 90221ca6b4024e4cbc6d229d3bc555d1
|
|
#: ../src/Doc/faq/library.rst:160
|
|
msgid ""
|
|
"Once your program is organized as a tractable collection of functions and "
|
|
"class behaviours you should write test functions that exercise the "
|
|
"behaviours. A test suite that automates a sequence of tests can be "
|
|
"associated with each module. This sounds like a lot of work, but since "
|
|
"Python is so terse and flexible it's surprisingly easy. You can make coding "
|
|
"much more pleasant and fun by writing your test functions in parallel with "
|
|
"the \"production code\", since this makes it easy to find bugs and even "
|
|
"design flaws earlier."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:168
|
|
msgid ""
|
|
"\"Support modules\" that are not intended to be the main module of a program "
|
|
"may include a self-test of the module. ::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:174
|
|
msgid ""
|
|
"Even programs that interact with complex external interfaces may be tested "
|
|
"when the external interfaces are unavailable by using \"fake\" interfaces "
|
|
"implemented in Python."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:180
|
|
msgid "How do I create documentation from doc strings?"
|
|
msgstr ""
|
|
|
|
# fad7f59855764b6b95785f1396abb188
|
|
#: ../src/Doc/faq/library.rst:182
|
|
msgid ""
|
|
"The :mod:`pydoc` module can create HTML from the doc strings in your Python "
|
|
"source code. An alternative for creating API documentation purely from "
|
|
"docstrings is `epydoc <http://epydoc.sourceforge.net/>`_. `Sphinx <http://"
|
|
"sphinx-doc.org>`_ can also include docstring content."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:189
|
|
msgid "How do I get a single keypress at a time?"
|
|
msgstr ""
|
|
|
|
# 5c0167168bc34f919136b9f5cb1a1189
|
|
#: ../src/Doc/faq/library.rst:191
|
|
msgid ""
|
|
"For Unix variants there are several solutions. It's straightforward to do "
|
|
"this using curses, but curses is a fairly large module to learn. Here's a "
|
|
"solution without curses::"
|
|
msgstr ""
|
|
|
|
# a715987744e34d5fbc5dfaa22bb4515e
|
|
#: ../src/Doc/faq/library.rst:216
|
|
msgid ""
|
|
"You need the :mod:`termios` and the :mod:`fcntl` module for any of this to "
|
|
"work, and I've only tried it on Linux, though it should work elsewhere. In "
|
|
"this code, characters are read and printed one at a time."
|
|
msgstr ""
|
|
|
|
# 813f540d56334fb4b066a8fb18b481a3
|
|
#: ../src/Doc/faq/library.rst:220
|
|
msgid ""
|
|
":func:`termios.tcsetattr` turns off stdin's echoing and disables canonical "
|
|
"mode. :func:`fcntl.fnctl` is used to obtain stdin's file descriptor flags "
|
|
"and modify them for non-blocking mode. Since reading stdin when it is empty "
|
|
"results in an :exc:`IOError`, this error is caught and ignored."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:227
|
|
msgid "Threads"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:230
|
|
msgid "How do I program using threads?"
|
|
msgstr ""
|
|
|
|
# aade5bd432964f7f8e4a17d3e91ad817
|
|
#: ../src/Doc/faq/library.rst:234
|
|
msgid ""
|
|
"Be sure to use the :mod:`threading` module and not the :mod:`thread` module. "
|
|
"The :mod:`threading` module builds convenient abstractions on top of the low-"
|
|
"level primitives provided by the :mod:`thread` module."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:238
|
|
msgid ""
|
|
"Aahz has a set of slides from his threading tutorial that are helpful; see "
|
|
"http://www.pythoncraft.com/OSCON2001/."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:243
|
|
msgid "None of my threads seem to run: why?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:245
|
|
msgid ""
|
|
"As soon as the main thread exits, all threads are killed. Your main thread "
|
|
"is running too quickly, giving the threads no time to do any work."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:248
|
|
msgid ""
|
|
"A simple fix is to add a sleep to the end of the program that's long enough "
|
|
"for all the threads to finish::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:262
|
|
msgid ""
|
|
"But now (on many platforms) the threads don't run in parallel, but appear to "
|
|
"run sequentially, one at a time! The reason is that the OS thread scheduler "
|
|
"doesn't start a new thread until the previous thread is blocked."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:266
|
|
msgid "A simple fix is to add a tiny sleep to the start of the run function::"
|
|
msgstr ""
|
|
|
|
# aea21e6b09a041ff957fecb4b0a89c0f
|
|
#: ../src/Doc/faq/library.rst:278
|
|
msgid ""
|
|
"Instead of trying to guess a good delay value for :func:`time.sleep`, it's "
|
|
"better to use some kind of semaphore mechanism. One idea is to use the :mod:"
|
|
"`Queue` module to create a queue object, let each thread append a token to "
|
|
"the queue when it finishes, and let the main thread read as many tokens from "
|
|
"the queue as there are threads."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:286
|
|
msgid "How do I parcel out work among a bunch of worker threads?"
|
|
msgstr ""
|
|
|
|
# 5030478637c142e3a6cd9440f3d27b9e
|
|
#: ../src/Doc/faq/library.rst:288
|
|
msgid ""
|
|
"Use the :mod:`Queue` module to create a queue containing a list of jobs. "
|
|
"The :class:`~Queue.Queue` class maintains a list of objects and has a ``."
|
|
"put(obj)`` method that adds items to the queue and a ``.get()`` method to "
|
|
"return them. The class will take care of the locking necessary to ensure "
|
|
"that each job is handed out exactly once."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:294
|
|
msgid "Here's a trivial example::"
|
|
msgstr ""
|
|
|
|
# 9388dec82b3f4056a524814851ce0228
|
|
#: ../src/Doc/faq/library.rst:332
|
|
msgid "When run, this will produce the following output:"
|
|
msgstr ""
|
|
|
|
# 873b457452d44ef0a185bbfc7967ca31
|
|
#: ../src/Doc/faq/library.rst:350
|
|
msgid ""
|
|
"Consult the module's documentation for more details; the :class:`~Queue."
|
|
"Queue` class provides a featureful interface."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:355
|
|
msgid "What kinds of global value mutation are thread-safe?"
|
|
msgstr ""
|
|
|
|
# 98825d7125a74191bf625b903e0fa199
|
|
#: ../src/Doc/faq/library.rst:357
|
|
msgid ""
|
|
"A :term:`global interpreter lock` (GIL) is used internally to ensure that "
|
|
"only one thread runs in the Python VM at a time. In general, Python offers "
|
|
"to switch among threads only between bytecode instructions; how frequently "
|
|
"it switches can be set via :func:`sys.setcheckinterval`. Each bytecode "
|
|
"instruction and therefore all the C implementation code reached from each "
|
|
"instruction is therefore atomic from the point of view of a Python program."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:364
|
|
msgid ""
|
|
"In theory, this means an exact accounting requires an exact understanding of "
|
|
"the PVM bytecode implementation. In practice, it means that operations on "
|
|
"shared variables of built-in data types (ints, lists, dicts, etc) that "
|
|
"\"look atomic\" really are."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:369
|
|
msgid ""
|
|
"For example, the following operations are all atomic (L, L1, L2 are lists, "
|
|
"D, D1, D2 are dicts, x, y are objects, i, j are ints)::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:384
|
|
msgid "These aren't::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:391
|
|
msgid ""
|
|
"Operations that replace other objects may invoke those other objects' :meth:"
|
|
"`__del__` method when their reference count reaches zero, and that can "
|
|
"affect things. This is especially true for the mass updates to dictionaries "
|
|
"and lists. When in doubt, use a mutex!"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:398
|
|
msgid "Can't we get rid of the Global Interpreter Lock?"
|
|
msgstr ""
|
|
|
|
# 4645f49916d74429b99ac83c664c66b2
|
|
#: ../src/Doc/faq/library.rst:403
|
|
msgid ""
|
|
"The :term:`global interpreter lock` (GIL) is often seen as a hindrance to "
|
|
"Python's deployment on high-end multiprocessor server machines, because a "
|
|
"multi-threaded Python program effectively only uses one CPU, due to the "
|
|
"insistence that (almost) all Python code can only run while the GIL is held."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:408
|
|
msgid ""
|
|
"Back in the days of Python 1.5, Greg Stein actually implemented a "
|
|
"comprehensive patch set (the \"free threading\" patches) that removed the "
|
|
"GIL and replaced it with fine-grained locking. Unfortunately, even on "
|
|
"Windows (where locks are very efficient) this ran ordinary Python code about "
|
|
"twice as slow as the interpreter using the GIL. On Linux the performance "
|
|
"loss was even worse because pthread locks aren't as efficient."
|
|
msgstr ""
|
|
|
|
# 0d1b3cb5fbc646a996f627baf27c1b2d
|
|
#: ../src/Doc/faq/library.rst:415
|
|
msgid ""
|
|
"Since then, the idea of getting rid of the GIL has occasionally come up but "
|
|
"nobody has found a way to deal with the expected slowdown, and users who "
|
|
"don't use threads would not be happy if their code ran at half the speed. "
|
|
"Greg's free threading patch set has not been kept up-to-date for later "
|
|
"Python versions."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:420
|
|
msgid ""
|
|
"This doesn't mean that you can't make good use of Python on multi-CPU "
|
|
"machines! You just have to be creative with dividing the work up between "
|
|
"multiple *processes* rather than multiple *threads*. Judicious use of C "
|
|
"extensions will also help; if you use a C extension to perform a time-"
|
|
"consuming task, the extension can release the GIL while the thread of "
|
|
"execution is in the C code and allow other threads to get some work done."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:427
|
|
msgid ""
|
|
"It has been suggested that the GIL should be a per-interpreter-state lock "
|
|
"rather than truly global; interpreters then wouldn't be able to share "
|
|
"objects. Unfortunately, this isn't likely to happen either. It would be a "
|
|
"tremendous amount of work, because many object implementations currently "
|
|
"have global state. For example, small integers and short strings are cached; "
|
|
"these caches would have to be moved to the interpreter state. Other object "
|
|
"types have their own free list; these free lists would have to be moved to "
|
|
"the interpreter state. And so on."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:436
|
|
msgid ""
|
|
"And I doubt that it can even be done in finite time, because the same "
|
|
"problem exists for 3rd party extensions. It is likely that 3rd party "
|
|
"extensions are being written at a faster rate than you can convert them to "
|
|
"store all their global state in the interpreter state."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:441
|
|
msgid ""
|
|
"And finally, once you have multiple interpreters not sharing any state, what "
|
|
"have you gained over running each interpreter in a separate process?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:446
|
|
msgid "Input and Output"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:449
|
|
msgid "How do I delete a file? (And other file questions...)"
|
|
msgstr ""
|
|
|
|
# 71640ee4d2224271bacdc47863e5b350
|
|
#: ../src/Doc/faq/library.rst:451
|
|
msgid ""
|
|
"Use ``os.remove(filename)`` or ``os.unlink(filename)``; for documentation, "
|
|
"see the :mod:`os` module. The two functions are identical; :func:`unlink` "
|
|
"is simply the name of the Unix system call for this function."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:455
|
|
msgid ""
|
|
"To remove a directory, use :func:`os.rmdir`; use :func:`os.mkdir` to create "
|
|
"one. ``os.makedirs(path)`` will create any intermediate directories in "
|
|
"``path`` that don't exist. ``os.removedirs(path)`` will remove intermediate "
|
|
"directories as long as they're empty; if you want to delete an entire "
|
|
"directory tree and its contents, use :func:`shutil.rmtree`."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:461
|
|
msgid "To rename a file, use ``os.rename(old_path, new_path)``."
|
|
msgstr ""
|
|
|
|
# 0dbfd8ffe6b347cbb8606e4b428e007c
|
|
#: ../src/Doc/faq/library.rst:463
|
|
msgid ""
|
|
"To truncate a file, open it using ``f = open(filename, \"r+\")``, and use "
|
|
"``f.truncate(offset)``; offset defaults to the current seek position. "
|
|
"There's also ``os.ftruncate(fd, offset)`` for files opened with :func:`os."
|
|
"open`, where *fd* is the file descriptor (a small integer)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:468
|
|
msgid ""
|
|
"The :mod:`shutil` module also contains a number of functions to work on "
|
|
"files including :func:`~shutil.copyfile`, :func:`~shutil.copytree`, and :"
|
|
"func:`~shutil.rmtree`."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:474
|
|
msgid "How do I copy a file?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:476
|
|
msgid ""
|
|
"The :mod:`shutil` module contains a :func:`~shutil.copyfile` function. Note "
|
|
"that on MacOS 9 it doesn't copy the resource fork and Finder info."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:481
|
|
msgid "How do I read (or write) binary data?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:483
|
|
msgid ""
|
|
"To read or write complex binary data formats, it's best to use the :mod:"
|
|
"`struct` module. It allows you to take a string containing binary data "
|
|
"(usually numbers) and convert it to Python objects; and vice versa."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:487
|
|
msgid ""
|
|
"For example, the following code reads two 2-byte integers and one 4-byte "
|
|
"integer in big-endian format from a file::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:496
|
|
msgid ""
|
|
"The '>' in the format string forces big-endian data; the letter 'h' reads "
|
|
"one \"short integer\" (2 bytes), and 'l' reads one \"long integer\" (4 "
|
|
"bytes) from the string."
|
|
msgstr ""
|
|
|
|
# fef9fd4c406745759a75aad37e902d24
|
|
#: ../src/Doc/faq/library.rst:500
|
|
msgid ""
|
|
"For data that is more regular (e.g. a homogeneous list of ints or floats), "
|
|
"you can also use the :mod:`array` module."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:505
|
|
msgid "I can't seem to use os.read() on a pipe created with os.popen(); why?"
|
|
msgstr ""
|
|
|
|
# d22d10e0ad1c44028fd64db3211e81d7
|
|
#: ../src/Doc/faq/library.rst:507
|
|
msgid ""
|
|
":func:`os.read` is a low-level function which takes a file descriptor, a "
|
|
"small integer representing the opened file. :func:`os.popen` creates a high-"
|
|
"level file object, the same type returned by the built-in :func:`open` "
|
|
"function. Thus, to read *n* bytes from a pipe *p* created with :func:`os."
|
|
"popen`, you need to use ``p.read(n)``."
|
|
msgstr ""
|
|
|
|
# f819db3658c14897b532123365257ba3
|
|
#: ../src/Doc/faq/library.rst:515
|
|
msgid ""
|
|
"How do I run a subprocess with pipes connected to both input and output?"
|
|
msgstr ""
|
|
|
|
# 7e374660290c446781cc624c56dbfd07
|
|
#: ../src/Doc/faq/library.rst:519
|
|
msgid "Use the :mod:`popen2` module. For example::"
|
|
msgstr ""
|
|
|
|
# dec6101a723d48708d571b72ded2b902
|
|
#: ../src/Doc/faq/library.rst:527
|
|
msgid ""
|
|
"Warning: in general it is unwise to do this because you can easily cause a "
|
|
"deadlock where your process is blocked waiting for output from the child "
|
|
"while the child is blocked waiting for input from you. This can be caused "
|
|
"by the parent expecting the child to output more text than it does or by "
|
|
"data being stuck in stdio buffers due to lack of flushing. The Python "
|
|
"parent can of course explicitly flush the data it sends to the child before "
|
|
"it reads any output, but if the child is a naive C program it may have been "
|
|
"written to never explicitly flush its output, even if it is interactive, "
|
|
"since flushing is normally automatic."
|
|
msgstr ""
|
|
|
|
# 1197cc04e58e49a1b97b882883642028
|
|
#: ../src/Doc/faq/library.rst:537
|
|
msgid ""
|
|
"Note that a deadlock is also possible if you use :func:`popen3` to read "
|
|
"stdout and stderr. If one of the two is too large for the internal buffer "
|
|
"(increasing the buffer size does not help) and you ``read()`` the other one "
|
|
"first, there is a deadlock, too."
|
|
msgstr ""
|
|
|
|
# c8b4db825b5648e680aa36cccf590464
|
|
#: ../src/Doc/faq/library.rst:542
|
|
msgid ""
|
|
"Note on a bug in popen2: unless your program calls ``wait()`` or "
|
|
"``waitpid()``, finished child processes are never removed, and eventually "
|
|
"calls to popen2 will fail because of a limit on the number of child "
|
|
"processes. Calling :func:`os.waitpid` with the :data:`os.WNOHANG` option "
|
|
"can prevent this; a good place to insert such a call would be before calling "
|
|
"``popen2`` again."
|
|
msgstr ""
|
|
|
|
# 10fb3be321ea4761a378d835626903d9
|
|
#: ../src/Doc/faq/library.rst:548
|
|
msgid ""
|
|
"In many cases, all you really need is to run some data through a command and "
|
|
"get the result back. Unless the amount of data is very large, the easiest "
|
|
"way to do this is to write it to a temporary file and run the command with "
|
|
"that temporary file as input. The standard module :mod:`tempfile` exports "
|
|
"a :func:`~tempfile.mktemp` function to generate unique temporary file "
|
|
"names. ::"
|
|
msgstr ""
|
|
|
|
# 8b956d91d40445478ec5c8d886d5b7ed
|
|
#: ../src/Doc/faq/library.rst:583
|
|
msgid ""
|
|
"Note that many interactive programs (e.g. vi) don't work well with pipes "
|
|
"substituted for standard input and output. You will have to use pseudo ttys "
|
|
"(\"ptys\") instead of pipes. Or you can use a Python interface to Don Libes' "
|
|
"\"expect\" library. A Python extension that interfaces to expect is called "
|
|
"\"expy\" and available from http://expectpy.sourceforge.net. A pure Python "
|
|
"solution that works like expect is `pexpect <https://pypi.python.org/pypi/"
|
|
"pexpect/>`_."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:592
|
|
msgid "How do I access the serial (RS232) port?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:594
|
|
msgid "For Win32, POSIX (Linux, BSD, etc.), Jython:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:596
|
|
msgid "http://pyserial.sourceforge.net"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:598
|
|
msgid "For Unix, see a Usenet post by Mitch Chapman:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:600
|
|
msgid "http://groups.google.com/groups?selm=34A04430.CF9@ohioee.com"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:604
|
|
msgid "Why doesn't closing sys.stdout (stdin, stderr) really close it?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:606
|
|
msgid ""
|
|
"Python file objects are a high-level layer of abstraction on top of C "
|
|
"streams, which in turn are a medium-level layer of abstraction on top of "
|
|
"(among other things) low-level C file descriptors."
|
|
msgstr ""
|
|
|
|
# 40a02022a26b432aa559de8f54a1b286
|
|
#: ../src/Doc/faq/library.rst:610
|
|
msgid ""
|
|
"For most file objects you create in Python via the built-in ``file`` "
|
|
"constructor, ``f.close()`` marks the Python file object as being closed from "
|
|
"Python's point of view, and also arranges to close the underlying C stream. "
|
|
"This also happens automatically in ``f``'s destructor, when ``f`` becomes "
|
|
"garbage."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:616
|
|
msgid ""
|
|
"But stdin, stdout and stderr are treated specially by Python, because of the "
|
|
"special status also given to them by C. Running ``sys.stdout.close()`` "
|
|
"marks the Python-level file object as being closed, but does *not* close the "
|
|
"associated C stream."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:621
|
|
msgid ""
|
|
"To close the underlying C stream for one of these three, you should first be "
|
|
"sure that's what you really want to do (e.g., you may confuse extension "
|
|
"modules trying to do I/O). If it is, use os.close::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:631
|
|
msgid "Network/Internet Programming"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:634
|
|
msgid "What WWW tools are there for Python?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:636
|
|
msgid ""
|
|
"See the chapters titled :ref:`internet` and :ref:`netdata` in the Library "
|
|
"Reference Manual. Python has many modules that will help you build server-"
|
|
"side and client-side web systems."
|
|
msgstr ""
|
|
|
|
# faca0f8973914815a8d319155ae0de0c
|
|
#: ../src/Doc/faq/library.rst:642
|
|
msgid ""
|
|
"A summary of available frameworks is maintained by Paul Boddie at https://"
|
|
"wiki.python.org/moin/WebProgramming\\ ."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:645
|
|
msgid ""
|
|
"Cameron Laird maintains a useful set of pages about Python web technologies "
|
|
"at http://phaseit.net/claird/comp.lang.python/web_python."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:650
|
|
msgid "How can I mimic CGI form submission (METHOD=POST)?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:652
|
|
msgid ""
|
|
"I would like to retrieve web pages that are the result of POSTing a form. Is "
|
|
"there existing code that would let me do this easily?"
|
|
msgstr ""
|
|
|
|
# cc7f47f414e945268f949aea1bb54a43
|
|
#: ../src/Doc/faq/library.rst:655
|
|
msgid "Yes. Here's a simple example that uses httplib::"
|
|
msgstr ""
|
|
|
|
# 6bbd0565911e4b01849546530b20af6c
|
|
#: ../src/Doc/faq/library.rst:679
|
|
msgid ""
|
|
"Note that in general for percent-encoded POST operations, query strings must "
|
|
"be quoted using :func:`urllib.urlencode`. For example, to send ``name=Guy "
|
|
"Steele, Jr.``::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:689
|
|
msgid "What module should I use to help with generating HTML?"
|
|
msgstr ""
|
|
|
|
# 6562031f44bd408d99eae3425867950a
|
|
#: ../src/Doc/faq/library.rst:693
|
|
msgid ""
|
|
"You can find a collection of useful links on the `Web Programming wiki page "
|
|
"<https://wiki.python.org/moin/WebProgramming>`_."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:698
|
|
msgid "How do I send mail from a Python script?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:700
|
|
msgid "Use the standard library module :mod:`smtplib`."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:702
|
|
msgid ""
|
|
"Here's a very simple interactive mail sender that uses it. This method will "
|
|
"work on any host that supports an SMTP listener. ::"
|
|
msgstr ""
|
|
|
|
# f96b24bc2e6348e99069db16a21c5822
|
|
#: ../src/Doc/faq/library.rst:722
|
|
msgid ""
|
|
"A Unix-only alternative uses sendmail. The location of the sendmail program "
|
|
"varies between systems; sometimes it is ``/usr/lib/sendmail``, sometimes ``/"
|
|
"usr/sbin/sendmail``. The sendmail manual page will help you out. Here's "
|
|
"some sample code::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:741
|
|
msgid "How do I avoid blocking in the connect() method of a socket?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:743
|
|
msgid ""
|
|
"The select module is commonly used to help with asynchronous I/O on sockets."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:745
|
|
msgid ""
|
|
"To prevent the TCP connect from blocking, you can set the socket to non-"
|
|
"blocking mode. Then when you do the ``connect()``, you will either connect "
|
|
"immediately (unlikely) or get an exception that contains the error number as "
|
|
"``.errno``. ``errno.EINPROGRESS`` indicates that the connection is in "
|
|
"progress, but hasn't finished yet. Different OSes will return different "
|
|
"values, so you're going to have to check what's returned on your system."
|
|
msgstr ""
|
|
|
|
# 9d51bbc18a6147c1b3d0996e626eb7b6
|
|
#: ../src/Doc/faq/library.rst:752
|
|
msgid ""
|
|
"You can use the ``connect_ex()`` method to avoid creating an exception. It "
|
|
"will just return the errno value. To poll, you can call ``connect_ex()`` "
|
|
"again later -- 0 or ``errno.EISCONN`` indicate that you're connected -- or "
|
|
"you can pass this socket to select to check if it's writable."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:759
|
|
msgid "Databases"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:762
|
|
msgid "Are there any interfaces to database packages in Python?"
|
|
msgstr ""
|
|
|
|
# 7f73d57d944b41bb8ca122e5e500dda0
|
|
#: ../src/Doc/faq/library.rst:768
|
|
msgid ""
|
|
"Python 2.3 includes the :mod:`bsddb` package which provides an interface to "
|
|
"the BerkeleyDB library. Interfaces to disk-based hashes such as :mod:`DBM "
|
|
"<dbm>` and :mod:`GDBM <gdbm>` are also included with standard Python."
|
|
msgstr ""
|
|
|
|
# e17212ec224c47fb9a41d13b606db95b
|
|
#: ../src/Doc/faq/library.rst:772
|
|
msgid ""
|
|
"Support for most relational databases is available. See the "
|
|
"`DatabaseProgramming wiki page <https://wiki.python.org/moin/"
|
|
"DatabaseProgramming>`_ for details."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:778
|
|
msgid "How do you implement persistent objects in Python?"
|
|
msgstr ""
|
|
|
|
# e19720fb14704b7caf1c8eb52984e685
|
|
#: ../src/Doc/faq/library.rst:780
|
|
msgid ""
|
|
"The :mod:`pickle` library module solves this in a very general way (though "
|
|
"you still can't store things like open files, sockets or windows), and the :"
|
|
"mod:`shelve` library module uses pickle and (g)dbm to create persistent "
|
|
"mappings containing arbitrary Python objects. For better performance, you "
|
|
"can use the :mod:`cPickle` module."
|
|
msgstr ""
|
|
|
|
# 1a7bb612acd8457c96fc689263595d3e
|
|
#: ../src/Doc/faq/library.rst:786
|
|
msgid ""
|
|
"A more awkward way of doing things is to use pickle's little sister, "
|
|
"marshal. The :mod:`marshal` module provides very fast ways to store "
|
|
"noncircular basic Python types to files and strings, and back again. "
|
|
"Although marshal does not do fancy things like store instances or handle "
|
|
"shared references properly, it does run extremely fast. For example, "
|
|
"loading a half megabyte of data may take less than a third of a second. "
|
|
"This often beats doing something more complex and general such as using gdbm "
|
|
"with pickle/shelve."
|
|
msgstr ""
|
|
|
|
# 3840155eab2c46f38734d3b48f7fe0d9
|
|
#: ../src/Doc/faq/library.rst:796
|
|
msgid "Why is cPickle so slow?"
|
|
msgstr ""
|
|
|
|
# 7687ae13889e44908f88e5522dd28712
|
|
#: ../src/Doc/faq/library.rst:800
|
|
msgid ""
|
|
"By default :mod:`pickle` uses a relatively old and slow format for backward "
|
|
"compatibility. You can however specify other protocol versions that are "
|
|
"faster::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:809
|
|
msgid ""
|
|
"If my program crashes with a bsddb (or anydbm) database open, it gets "
|
|
"corrupted. How come?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:811
|
|
msgid ""
|
|
"Databases opened for write access with the bsddb module (and often by the "
|
|
"anydbm module, since it will preferentially use bsddb) must explicitly be "
|
|
"closed using the ``.close()`` method of the database. The underlying "
|
|
"library caches database contents which need to be converted to on-disk form "
|
|
"and written."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:816
|
|
msgid ""
|
|
"If you have initialized a new bsddb database but not written anything to it "
|
|
"before the program crashes, you will often wind up with a zero-length file "
|
|
"and encounter an exception the next time the file is opened."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:822
|
|
msgid ""
|
|
"I tried to open Berkeley DB file, but bsddb produces bsddb.error: (22, "
|
|
"'Invalid argument'). Help! How can I restore my data?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:824
|
|
msgid ""
|
|
"Don't panic! Your data is probably intact. The most frequent cause for the "
|
|
"error is that you tried to open an earlier Berkeley DB file with a later "
|
|
"version of the Berkeley DB library."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:828
|
|
msgid ""
|
|
"Many Linux systems now have all three versions of Berkeley DB available. If "
|
|
"you are migrating from version 1 to a newer version use db_dump185 to dump a "
|
|
"plain text version of the database. If you are migrating from version 2 to "
|
|
"version 3 use db2_dump to create a plain text version of the database. In "
|
|
"either case, use db_load to create a new native database for the latest "
|
|
"version installed on your computer. If you have version 3 of Berkeley DB "
|
|
"installed, you should be able to use db2_load to create a native version 2 "
|
|
"database."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:836
|
|
msgid ""
|
|
"You should move away from Berkeley DB version 1 files because the hash file "
|
|
"code contains known bugs that can corrupt your data."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:841
|
|
msgid "Mathematics and Numerics"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:844
|
|
msgid "How do I generate random numbers in Python?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:846
|
|
msgid ""
|
|
"The standard module :mod:`random` implements a random number generator. "
|
|
"Usage is simple::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:852
|
|
msgid "This returns a random floating point number in the range [0, 1)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:854
|
|
msgid ""
|
|
"There are also many other specialized generators in this module, such as:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:856
|
|
msgid "``randrange(a, b)`` chooses an integer in the range [a, b)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:857
|
|
msgid "``uniform(a, b)`` chooses a floating point number in the range [a, b)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:858
|
|
msgid ""
|
|
"``normalvariate(mean, sdev)`` samples the normal (Gaussian) distribution."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:860
|
|
msgid "Some higher-level functions operate on sequences directly, such as:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:862
|
|
msgid "``choice(S)`` chooses random element from a given sequence"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:863
|
|
msgid "``shuffle(L)`` shuffles a list in-place, i.e. permutes it randomly"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/library.rst:865
|
|
msgid ""
|
|
"There's also a ``Random`` class you can instantiate to create independent "
|
|
"multiple random number generators."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:5
|
|
msgid "Programming FAQ"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:12
|
|
msgid "General Questions"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:15
|
|
msgid ""
|
|
"Is there a source code level debugger with breakpoints, single-stepping, "
|
|
"etc.?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:19
|
|
msgid ""
|
|
"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 ""
|
|
|
|
# bad998877641449e848192d8c2f7b7ca
|
|
#: ../src/Doc/faq/programming.rst:24
|
|
msgid ""
|
|
"The IDLE interactive development environment, which is part of the standard "
|
|
"Python distribution (normally available as Tools/scripts/idle), includes a "
|
|
"graphical debugger."
|
|
msgstr ""
|
|
|
|
# fa25926b9fbe41cca3239569051efc64
|
|
#: ../src/Doc/faq/programming.rst:28
|
|
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 the "
|
|
"`Python for Windows Extensions <http://sourceforge.net/projects/pywin32/>`__ "
|
|
"project and as a part of the ActivePython distribution (see http://www."
|
|
"activestate.com/activepython\\ )."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:35
|
|
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 ""
|
|
|
|
# bfc1271a533e428490bbef17f369d211
|
|
#: ../src/Doc/faq/programming.rst:41
|
|
msgid ""
|
|
"`Eric <http://eric-ide.python-projects.org/>`_ is an IDE built on PyQt and "
|
|
"the Scintilla editing component."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:44
|
|
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 "
|
|
"http://www.gnu.org/software/ddd."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:49
|
|
msgid ""
|
|
"There are a number of commercial Python IDEs that include graphical "
|
|
"debuggers. They include:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:52
|
|
msgid "Wing IDE (http://wingware.com/)"
|
|
msgstr ""
|
|
|
|
# cd51e87efa494b02a79da6f88505405a
|
|
#: ../src/Doc/faq/programming.rst:53
|
|
msgid "Komodo IDE (http://komodoide.com/)"
|
|
msgstr ""
|
|
|
|
# ea0fa502768142ea8d51289781c801c5
|
|
#: ../src/Doc/faq/programming.rst:54
|
|
msgid "PyCharm (https://www.jetbrains.com/pycharm/)"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:58
|
|
msgid "Is there a tool to help find bugs or perform static analysis?"
|
|
msgstr ""
|
|
|
|
# cf24545073b64b608121d95b7227749a
|
|
#: ../src/Doc/faq/programming.rst:62
|
|
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 ""
|
|
|
|
# c3d75402116446f08d24651b60587ab5
|
|
#: ../src/Doc/faq/programming.rst:66
|
|
msgid ""
|
|
"`Pylint <http://www.logilab.org/projects/pylint>`_ 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. http://docs.pylint.org/ provides a full list of Pylint's features."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:76
|
|
msgid "How can I create a stand-alone binary from a Python script?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:78
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:84
|
|
msgid ""
|
|
"One is to use the freeze tool, which is included in the Python source tree "
|
|
"as ``Tools/freeze``. It converts Python byte code to C arrays; a C compiler "
|
|
"you can embed all your modules into a new program, which is then linked with "
|
|
"the standard Python modules."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:89
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:98
|
|
msgid ""
|
|
"Obviously, freeze requires a C compiler. There are several other utilities "
|
|
"which don't. One is Thomas Heller's py2exe (Windows only) at"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:101
|
|
msgid "http://www.py2exe.org/"
|
|
msgstr ""
|
|
|
|
# ab1effd97d9a4db6b9e2c200578fbfdf
|
|
#: ../src/Doc/faq/programming.rst:103
|
|
msgid ""
|
|
"Another tool is Anthony Tuininga's `cx_Freeze <http://cx-freeze.sourceforge."
|
|
"net/>`_."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:107
|
|
msgid "Are there coding standards or a style guide for Python programs?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:109
|
|
msgid ""
|
|
"Yes. The coding style required for standard library modules is documented "
|
|
"as :pep:`8`."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:114
|
|
msgid "My program is too slow. How do I speed it up?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:116
|
|
msgid ""
|
|
"That's a tough one, in general. There are many tricks to speed up Python "
|
|
"code; consider rewriting parts in C as a last resort."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:119
|
|
msgid ""
|
|
"In some cases it's possible to automatically translate Python to C or x86 "
|
|
"assembly language, meaning that you don't have to modify your code to gain "
|
|
"increased speed."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:125
|
|
msgid ""
|
|
"`Pyrex <http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/>`_ can compile "
|
|
"a slightly modified version of Python code into a C extension, and can be "
|
|
"used on many different platforms."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:129
|
|
msgid ""
|
|
"`Psyco <http://psyco.sourceforge.net>`_ is a just-in-time compiler that "
|
|
"translates Python code into x86 assembly language. If you can use it, Psyco "
|
|
"can provide dramatic speedups for critical functions."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:133
|
|
msgid ""
|
|
"The rest of this answer will discuss various tricks for squeezing a bit more "
|
|
"speed out of Python code. *Never* apply any optimization tricks unless you "
|
|
"know you need them, after profiling has indicated that a particular function "
|
|
"is the heavily executed hot spot in the code. Optimizations almost always "
|
|
"make the code less clear, and you shouldn't pay the costs of reduced clarity "
|
|
"(increased development time, greater likelihood of bugs) unless the "
|
|
"resulting performance benefit is worth it."
|
|
msgstr ""
|
|
|
|
# 55812fb1974b4d35b3629077fdfbf6df
|
|
#: ../src/Doc/faq/programming.rst:141
|
|
msgid ""
|
|
"There is a page on the wiki devoted to `performance tips <https://wiki."
|
|
"python.org/moin/PythonSpeed/PerformanceTips>`_."
|
|
msgstr ""
|
|
|
|
# 13d2e0a3cc5b49d3afa3db3b84eeeece
|
|
#: ../src/Doc/faq/programming.rst:144
|
|
msgid ""
|
|
"Guido van Rossum has written up an anecdote related to optimization at "
|
|
"https://www.python.org/doc/essays/list2str."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:147
|
|
msgid ""
|
|
"One thing to notice is that function and (especially) method calls are "
|
|
"rather expensive; if you have designed a purely OO interface with lots of "
|
|
"tiny functions that don't do much more than get or set an instance variable "
|
|
"or call another method, you might consider using a more direct way such as "
|
|
"directly accessing instance variables. Also see the standard module :mod:"
|
|
"`profile` which makes it possible to find out where your program is spending "
|
|
"most of its time (if you have some patience -- the profiling itself can slow "
|
|
"your program down by an order of magnitude)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:156
|
|
msgid ""
|
|
"Remember that many standard optimization heuristics you may know from other "
|
|
"programming experience may well apply to Python. For example it may be "
|
|
"faster to send output to output devices using larger writes rather than "
|
|
"smaller ones in order to reduce the overhead of kernel system calls. Thus "
|
|
"CGI scripts that write all output in \"one shot\" may be faster than those "
|
|
"that write lots of small pieces of output."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:163
|
|
msgid ""
|
|
"Also, be sure to use Python's core features where appropriate. For example, "
|
|
"slicing allows programs to chop up lists and other sequence objects in a "
|
|
"single tick of the interpreter's mainloop using highly optimized C "
|
|
"implementations. Thus to get the same effect as::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:172
|
|
msgid "it is much shorter and far faster to use ::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:176
|
|
msgid ""
|
|
"Note that the functionally-oriented built-in functions such as :func:`map`, :"
|
|
"func:`zip`, and friends can be a convenient accelerator for loops that "
|
|
"perform a single task. For example to pair the elements of two lists "
|
|
"together::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:184
|
|
msgid "or to compute a number of sines::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:189
|
|
msgid "The operation completes very quickly in such cases."
|
|
msgstr ""
|
|
|
|
# 54d42c305aed46aea0e1dac5e7d0e9ec
|
|
#: ../src/Doc/faq/programming.rst:191
|
|
msgid ""
|
|
"Other examples include the ``join()`` and ``split()`` :ref:`methods of "
|
|
"string objects <string-methods>`. For example if s1..s7 are large (10K+) "
|
|
"strings then ``\"\".join([s1,s2,s3,s4,s5,s6,s7])`` may be far faster than "
|
|
"the more obvious ``s1+s2+s3+s4+s5+s6+s7``, since the \"summation\" will "
|
|
"compute many subexpressions, whereas ``join()`` does all the copying in one "
|
|
"pass. For manipulating strings, use the ``replace()`` and the ``format()`` :"
|
|
"ref:`methods on string objects <string-methods>`. Use regular expressions "
|
|
"only when you're not dealing with constant string patterns. You may still "
|
|
"use :ref:`the old % operations <string-formatting>` ``string % tuple`` and "
|
|
"``string % dictionary``."
|
|
msgstr ""
|
|
|
|
# d15916e437c84e658a3a86d114462937
|
|
#: ../src/Doc/faq/programming.rst:202
|
|
msgid ""
|
|
"Be sure to use the :meth:`list.sort` built-in method to do sorting, and see "
|
|
"the `sorting mini-HOWTO <https://wiki.python.org/moin/HowTo/Sorting>`_ for "
|
|
"examples of moderately advanced usage. :meth:`list.sort` beats other "
|
|
"techniques for sorting in all but the most extreme circumstances."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:207
|
|
msgid ""
|
|
"Another common trick is to \"push loops into functions or methods.\" For "
|
|
"example suppose you have a program that runs slowly and you use the profiler "
|
|
"to determine that a Python function ``ff()`` is being called lots of times. "
|
|
"If you notice that ``ff()``::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:216
|
|
msgid "tends to be called in loops like::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:220 ../src/Doc/faq/windows.rst:107
|
|
msgid "or::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:226
|
|
msgid ""
|
|
"then you can often eliminate function call overhead by rewriting ``ff()`` "
|
|
"to::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:235
|
|
msgid "and rewrite the two examples to ``list = ffseq(oldlist)`` and to::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:240
|
|
msgid ""
|
|
"Single calls to ``ff(x)`` translate to ``ffseq([x])[0]`` with little "
|
|
"penalty. Of course this technique is not always appropriate and there are "
|
|
"other variants which you can figure out."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:244
|
|
msgid ""
|
|
"You can gain some performance by explicitly storing the results of a "
|
|
"function or method lookup into a local variable. A loop like::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:250
|
|
msgid ""
|
|
"resolves ``dict.get`` every iteration. If the method isn't going to change, "
|
|
"a slightly faster implementation is::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:257
|
|
msgid ""
|
|
"Default arguments can be used to determine values once, at compile time "
|
|
"instead of at run time. This can only be done for functions or objects "
|
|
"which will not be changed during program execution, such as replacing ::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:264
|
|
msgid "with ::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:269
|
|
msgid ""
|
|
"Because this trick uses default arguments for terms which should not be "
|
|
"changed, it should only be used when you are not concerned with presenting a "
|
|
"possibly confusing API to your users."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:275
|
|
msgid "Core Language"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:278
|
|
msgid "Why am I getting an UnboundLocalError when the variable has a value?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:280
|
|
msgid ""
|
|
"It can be a surprise to get the UnboundLocalError in previously working code "
|
|
"when it is modified by adding an assignment statement somewhere in the body "
|
|
"of a function."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:284
|
|
msgid "This code:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:292
|
|
msgid "works, but this code:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:299
|
|
msgid "results in an UnboundLocalError:"
|
|
msgstr ""
|
|
|
|
# 7d745afdbd874d62b29bbedfc0099907
|
|
#: ../src/Doc/faq/programming.rst:306
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:313
|
|
msgid ""
|
|
"In the example above you can access the outer scope variable by declaring it "
|
|
"global:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:324
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:333
|
|
msgid "What are the rules for local and global variables in Python?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:335
|
|
msgid ""
|
|
"In Python, variables that are only referenced inside a function are "
|
|
"implicitly global. If a variable is assigned a new value anywhere within "
|
|
"the function's body, it's assumed to be a local. If a variable is ever "
|
|
"assigned a new value inside the function, the variable is implicitly local, "
|
|
"and you need to explicitly declare it as 'global'."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:341
|
|
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 ""
|
|
|
|
# 924a0fb4c52d4d508ae61ede7c3f8fdf
|
|
#: ../src/Doc/faq/programming.rst:351
|
|
msgid ""
|
|
"Why do lambdas defined in a loop with different values all return the same "
|
|
"result?"
|
|
msgstr ""
|
|
|
|
# 6e3ea9d4df2642eb9d3e92eaa6a9968c
|
|
#: ../src/Doc/faq/programming.rst:353
|
|
msgid ""
|
|
"Assume you use a for loop to define a few different lambdas (or even plain "
|
|
"functions), e.g.::"
|
|
msgstr ""
|
|
|
|
# 13aa3d4bd1ba489385475d37babef0c0
|
|
#: ../src/Doc/faq/programming.rst:360
|
|
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 ""
|
|
|
|
# 05dae30e0a144c0297629c1951263f65
|
|
#: ../src/Doc/faq/programming.rst:370
|
|
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 ""
|
|
|
|
# bdbfb8d8dc1247e98b41e0aff5680c34
|
|
#: ../src/Doc/faq/programming.rst:380
|
|
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 ""
|
|
|
|
# 0d3f70faade14c55b8ed25080bd41a4e
|
|
#: ../src/Doc/faq/programming.rst:387
|
|
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 ""
|
|
|
|
# b620a634f93a46fca3caa69d6a8410d2
|
|
#: ../src/Doc/faq/programming.rst:398
|
|
msgid ""
|
|
"Note that this behaviour is not peculiar to lambdas, but applies to regular "
|
|
"functions too."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:403
|
|
msgid "How do I share global variables across modules?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:405
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:411
|
|
msgid "config.py::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:415
|
|
msgid "mod.py::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:420
|
|
msgid "main.py::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:426
|
|
msgid ""
|
|
"Note that using a module is also the basis for implementing the Singleton "
|
|
"design pattern, for the same reason."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:431
|
|
msgid "What are the \"best practices\" for using import in a module?"
|
|
msgstr ""
|
|
|
|
# fe8501e866514060acb58f1c1a7bbd23
|
|
#: ../src/Doc/faq/programming.rst:433
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:437
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:442
|
|
msgid "It's good practice if you import modules in the following order:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:444
|
|
msgid "standard library modules -- e.g. ``sys``, ``os``, ``getopt``, ``re``"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:445
|
|
msgid ""
|
|
"third-party library modules (anything installed in Python's site-packages "
|
|
"directory) -- e.g. mx.DateTime, ZODB, PIL.Image, etc."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:447
|
|
msgid "locally-developed modules"
|
|
msgstr ""
|
|
|
|
# 9f4cb04c4862498b986f121672a5251b
|
|
#: ../src/Doc/faq/programming.rst:449
|
|
msgid ""
|
|
"Only use explicit relative package imports. If you're writing code that's "
|
|
"in the ``package.sub.m1`` module and want to import ``package.sub.m2``, do "
|
|
"not just write ``import m2``, even though it's legal. Write ``from package."
|
|
"sub import m2`` or ``from . import m2`` instead."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:454
|
|
msgid ""
|
|
"It is sometimes necessary to move imports to a function or class to avoid "
|
|
"problems with circular imports. Gordon McMillan says:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:457
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:463
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:468
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:473
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:486
|
|
msgid "Why are default values shared between objects?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:488
|
|
msgid ""
|
|
"This type of bug commonly bites neophyte programmers. Consider this "
|
|
"function::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:495
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:499
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:504
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:508
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:516
|
|
msgid "but::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:522
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:537
|
|
msgid ""
|
|
"You could use a global variable containing a dictionary instead of the "
|
|
"default value; it's a matter of taste."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:542
|
|
msgid ""
|
|
"How can I pass optional or keyword parameters from one function to another?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:544
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:555
|
|
msgid ""
|
|
"In the unlikely case that you care about Python versions older than 2.0, "
|
|
"use :func:`apply`::"
|
|
msgstr ""
|
|
|
|
# 96b5be5f561c4e388030863e5bbacca1
|
|
#: ../src/Doc/faq/programming.rst:572
|
|
msgid "What is the difference between arguments and parameters?"
|
|
msgstr ""
|
|
|
|
# a4cafc0bd37a4682bb11a96bcc193305
|
|
#: ../src/Doc/faq/programming.rst:574
|
|
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 types "
|
|
"of arguments a function can accept. For example, given the function "
|
|
"definition::"
|
|
msgstr ""
|
|
|
|
# aebb59148b8f4b369dcddd620bda8acc
|
|
#: ../src/Doc/faq/programming.rst:582
|
|
msgid ""
|
|
"*foo*, *bar* and *kwargs* are parameters of ``func``. However, when calling "
|
|
"``func``, for example::"
|
|
msgstr ""
|
|
|
|
# 786ad2fc6ac74da49f7655b754d46766
|
|
#: ../src/Doc/faq/programming.rst:587
|
|
msgid "the values ``42``, ``314``, and ``somevar`` are arguments."
|
|
msgstr ""
|
|
|
|
# 0bd1025c430c46fca744f1ab71d0c6f9
|
|
#: ../src/Doc/faq/programming.rst:591
|
|
msgid "Why did changing list 'y' also change list 'x'?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:593
|
|
#, fuzzy
|
|
msgid "If you wrote code like::"
|
|
msgstr "In C++ you'd write"
|
|
|
|
# dcf823fe26834b4298e3ab0729b2fa4c
|
|
#: ../src/Doc/faq/programming.rst:603
|
|
msgid ""
|
|
"you might be wondering why appending an element to ``y`` changed ``x`` too."
|
|
msgstr ""
|
|
|
|
# 49fc350d28fb420ca92faac571737b2d
|
|
#: ../src/Doc/faq/programming.rst:605
|
|
msgid "There are two factors that produce this result:"
|
|
msgstr ""
|
|
|
|
# 413d98a41e7b4e67aed138c28d7ba12f
|
|
#: ../src/Doc/faq/programming.rst:607
|
|
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 ""
|
|
|
|
# e44847fa07dd4dc4af11a625d09fda63
|
|
#: ../src/Doc/faq/programming.rst:611
|
|
msgid ""
|
|
"Lists are :term:`mutable`, which means that you can change their content."
|
|
msgstr ""
|
|
|
|
# a8ee185e5f0240fd850b3c16b68088da
|
|
#: ../src/Doc/faq/programming.rst:613
|
|
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 ""
|
|
|
|
# 9f8319228d964bfda3bab873ba568653
|
|
#: ../src/Doc/faq/programming.rst:617
|
|
msgid "If we instead assign an immutable object to ``x``::"
|
|
msgstr ""
|
|
|
|
# 2a525148729d47d8b88281de2d3d4f0c
|
|
#: ../src/Doc/faq/programming.rst:627
|
|
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 ""
|
|
|
|
# 46a5fa2e975f4e98b02b22431e76776e
|
|
#: ../src/Doc/faq/programming.rst:635
|
|
msgid ""
|
|
"Some operations (for example ``y.append(10)`` and ``y.sort()``) mutate the "
|
|
"object, whereas superficially similar operations (for example ``y = y + "
|
|
"[10]`` and ``sorted(y)``) 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."
|
|
msgstr ""
|
|
|
|
# b71ccf689a1e48a7ae3dc9f6cd9a3322
|
|
#: ../src/Doc/faq/programming.rst:644
|
|
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 ""
|
|
|
|
# 2a5ffb67bd9448e8ade209869f3c7f75
|
|
#: ../src/Doc/faq/programming.rst:651
|
|
msgid "In other words:"
|
|
msgstr ""
|
|
|
|
# dc6bcce15dcf4b898d9e766c2b41e03e
|
|
#: ../src/Doc/faq/programming.rst:653
|
|
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 ""
|
|
|
|
# 4d5f00e6b8d34e29bf200694d85fd9e4
|
|
#: ../src/Doc/faq/programming.rst:656
|
|
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 ""
|
|
|
|
# ac62a0f8bdb148b28efffd5e47189104
|
|
#: ../src/Doc/faq/programming.rst:661
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:666
|
|
msgid "How do I write a function with output parameters (call by reference)?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:668
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:673
|
|
msgid "By returning a tuple of the results::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:684
|
|
msgid "This is almost always the clearest solution."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:686
|
|
msgid ""
|
|
"By using global variables. This isn't thread-safe, and is not recommended."
|
|
msgstr ""
|
|
"En utilisant des variables globales. Ce qui n'est pas thread-safe, et n'est "
|
|
"donc pas recommandé."
|
|
|
|
#: ../src/Doc/faq/programming.rst:688
|
|
msgid "By passing a mutable (changeable in-place) object::"
|
|
msgstr "En passant un objet mutable (modifiable par remplacement)::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:698
|
|
msgid "By passing in a dictionary that gets mutated::"
|
|
msgstr "En utilisant un dictionnaire, qui est modifié (en place)."
|
|
|
|
#: ../src/Doc/faq/programming.rst:708
|
|
#, fuzzy
|
|
msgid "Or bundle up values in a class instance::"
|
|
msgstr "Ou regrouper les valeurs dans une instance de classe::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:724
|
|
msgid "There's almost never a good reason to get this complicated."
|
|
msgstr ""
|
|
"Il n'y a pratiquement jamais de bonne raison de faire quelque chose d'aussi "
|
|
"compliqué."
|
|
|
|
#: ../src/Doc/faq/programming.rst:726
|
|
msgid "Your best choice is to return a tuple containing the multiple results."
|
|
msgstr ""
|
|
"Votre meilleure option est de renvoyer un tuple contenant les résultats "
|
|
"multiples."
|
|
|
|
#: ../src/Doc/faq/programming.rst:730
|
|
msgid "How do you make a higher order function in Python?"
|
|
msgstr "Comment construire une fonction de grand ordre en Python?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:732
|
|
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 ""
|
|
"Vous avez deux choix: vous pouvez utiliser les portées imbriquées ou vous "
|
|
"pouvez utiliser des objets appelable. Par exemple, supposons que vous "
|
|
"vouliez définir ``lineare (a, b)`` qui retourne une fonction ``f (x)`` qui "
|
|
"calcule la valeur ``a * x + b``. En utilisant les portées imbriquées::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:741
|
|
msgid "Or using a callable object::"
|
|
msgstr "Ou en utilisant un objet appelable."
|
|
|
|
#: ../src/Doc/faq/programming.rst:751
|
|
msgid "In both cases, ::"
|
|
msgstr "dans les deux cas, ::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:755
|
|
msgid "gives a callable object where ``taxes(10e6) == 0.3 * 10e6 + 2``."
|
|
msgstr "retourne un objet appelable tel que ``taxes(10e6) == 0.3 * 10e6 + 2``."
|
|
|
|
#: ../src/Doc/faq/programming.rst:757
|
|
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 appelables 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 collection d'objet appelables peuvent partager leur signatures par "
|
|
"héritage::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:766
|
|
#, fuzzy
|
|
msgid "Object can encapsulate state for several methods::"
|
|
msgstr "Les objets peuvent encapsuler un état pour plusieurs méthodes::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:784
|
|
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."
|
|
|
|
#: ../src/Doc/faq/programming.rst:789
|
|
msgid "How do I copy an object in Python?"
|
|
msgstr "Comment copier un objet en Python?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:791
|
|
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 ""
|
|
"En général, essayez :funct:`copy.copy` ou :func:`copy.deepcopy` pour le cas "
|
|
"général. Tout les objets ne peuvent pas être copiés, mais la plupart peuvent."
|
|
|
|
#: ../src/Doc/faq/programming.rst:794
|
|
msgid ""
|
|
"Some objects can be copied more easily. Dictionaries have a :meth:`~dict."
|
|
"copy` method::"
|
|
msgstr ""
|
|
"Certains objects peuvent être copiés plus facilement. Les Dictionnaires ont "
|
|
"une méthode :meth:`~dict.copy` ::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:799
|
|
msgid "Sequences can be copied by slicing::"
|
|
msgstr "Les séquences peuvent être copiées par tranches::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:805
|
|
msgid "How can I find the methods or attributes of an object?"
|
|
msgstr "Comment puis-je trouver les méthodes ou les attribues d'un objet?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:807
|
|
msgid ""
|
|
"For an instance x of a user-defined class, ``dir(x)`` returns an "
|
|
"alphabetized list of the names containing the instance attributes and "
|
|
"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."
|
|
|
|
#: ../src/Doc/faq/programming.rst:813
|
|
msgid "How can my code discover the name of an object?"
|
|
msgstr "Comment mon code peut il découvrir le nom d'un objet?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:815
|
|
msgid ""
|
|
"Generally speaking, it can't, because objects don't really have names. "
|
|
"Essentially, assignment always binds a name to a value; The same is true of "
|
|
"``def`` and ``class`` statements, but in that case the value is a callable. "
|
|
"Consider the following code::"
|
|
msgstr ""
|
|
"De façon générale, il ne peut pas, par ce que les objets n'ont pas "
|
|
"réellement de noms. Essentiellement, l'assignation attache un nom à une "
|
|
"valeur; C'est vrai aussi pour les mots clés ``def`` et ``class``, à la "
|
|
"différence que la valeur est un objet appelable."
|
|
|
|
#: ../src/Doc/faq/programming.rst:832
|
|
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."
|
|
msgstr ""
|
|
"Le fait que la classe ait un nom est discutable, même si elle a deux noms et "
|
|
"qu'elle est appelé 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 sont attachés à la même valeur."
|
|
|
|
#: ../src/Doc/faq/programming.rst:837
|
|
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éral, il ne devrait pas être nécessaire pour votre application "
|
|
"de \"connaitre le nom\" d'une valeur particulière. À moins que vous soyez "
|
|
"délibérément en train d'écrire un programme introspectif, c'est souvent une "
|
|
"indication qu'un changement d'approche pourrait être bénéfique."
|
|
|
|
#: ../src/Doc/faq/programming.rst:842
|
|
msgid ""
|
|
"In comp.lang.python, Fredrik Lundh once gave an excellent analogy in answer "
|
|
"to this question:"
|
|
msgstr ""
|
|
"Sur comp.lang.python, Fredrik Lundh a donné un jour une excellente analogie "
|
|
"pour répondre à cette question:"
|
|
|
|
#: ../src/Doc/faq/programming.rst:845
|
|
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 ""
|
|
"De la même manière que vous trouvez le nom du chat que vous avez trouvé dans "
|
|
"votre coure: le chat ne peux pas vous dire lui même son nom, et il s'en "
|
|
"moque un peu -- alors le meilleur moyen de savoir comment il est appelé est "
|
|
"de demander à tous vos voisins (namespaces) si c'est leur chat (object)…"
|
|
|
|
#: ../src/Doc/faq/programming.rst:850
|
|
msgid ""
|
|
"....and don't be surprised if you'll find that it's known by many names, or "
|
|
"no name at all!"
|
|
msgstr ""
|
|
"…et ne soyez pas surpris si vous découvrez qu'il est connus sous plusieurs "
|
|
"noms différents, ou pas de nom du tout!"
|
|
|
|
#: ../src/Doc/faq/programming.rst:855
|
|
msgid "What's up with the comma operator's precedence?"
|
|
msgstr "Quel est le souci avec la précédente de l'opérateur virgule?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:857
|
|
msgid "Comma is not an operator in Python. Consider this session::"
|
|
msgstr ""
|
|
"Virgule n'est pas un opérateur en Python. Observez la session suivante::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:862
|
|
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 "
|
|
"expression, l'expression ci dessus, est évaluée de la même façon que si vous "
|
|
"aviez écrit::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:867
|
|
msgid "not::"
|
|
msgstr "et non::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:871
|
|
msgid ""
|
|
"The same is true of the various assignment operators (``=``, ``+=`` etc). "
|
|
"They are not truly operators but syntactic delimiters in assignment "
|
|
"statements."
|
|
msgstr ""
|
|
"Ceci est vrai de tous les opérateurs d'assignations (``=``, ``+=`` etc). Ce "
|
|
"ne sont pas vraiment des opérateurs mais des délimiteurs syntaxiques dans "
|
|
"les instructions d'assignation."
|
|
|
|
#: ../src/Doc/faq/programming.rst:876
|
|
msgid "Is there an equivalent of C's \"?:\" ternary operator?"
|
|
msgstr "Existe-t'il un équivalent à l'opérateur \"?:\" ternaire du C?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:878
|
|
msgid ""
|
|
"Yes, this feature was added in Python 2.5. The syntax would be as follows::"
|
|
msgstr ""
|
|
"Oui, cette fonctionnalité à été ajouté à partir de Python 2.5. La syntaxe "
|
|
"est la suivante::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:886
|
|
msgid "For versions previous to 2.5 the answer would be 'No'."
|
|
msgstr "Pour les versions précédentes de python la réponse serait \"Non\"."
|
|
|
|
#: ../src/Doc/faq/programming.rst:890
|
|
msgid "Is it possible to write obfuscated one-liners in Python?"
|
|
msgstr ""
|
|
"Est-il possible d'écrire des programmes volontairement difficile à "
|
|
"comprendre sur une seule ligne en Python?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:892
|
|
msgid ""
|
|
"Yes. Usually this is done by nesting :keyword:`lambda` within :keyword:"
|
|
"`lambda`. See the following three examples, due to Ulf Bartelt::"
|
|
msgstr ""
|
|
"Oui. Cela est généralement réalisé en imbriquant les :keyword:`lambda` les "
|
|
"uns dans les autres. Observez les trois exemples suivants, contribués par "
|
|
"Ulf Bartelt::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:917
|
|
msgid "Don't try this at home, kids!"
|
|
msgstr "Les enfants, ne faîtes pas ça chez vous!"
|
|
|
|
#: ../src/Doc/faq/programming.rst:921
|
|
msgid "Numbers and strings"
|
|
msgstr "Nombres et chaines de caractères"
|
|
|
|
#: ../src/Doc/faq/programming.rst:924
|
|
msgid "How do I specify hexadecimal and octal integers?"
|
|
msgstr "Comment puis-je spécifier des entiers hexadécimaux ou octaux?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:926
|
|
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 spécifier un entier octal, faites précéder la valeur octale par un "
|
|
"zéro, puis un \"o\" majuscule ou minuscule. Par exemple assigner la valeur "
|
|
"octale \"10\" (8 en décimal) à \"a\", tapez::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:934
|
|
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 ""
|
|
"L'hexadécimal est tout aussi simple, faîtes précéder le nombre hexadécimal "
|
|
"par un zéro, puis un \"x\" majuscule ou minuscule. Les nombres hexadécimaux "
|
|
"peuvent être écrit en majuscules ou en minuscules. Par exemple, dans "
|
|
"l'interpréteur Python::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:947
|
|
msgid "Why does -22 // 10 return -3?"
|
|
msgstr "Pourquoi -22//10 retourne-t'il -3?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:949
|
|
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 ""
|
|
"Cela est principalement due à la volonté que ``i % j`` ait le même signe que "
|
|
"j. Si vous voulez cela, vous voulez aussi::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:954
|
|
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 ""
|
|
"Alors la division entière doit retourner l'entier inférieur. Le C demande "
|
|
"aussi à ce que cette égalité soit vérifiée, et donc les compilateur qui "
|
|
"tronquent ``i//j`` ont besoin que ``i % j`` ait le même signe que ``i``."
|
|
|
|
#: ../src/Doc/faq/programming.rst:958
|
|
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 ""
|
|
"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 dit 10h maintenant, "
|
|
"que disait-elle il y a 200 heures? ``-190%12 == 2`` est utile; ``-192 % 12 "
|
|
"== -10`` est un bug qui attends pour mordre."
|
|
|
|
# 947cdc04b21e4a4b946644f003e25388
|
|
#: ../src/Doc/faq/programming.rst:966
|
|
msgid ""
|
|
"On Python 2, ``a / b`` returns the same as ``a // b`` if ``__future__."
|
|
"division`` is not in effect. This is also known as \"classic\" division."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:972
|
|
msgid "How do I convert a string to a number?"
|
|
msgstr "Comment puis-je convertir une chaine de caractère en nombre?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:974
|
|
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 ""
|
|
"Pour les entiers, utilisez la fonction built-in :func: `int` de type "
|
|
"constructeur, par exemple ``int('144') == 144``. De façon similaire, :func:"
|
|
"`float` convertit en valeur flottante, par exemple ``float('144')`` == "
|
|
"144.0``."
|
|
|
|
#: ../src/Doc/faq/programming.rst:978
|
|
msgid ""
|
|
"By default, these interpret the number as decimal, so that ``int('0144') == "
|
|
"144`` 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 '0' indicates octal, and '0x' "
|
|
"indicates a hex number."
|
|
msgstr ""
|
|
"Par défaut, ces fonctions interprètent les nombre en tant que décimaux, de "
|
|
"telles façons que ``int('0144')==144`` et ``int('0x144')`` remontent :exc:"
|
|
"`ValueError`. ``int(string, base)`` prends la base depuis laquelle il faut "
|
|
"convertir dans le second argument, optionnel, donc ``int('0x144', 16) == "
|
|
"324``. Si la base donnée est 0, le nombre est interprété selon les règles "
|
|
"Python: un '0' en tête indique octal, et '0x' indique un hexadécimal."
|
|
|
|
#: ../src/Doc/faq/programming.rst:984
|
|
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 ""
|
|
"N'utilisez pas la fonction built-in :func:`eval` si tout ce que vous avez "
|
|
"besoin est de convertir des chaines en nombres. :func:`eval` sera "
|
|
"significativement plus lent et implique des risque de sécurité: quelqu'un "
|
|
"pourrait vous envoyez une expression Python pouvant avoir des effets de bord "
|
|
"indésirables. Par exemple, quelqu'un pourrait passer ``__import__('os')."
|
|
"system(\"rm -rf $HOME\")`` ce qui aurait pour effet d'effacer votre "
|
|
"répertoire personnel."
|
|
|
|
#: ../src/Doc/faq/programming.rst:991
|
|
#, fuzzy
|
|
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 "
|
|
"regards numbers starting with '0' as octal (base 8)."
|
|
msgstr ""
|
|
":func:`eval` a aussi pour effet d'interpréter les nombres comme comme des "
|
|
"expression python, ainsi ``eval('09')`` produit une erreur de syntaxe par ce "
|
|
"que Python ne permet pas les '0' en tête d'un nombre décimal (à l'exception "
|
|
"du nombre '0')."
|
|
|
|
#: ../src/Doc/faq/programming.rst:997
|
|
msgid "How do I convert a number to a string?"
|
|
msgstr "Comment convertir un nombre en chaine de caractère?"
|
|
|
|
# faut il traduire la référence?
|
|
#: ../src/Doc/faq/programming.rst:999
|
|
#, fuzzy
|
|
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:`formatstrings` section, e.g. ``\"{:04d}\"."
|
|
"format(144)`` yields ``'0144'`` and ``\"{:.3f}\".format(1/3)`` yields "
|
|
"``'0.333'``. You may also use :ref:`the % operator <string-formatting>` on "
|
|
"strings. See the library reference manual for details."
|
|
msgstr ""
|
|
"Pour convertir, par exemple, le nombre 144 en la chaîne '144 ', utilisez la "
|
|
"fonction intégrée: func: «str». Si vous voulez une représentation "
|
|
"hexadécimale ou octale, utilisez les fonctions intégrées :func:``hex`` ou: "
|
|
"func:``oct``. Pour une meilleure la mise en forme, voir la section :ref:"
|
|
"`string-formatting`, par exemple, ``\"{:04d) \".format (144)`` renvoit "
|
|
"``'0144'`` et ``\"{:.3f)\".format (1 / 3) donne ``'0,333' ``."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1009
|
|
msgid "How do I modify a string in place?"
|
|
msgstr "Comment modifier une chaine de caractère \"en place\"?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1011
|
|
msgid ""
|
|
"You can't, because strings are immutable. If you need an object with this "
|
|
"ability, try converting the string to a list or use the array module::"
|
|
msgstr ""
|
|
"Vous ne pouvez pas, par ce que les chaines de caractères sont immuables, Si "
|
|
"vous avez besoin d'un objet ayant une telle capacité, essayez de convertir "
|
|
"la chaine en liste, ou utilisez le module array::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1034
|
|
msgid "How do I use strings to call functions/methods?"
|
|
msgstr ""
|
|
"Comment utiliser des chaines de caractères pour appeler des fonctions/"
|
|
"méthodes?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1036
|
|
msgid "There are various techniques."
|
|
msgstr "Il y a différentes techniques."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1038
|
|
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 "
|
|
"chaines de caractères à des fonctions. Le principal avantage de cette "
|
|
"technique est que les chaines n'ont pas besoin d'être égales aux noms de "
|
|
"fonctions. C'est aussi la principale façon d'imiter la construction \"case"
|
|
"\"::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1053
|
|
msgid "Use the built-in function :func:`getattr`::"
|
|
msgstr "Utiliser la fonction :func:`getattr`::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1058
|
|
msgid ""
|
|
"Note that :func:`getattr` works on any object, including classes, class "
|
|
"instances, modules, and so on."
|
|
msgstr ""
|
|
"Notez que :func:`getattr` marche sur n'importe quel objet, ceci inclue les "
|
|
"classes, les instances de classes, les modules et ainsi de suite."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1061
|
|
msgid "This is used in several places in the standard library, like this::"
|
|
msgstr ""
|
|
"Ceci est utilisé dans plusieurs endroit de la bibliothèque standard, de "
|
|
"cette façon::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1074
|
|
msgid "Use :func:`locals` or :func:`eval` to resolve the function name::"
|
|
msgstr ""
|
|
"Utilisez :func:`locals` ou :func:`eval` pour résoudre le nom de fonction::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1087
|
|
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: En utilisant :func:`eval` est lent est dangereux. Si vous n'avez pas "
|
|
"un contrôle absolu sur le contenu de la chaine de caractère, quelqu'un peut "
|
|
"passer une chaine de caractère pouvant résulter en l'exécution de code "
|
|
"arbitraire."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1092
|
|
msgid ""
|
|
"Is there an equivalent to Perl's chomp() for removing trailing newlines from "
|
|
"strings?"
|
|
msgstr ""
|
|
"Existe-t'il un équivalent à la fonction chomp() de Perl, pour retirer les "
|
|
"caractères de fin de ligne d'une chaine de caractère?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1094
|
|
#, fuzzy
|
|
msgid ""
|
|
"Starting with Python 2.2, 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 ""
|
|
"À partir de Python 2.2 vous pouvez utiliser ``S.rstrip(\"\r\n"
|
|
"\")`` pour retirer toute occurrence de n'importe quel terminateur de ligne à "
|
|
"la fin d'une chaine de caractère ``S``, sans retirer aucun espace de fin de "
|
|
"ligne. Si la chaine ``S`` représente plus d'une ligne, avec plusieurs lignes "
|
|
"vides, les terminateurs de lignes de toutes les lignes vides seront retirés::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1106
|
|
msgid ""
|
|
"Since this is typically only desired when reading text one line at a time, "
|
|
"using ``S.rstrip()`` this way works well."
|
|
msgstr ""
|
|
"Du fait que ce soit principalement utile en lisant un texte ligne à ligne, "
|
|
"utiliser ``S.rstrip()`` devrait marcher correctement."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1109
|
|
msgid "For older versions of Python, there are two partial substitutes:"
|
|
msgstr ""
|
|
"Pour les versions plus anciennes de python, il y a deux substituts partiels "
|
|
"disponibles."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1111
|
|
msgid ""
|
|
"If you want to remove all trailing whitespace, use the ``rstrip()`` method "
|
|
"of string objects. This removes all trailing whitespace, not just a single "
|
|
"newline."
|
|
msgstr ""
|
|
"Si vous voulez retirer tous les espaces de fin de ligne, utilisez la méthode "
|
|
"``rstrip()`` des chaines de caractères. Cela retire tous les espaces de fin "
|
|
"de ligne, pas seulement le caractère de fin de ligne."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1115
|
|
msgid ""
|
|
"Otherwise, if there is only one line in the string ``S``, use ``S."
|
|
"splitlines()[0]``."
|
|
msgstr ""
|
|
"Sinon, s'il y a seulement une ligne dans la chaine ``S``, utilisez ``S."
|
|
"splitlines()``[0]."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1120
|
|
msgid "Is there a scanf() or sscanf() equivalent?"
|
|
msgstr "Existe-t'il un équivalent à scanf() ou sscanf()?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1122
|
|
msgid "Not as such."
|
|
msgstr "Pas exactement."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1124
|
|
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`. ``split()`` supports an optional \"sep\" "
|
|
"parameter which is useful if the line uses something other than whitespace "
|
|
"as a separator."
|
|
msgstr ""
|
|
"Pour une simple analyse de chaine, l'approche la plus simple est "
|
|
"généralement de découper la ligne en mots délimités par des espaces, en "
|
|
"utilisant la méthode :meth:`~str.split` des objets chaine de caractères, et "
|
|
"ensuite de convertir les chaines de décimales en valeurs numériques en "
|
|
"utilisant la fonction :func:`int` ou :func:`float`, ``split()`` supporte un "
|
|
"paramètre optionnel \"sep\" qui est utile si la ligne utilise autre chose "
|
|
"que des espaces comme séparateur."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1130
|
|
#, fuzzy
|
|
msgid ""
|
|
"For more complicated input parsing, regular expressions are more powerful "
|
|
"than C's :c:func:`sscanf` and better suited for the task."
|
|
msgstr ""
|
|
"Pour les analyses plus compliquées, les expressions rationnelles sont plus "
|
|
"puissantes que la fonction `sscanf` de C et mieux adaptées à la tâche."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1135
|
|
#, fuzzy
|
|
msgid ""
|
|
"What does 'UnicodeError: ASCII [decoding,encoding] error: ordinal not in "
|
|
"range(128)' mean?"
|
|
msgstr ""
|
|
"Que signifient les erreurs 'UnicodeDecodeError' ou 'UnicodeEncodeError'?"
|
|
|
|
# d32100f5f3e241519f579f93e95f5a43
|
|
#: ../src/Doc/faq/programming.rst:1137
|
|
msgid ""
|
|
"This error indicates that your Python installation can handle only 7-bit "
|
|
"ASCII strings. There are a couple ways to fix or work around the problem."
|
|
msgstr ""
|
|
|
|
# 1c12ed114b5d49e19257a764fd59e9ef
|
|
#: ../src/Doc/faq/programming.rst:1140
|
|
msgid ""
|
|
"If your programs must handle data in arbitrary character set encodings, the "
|
|
"environment the application runs in will generally identify the encoding of "
|
|
"the data it is handing you. You need to convert the input to Unicode data "
|
|
"using that encoding. For example, a program that handles email or web input "
|
|
"will typically find character set encoding information in Content-Type "
|
|
"headers. This can then be used to properly convert input data to Unicode. "
|
|
"Assuming the string referred to by ``value`` is encoded as UTF-8::"
|
|
msgstr ""
|
|
|
|
# 0a0a8bd0d96c44e98289983f8156d4cc
|
|
#: ../src/Doc/faq/programming.rst:1150
|
|
msgid ""
|
|
"will return a Unicode object. If the data is not correctly encoded as "
|
|
"UTF-8, the above call will raise a :exc:`UnicodeError` exception."
|
|
msgstr ""
|
|
|
|
# c23fedd940ec4113a5408e1bd9df81a8
|
|
#: ../src/Doc/faq/programming.rst:1153
|
|
msgid ""
|
|
"If you only want strings converted to Unicode which have non-ASCII data, you "
|
|
"can try converting them first assuming an ASCII encoding, and then generate "
|
|
"Unicode objects if that fails::"
|
|
msgstr ""
|
|
|
|
# 44c53b389d894ef996a351e4c5469ce3
|
|
#: ../src/Doc/faq/programming.rst:1165
|
|
msgid ""
|
|
"It's possible to set a default encoding in a file called ``sitecustomize."
|
|
"py`` that's part of the Python library. However, this isn't recommended "
|
|
"because changing the Python-wide default encoding may cause third-party "
|
|
"extension modules to fail."
|
|
msgstr ""
|
|
|
|
# b60213029b4c4e27a28d9f82396f65dc
|
|
#: ../src/Doc/faq/programming.rst:1170
|
|
msgid ""
|
|
"Note that on Windows, there is an encoding known as \"mbcs\", which uses an "
|
|
"encoding specific to your current locale. In many cases, and particularly "
|
|
"when working with COM, this may be an appropriate default encoding to use."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1176
|
|
msgid "Sequences (Tuples/Lists)"
|
|
msgstr "Sequences (Tuples/Lists)"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1179
|
|
msgid "How do I convert between tuples and lists?"
|
|
msgstr "Comment convertir les listes en tuples et inversement?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1181
|
|
msgid ""
|
|
"The type constructor ``tuple(seq)`` converts any sequence (actually, any "
|
|
"iterable) into a tuple with the same items in the same order."
|
|
msgstr ""
|
|
"Le constructeur de type ``tuple(seq)`` convertit toute séquence (en fait "
|
|
"tout itérable) en un tuple avec les mêmes éléments dans le même ordre…"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1184
|
|
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 ""
|
|
"Par exemple ``tuple([1, 2, 3])`` renvoi ``(1, 2, 3)`` et ``tuple('abc')`` "
|
|
"renvoi ``('a', 'b', 'c')``. Si l'argument est un tuple, cela ne crèe pas une "
|
|
"copie, mais renvoi le même objet, ce qui en fait un fonction économique à "
|
|
"appeler quand vous ne savez pas si votre objet est déjà un tulpe."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1189
|
|
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))`` retourne ``[1,2,3]`` et ``list('abc')`` retourne "
|
|
"``['a','b','c']``. Si l'argument est une liste, il retourne une copie, de la "
|
|
"même façon que ``seq[:]``."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1196
|
|
msgid "What's a negative index?"
|
|
msgstr "Qu'est-ce qu'un indexe négatif?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1198
|
|
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 ""
|
|
"Les séquences Python sont indexées avec des nombres positifs aussi bien que "
|
|
"négatifs. Pour les nombres positifs, 0 est le premier index, 1 est le "
|
|
"second, et ainsi de suite. Pour les indexes négatifs, -1 est le dernier "
|
|
"index, -2 est le pénultième (avant dernier), et ainsi de suite. On peut "
|
|
"aussi dire que ``seq[-n]`` est équivalent à ``seq[len(seq)-n]``."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1203
|
|
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 ""
|
|
"Utiliser des indexes négatifs peut être très pratique. Par exemple "
|
|
"``S[:-1]`` indique la chaine entière a l'exception du dernier caractère, ce "
|
|
"qui est pratique pour retirer un caractère de fin de ligne en fin d'une "
|
|
"chaine."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1209
|
|
msgid "How do I iterate over a sequence in reverse order?"
|
|
msgstr "Comment itérer à rebours sur une séquence?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1211
|
|
msgid ""
|
|
"Use the :func:`reversed` built-in function, which is new in Python 2.4::"
|
|
msgstr ""
|
|
"Utilisez la fonction embarquée :func:`reversed`, qui est apparue en Python "
|
|
"2.4::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1216
|
|
msgid ""
|
|
"This won't touch your original sequence, but build a new copy with reversed "
|
|
"order to iterate over."
|
|
msgstr ""
|
|
"Cela ne modifiera pas votre séquence initiale, mais construira à la place "
|
|
"une copie en ordre inverse pour itérer dessus."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1219
|
|
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::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1226
|
|
msgid "How do you remove duplicates from a list?"
|
|
msgstr "Comment retirer les doublons d'une liste?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1228
|
|
msgid "See the Python Cookbook for a long discussion of many ways to do this:"
|
|
msgstr ""
|
|
"Lisez le Python Cookbook pour trouver une longue discussion sur les "
|
|
"nombreuses façons de faire cela:"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1230
|
|
#, fuzzy
|
|
msgid "http://code.activestate.com/recipes/52560/"
|
|
msgstr "http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1232
|
|
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 ""
|
|
"Si changer l'ordre de la liste ne vous dérange pas, commencez par trier "
|
|
"celle ci, puis parcourez la d'un bout à l'autre, en supprimant les doublons "
|
|
"trouvés en chemin::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1244
|
|
msgid ""
|
|
"If all elements of the list may be used as dictionary keys (i.e. they are "
|
|
"all hashable) this is often faster ::"
|
|
msgstr ""
|
|
"Si tous les éléments de la liste peuvent être utilisés comme des clés de "
|
|
"dictionnaire (cad, elles sont toutes hashables) ceci est souvent plus "
|
|
"rapide::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1252
|
|
msgid "In Python 2.5 and later, the following is possible instead::"
|
|
msgstr "En Python 2.5 et suivant, la forme suivante est possible à la place::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1256
|
|
msgid ""
|
|
"This converts the list into a set, thereby removing duplicates, and then "
|
|
"back into a list."
|
|
msgstr ""
|
|
"Ceci convertis la liste en un ensemble, ce qui supprime automatiquement les "
|
|
"doublons, puis la transforme à nouveau en liste."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1261
|
|
msgid "How do you make an array in Python?"
|
|
msgstr "Comment construire un tableau en Python?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1263
|
|
msgid "Use a list::"
|
|
msgstr "Utilisez une liste::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1267
|
|
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 ""
|
|
"Les listes ont un cout équivalent à celui des tableau C ou Pascal; la "
|
|
"principale différence est qu'une liste Python peut contenir des objets de "
|
|
"différents types."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1270
|
|
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 the Numeric extensions and others define array-like "
|
|
"structures with various characteristics as well."
|
|
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 l'extension ``Numeric`` et d'autres, "
|
|
"fournissent différentes structures de types tableaux, avec des "
|
|
"caractéristiques différentes."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1275
|
|
msgid ""
|
|
"To get Lisp-style linked lists, you can emulate cons cells using tuples::"
|
|
msgstr ""
|
|
"Pour obtenir des listes chainées de type Lisp, vous pouvez émuler les \"cons "
|
|
"cells\" en utilisant des tuples::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1279
|
|
msgid ""
|
|
"If mutability is desired, you could use lists instead of tuples. Here the "
|
|
"analogue of lisp car is ``lisp_list[0]`` and the analogue of cdr is "
|
|
"``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 tuple. Ici la version équivalente au \"car\" de Lisp est "
|
|
"``lisp_list[0]`` et l'équivalent à \"cdr\" est ``list_lip[1]``. Ne faîtes "
|
|
"ceci que si vous êtes réellement sûr d'en avoir besoin, cette méthode est en "
|
|
"générale bien plus lente que les listes Python."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1286
|
|
msgid "How do I create a multidimensional list?"
|
|
msgstr "Comment puis-je créer une liste à plusieurs dimensions?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1288
|
|
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::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1292
|
|
msgid "This looks correct if you print it::"
|
|
msgstr "Cela semble correct quand vous essayer de l'afficher::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1297
|
|
msgid "But when you assign a value, it shows up in multiple places:"
|
|
msgstr ""
|
|
"Mais quand vous assignez une valeur, elle apparait en de multiples endroits::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1303
|
|
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 ""
|
|
"La raison en est que dupliquer une liste en utilisant ``*`` ne crée pas de "
|
|
"copies, cela crée 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 de façon quasi certaine, pas ce que vous souhaitez."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1308
|
|
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 ""
|
|
"L'approche suggérée est de créer une liste de la longueur désiré d'abords, "
|
|
"puis de remplir tous les éléments avec une chaîne nouvellement créée."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1315
|
|
msgid ""
|
|
"This generates a list containing 3 different lists of length two. You can "
|
|
"also use a list comprehension::"
|
|
msgstr ""
|
|
"Cette liste générée contient trois listes différentes de longueur deux. Vous "
|
|
"pouvez aussi utilisez la notation de compréhension de listes."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1321
|
|
#, fuzzy
|
|
msgid ""
|
|
"Or, you can use an extension that provides a matrix datatype; `Numeric "
|
|
"Python <http://www.numpy.org/>`_ is the best known."
|
|
msgstr ""
|
|
"Ou, vous pouvez utiliser une extension qui fournis un type de donnée de type "
|
|
"matrice; `Numeric Python <http://numpy.scipy.org/>`_ étant le plus connu."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1326
|
|
msgid "How do I apply a method to a sequence of objects?"
|
|
msgstr "Comment appliquer une méthode à une séquence d'objets?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1328
|
|
msgid "Use a list comprehension::"
|
|
msgstr "Utilisez une compréhension de liste::"
|
|
|
|
# b9679b4f562b436b813e6240782d1e63
|
|
#: ../src/Doc/faq/programming.rst:1332
|
|
msgid "More generically, you can try the following function::"
|
|
msgstr ""
|
|
|
|
# 5a0eb6dede2647bdac746cbc48c5eba5
|
|
#: ../src/Doc/faq/programming.rst:1342
|
|
msgid ""
|
|
"Why does a_tuple[i] += ['item'] raise an exception when the addition works?"
|
|
msgstr ""
|
|
|
|
# 8e31dcde6e1f4ce3b7c3c4effef19a96
|
|
#: ../src/Doc/faq/programming.rst:1344
|
|
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 ""
|
|
|
|
# 18c8244bc189403c8895afe6d77cc812
|
|
#: ../src/Doc/faq/programming.rst:1348
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1352
|
|
#, fuzzy
|
|
msgid "If you wrote::"
|
|
msgstr "In C++ you'd write"
|
|
|
|
# cffe9637e54d476794eb875231ac036a
|
|
#: ../src/Doc/faq/programming.rst:1360
|
|
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 ""
|
|
|
|
# 8dcb87ef61454fadbf4fc78f068e58c7
|
|
#: ../src/Doc/faq/programming.rst:1366
|
|
msgid ""
|
|
"Under the covers, what this augmented assignment statement is doing is "
|
|
"approximately this::"
|
|
msgstr ""
|
|
|
|
# 04515ebb67074e5193bcbe4a00b2bd91
|
|
#: ../src/Doc/faq/programming.rst:1375
|
|
msgid ""
|
|
"It is the assignment part of the operation that produces the error, since a "
|
|
"tuple is immutable."
|
|
msgstr ""
|
|
|
|
# 22ab6008a94a4d6495c88e57365e7312
|
|
#: ../src/Doc/faq/programming.rst:1378
|
|
msgid "When you write something like::"
|
|
msgstr ""
|
|
|
|
# 9b46cde118ca40508fedaacc63714819
|
|
#: ../src/Doc/faq/programming.rst:1386
|
|
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 ""
|
|
|
|
# c28e7f2a9c4c4302955de0232c836eda
|
|
#: ../src/Doc/faq/programming.rst:1392
|
|
msgid ""
|
|
"To see why this happens, you need to know that (a) if an object implements "
|
|
"an ``__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, ``__iadd__`` is equivalent to "
|
|
"calling ``extend`` on the list and returning the list. That's why we say "
|
|
"that for lists, ``+=`` is a \"shorthand\" for ``list.extend``::"
|
|
msgstr ""
|
|
|
|
# ced4b3cf4f0946c1a201c57c5e321cf3
|
|
#: ../src/Doc/faq/programming.rst:1404
|
|
msgid "This is equivalent to::"
|
|
msgstr ""
|
|
|
|
# 785acb48819d476eb6b4f321f4c38644
|
|
#: ../src/Doc/faq/programming.rst:1409
|
|
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 ""
|
|
|
|
# 57b86ec3f01146199872ad5223ff75ac
|
|
#: ../src/Doc/faq/programming.rst:1414
|
|
msgid "Thus, in our tuple example what is happening is equivalent to::"
|
|
msgstr ""
|
|
|
|
# 9885a85fc7e943cebf75939e62e69ff6
|
|
#: ../src/Doc/faq/programming.rst:1422
|
|
msgid ""
|
|
"The ``__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."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1428
|
|
msgid "Dictionaries"
|
|
msgstr "Dictionnaires"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1431
|
|
msgid "How can I get a dictionary to display its keys in a consistent order?"
|
|
msgstr ""
|
|
"Comment puis-je faire afficher les éléments d'un dictionnaire dans un ordre "
|
|
"consistant?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1433
|
|
msgid ""
|
|
"You can't. Dictionaries store their keys in an unpredictable order, so the "
|
|
"display order of a dictionary's elements will be similarly unpredictable."
|
|
msgstr ""
|
|
"Vous ne pouvez pas. Les dictionnaires enregistrent leurs clées dans un ordre "
|
|
"non prévisible, l'ordre d'affichage des éléments d'un dictionnaire sera donc "
|
|
"de la même façon imprévisible."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1436
|
|
msgid ""
|
|
"This can be frustrating if you want to save a printable version to a file, "
|
|
"make some changes and then compare it with some other printed dictionary. "
|
|
"In this case, use the ``pprint`` module to pretty-print the dictionary; the "
|
|
"items will be presented in order sorted by the key."
|
|
msgstr ""
|
|
"Cela peut être frustrant si vous voulez sauvegarder une version affichable "
|
|
"dans un fichier, faire des changement puis comparer avec un autre "
|
|
"dictionnaire affiché. Dans ce cas, utilisez le module ``pprint``` pour "
|
|
"afficher joliement le dictionnaire; les éléments seront présentés triés par "
|
|
"clés."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1441
|
|
msgid ""
|
|
"A more complicated solution is to subclass ``dict`` to create a "
|
|
"``SortedDict`` class that prints itself in a predictable order. Here's one "
|
|
"simpleminded implementation of such a class::"
|
|
msgstr ""
|
|
"Une solution plus compliquée est de sousclasser ``dict`` pour créer une "
|
|
"classe``SorterDict`` qui s'affiche de façon prévisible. Voici une "
|
|
"implémentation simple d'une telle classe::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1453
|
|
msgid ""
|
|
"This will work for many common situations you might encounter, though it's "
|
|
"far from a perfect solution. The largest flaw is that if some values in the "
|
|
"dictionary are also dictionaries, their values won't be presented in any "
|
|
"particular order."
|
|
msgstr ""
|
|
"Cela marchera dans la plupart des situations que vous pourriez rencontrer, "
|
|
"même si c'est loin d'être une solution parfaite. Le plus gros problème avec "
|
|
"cette solution est que si certaines valeurs dans le dictionnaire sont aussi "
|
|
"des dictionnaire, alors elles ne seront pas présentées dans un ordre "
|
|
"particulier."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1460
|
|
msgid ""
|
|
"I want to do a complicated sort: can you do a Schwartzian Transform in "
|
|
"Python?"
|
|
msgstr ""
|
|
"Je souhaite faire un tri compliqué: peut on faire une transformation de "
|
|
"Schwartz en Python?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1462
|
|
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, just use the ``key`` argument for the ``sort()`` method::"
|
|
msgstr ""
|
|
"Cette technique, attribuée à Randal Schwartz de la communauté Perl, trie les "
|
|
"éléments d'une liste selon une mesure qui fait correspondre chaque élément à "
|
|
"une \"valeur de tri\". En Python, utilisez simplement l'argument ``key`` de "
|
|
"la méthode ``sort``::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1469
|
|
msgid ""
|
|
"The ``key`` argument is new in Python 2.4, for older versions this kind of "
|
|
"sorting is quite simple to do with list comprehensions. To sort a list of "
|
|
"strings by their uppercase values::"
|
|
msgstr ""
|
|
"L'argument ``key`` est apparus en Python 2.4, pour les anciennes versions de "
|
|
"Python, ce type de tri est relativement simple à faire avec des "
|
|
"compréhensions de liste. Pour trier une liste de chaines par leur valeur en "
|
|
"majuscule on peut faire::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1477
|
|
msgid ""
|
|
"To sort by the integer value of a subfield extending from positions 10-15 in "
|
|
"each string::"
|
|
msgstr ""
|
|
"Pour trier par la valeur d'un sous-champ allant des index 10 à 15 dans "
|
|
"chaque chaine chaine::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1484
|
|
#, fuzzy
|
|
msgid "Note that Isorted may also be computed by ::"
|
|
msgstr ""
|
|
"Pour les versions antérieures à 3.0, Isorted peut également être calculé par:"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1495
|
|
msgid ""
|
|
"but since this method calls ``intfield()`` many times for each element of L, "
|
|
"it is slower than the Schwartzian Transform."
|
|
msgstr ""
|
|
"mais du fait que cette méthode appelle `` intfield () `` plusieurs fois pour "
|
|
"chaque élément de L, elle est plus lente que la transformée de Schwartz."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1500
|
|
msgid "How can I sort one list by values from another list?"
|
|
msgstr ""
|
|
"Comment puis-je trier une liste en fonction des valeurs d'une autre liste?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1502
|
|
#, fuzzy
|
|
msgid ""
|
|
"Merge them into a single list of tuples, sort the resulting list, and then "
|
|
"pick out the element you want. ::"
|
|
msgstr ""
|
|
"Fusionnez les dans un itérateur de tuples, trier la liste obtenue, puis "
|
|
"choisissez l'élément que vous voulez. ::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1515
|
|
#, fuzzy
|
|
msgid "An alternative for the last step is::"
|
|
msgstr "Une alternative pour la dernière étape est la suivante::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1520
|
|
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 vous trouvez cela plus lisible, vous préférez peut-être utiliser ceci à "
|
|
"la place de la compréhension de la liste finale. Toutefois, ceci est presque "
|
|
"deux fois plus lent pour les longues listes. Pourquoi? Tout d'abord, "
|
|
"``append ()`` doit réaffecter la mémoire, et si il utilise quelques astuces "
|
|
"pour éviter de le faire à chaque fois, il doit encore le faire de temps en "
|
|
"temps, ce qui coûte assez cher. Deuxièmement, l'expression \"result.append\" "
|
|
"exige une recherche d'attribut supplémentaire, et enfin, tous ces appels de "
|
|
"fonction impactent la vitesse d'exécution."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1530
|
|
msgid "Objects"
|
|
msgstr "Objets"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1533
|
|
msgid "What is a class?"
|
|
msgstr "Qu'est-ce qu'une classe?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1535
|
|
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."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1539
|
|
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 "
|
|
"ou ses classes de base. Il hérite alors les attributs et les méthodes de ses "
|
|
"classes de base. Cela permet à un modèle d'objet d'être successivement "
|
|
"raffinés 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 sous-"
|
|
"classes telles que ``MboxMailbox``, ``MaildirMailbox``, ``OutlookMailbox`` "
|
|
"qui gèrent les différents formats de boîtes aux lettres spécifiques."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1548
|
|
msgid "What is a method?"
|
|
msgstr "Qu'est-ce qu'une méthode?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1550
|
|
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 ""
|
|
"Une méthode est une fonction sur un objet ``x`` appelez normalement comme "
|
|
"``x.name(arguments…)``. Les méthodes sont définies comme des fonctions à "
|
|
"l'intérieur de la définition de classe::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1560
|
|
msgid "What is self?"
|
|
msgstr "Qu'est-ce que self?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1562
|
|
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 ""
|
|
"Self est simplement un nom conventionnel pour le premier argument d'une "
|
|
"méthode. Une méthode définie comme ``meth(self, a, b, c)`` doit être appelée "
|
|
"en tant que ``x.meth(a, b, c)``, pour une instance ``x`` de la classe dans "
|
|
"laquelle elle est définie, la méthode appelée considérera qu'elle est "
|
|
"appelée ``meth(x, a, b, c)``."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1567
|
|
msgid "See also :ref:`why-self`."
|
|
msgstr "Voir aussi: ref:`why-self`."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1571
|
|
msgid ""
|
|
"How do I check if an object is an instance of a given class or of a subclass "
|
|
"of it?"
|
|
msgstr ""
|
|
"Comment puis-je vérifier si un objet est une instance d'une classe donnée ou "
|
|
"d'une sous-classe de celui-ci?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1573
|
|
#, fuzzy
|
|
msgid ""
|
|
"Use the built-in function ``isinstance(obj, cls)``. 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, long, float, complex))``."
|
|
msgstr ""
|
|
"Utilisez la fonction intégrée ``isInstance(obj, CLS)``. Vous pouvez vérifier "
|
|
"si un objet est une instance de n'importe lequel d'un certain nombre de "
|
|
"classes en fournissant un tuple à la place d'une seule classe, par exemple, "
|
|
"``IsInstance (obj, (Classe1, classe2, ...))``, et peut également vérifier si "
|
|
"un objet est l'un des types intégrés à Python, par exemple, ``IsInstance "
|
|
"(obj, str) isInstance`` ou ``(obj, (int, float, complexes ))``."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1579
|
|
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 ""
|
|
"Notez que la plupart des programmes n'utilisent pas : func:``isInstance`` "
|
|
"sur les classes définies par l'utilisateur, très souvent. Si vous développez "
|
|
"vous-même les classes, un style plus appropriée orientée objet est de "
|
|
"définir des méthodes sur les classes qui encapsulent un comportement "
|
|
"particulier, au lieu de vérifier la classe de l'objet et de faire quelque "
|
|
"chose de différent en fonction de sa classe. Par exemple, si vous avez une "
|
|
"fonction qui fait quelque chose::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1593
|
|
msgid ""
|
|
"A better approach is to define a ``search()`` method on all the classes and "
|
|
"just call it::"
|
|
msgstr ""
|
|
"Une meilleure approche est de définir une méthode ``search()`` sur toutes "
|
|
"les classes et qu'il suffit d'appeler::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1608
|
|
msgid "What is delegation?"
|
|
msgstr "Qu'est-ce que la délégation?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1610
|
|
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 ""
|
|
"La délégation est une technique orientée objet (aussi appelé un modèle de "
|
|
"conception). Disons que vous avez un objet ``x`` et que vous souhaitez "
|
|
"modifier le comportement d'une seule de ses méthodes. Vous pouvez créer une "
|
|
"nouvelle classe qui fournit une nouvelle implémentation de la méthode qui "
|
|
"vous intéresse dans l'évolution et les délégués de toutes les autres "
|
|
"méthodes la méthode correspondante de ``x``."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1616
|
|
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:"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1631
|
|
msgid ""
|
|
"Here the ``UpperOut`` class redefines the ``write()`` method to convert the "
|
|
"argument string to uppercase before calling the underlying ``self.__outfile."
|
|
"write()`` method. All other methods are delegated to the underlying ``self."
|
|
"__outfile`` object. The delegation is accomplished via the ``__getattr__`` "
|
|
"method; consult :ref:`the language reference <attribute-access>` for more "
|
|
"information about controlling attribute access."
|
|
msgstr ""
|
|
"Ici, la classe ``UpperOut`` redéfinit la méthode ``write()`` pour convertir "
|
|
"la chaîne d'argument en majuscules avant d'appeler la méthode sous-jacentes "
|
|
"``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 le contrôle d'accès d'attribut."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1638
|
|
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:"
|
|
"`__setattr__` method too, and it must do so carefully. The basic "
|
|
"implementation of :meth:`__setattr__` is roughly equivalent to the "
|
|
"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:"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1649
|
|
msgid ""
|
|
"Most :meth:`__setattr__` implementations must modify ``self.__dict__`` to "
|
|
"store local state for self without causing an infinite recursion."
|
|
msgstr ""
|
|
"La plupart des implémentations de: meth:`__setattr__` doivent modifier "
|
|
"``self.__dict__`` pour stocker l'état locale de self sans provoquer une "
|
|
"récursion infinie."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1654
|
|
msgid ""
|
|
"How do I call a method defined in a base class from a derived class that "
|
|
"overrides it?"
|
|
msgstr ""
|
|
"Comment appeler une méthode définie dans une classe de base depuis une "
|
|
"classe dérivée qui la surcharge?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1656
|
|
#, fuzzy
|
|
msgid ""
|
|
"If you're using new-style classes, use the built-in :func:`super` function::"
|
|
msgstr "Utilisez la fonction built-in :func:``super``::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1662
|
|
#, fuzzy
|
|
msgid ""
|
|
"If you're 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 version antérieure à 3.0, vous pouvez utiliser des classes classiques: "
|
|
"Pour une définition de classe telle que ``class derived(Base)...`` vous "
|
|
"pouvez appeler la méthode ``meth()`` défini 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, vous devez donc fournir "
|
|
"l'argument ``self``."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1670
|
|
msgid "How can I organize my code to make it easier to change the base class?"
|
|
msgstr ""
|
|
"Comment puis-je organiser mon code pour permettre de changer la classe de "
|
|
"base plus facilement?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1672
|
|
msgid ""
|
|
"You could define an alias for the base class, assign the real base class to "
|
|
"it before your class definition, and use the alias throughout your class. "
|
|
"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::"
|
|
msgstr ""
|
|
"Vous pouvez définir un alias pour la classe de base, lui attribuer la classe "
|
|
"de base réelle avant la définition de classe, et utiliser l'alias au long de "
|
|
"votre classe. Ensuite, tout ce que vous devez changer est la valeur "
|
|
"attribuée à l'alias. Incidemment, cette astuce est également utile si vous "
|
|
"voulez décider dynamiquement (par exemple en fonction de la disponibilité "
|
|
"des ressources) la classe de base à utiliser. Exemple::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1687
|
|
msgid "How do I create static class data and static class methods?"
|
|
msgstr ""
|
|
"Comment puis-je créer des données statiques de classe et des méthodes "
|
|
"statiques de classe?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1689
|
|
msgid ""
|
|
"Both static data and static methods (in the sense of C++ or Java) are "
|
|
"supported in Python."
|
|
msgstr ""
|
|
"Tant les données statiques que les méthodes statiques (dans le sens de C + + "
|
|
"ou Java) sont pris en charge en Python."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1692
|
|
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:"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1704
|
|
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 ""
|
|
"``c.count`` se réfère également à ``C.count`` pour tout ``c`` telle que "
|
|
"``isInstance (c, C)`` est vrai, sauf remplacement par ``c`` lui-même ou par "
|
|
"une classe sur le chemin de recherche de classe de base de ``c.__class__`` "
|
|
"jusqu'à ``C``."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1708
|
|
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 ""
|
|
"Attention: dans une méthode de C, une affectation comme ``self.count=42`` "
|
|
"crée une nouvelle instance et sans rapport avec le nom \"count\" dans 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:"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1715
|
|
msgid "Static methods are possible since Python 2.2::"
|
|
msgstr "Les méthodes statiques sont possibles depuis Python 2.2::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1723
|
|
msgid "With Python 2.4's decorators, this can also be written as ::"
|
|
msgstr "Avec les décorateurs de Python 2.4, cela peut aussi s'écrire:"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1731
|
|
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::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1737
|
|
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."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1742
|
|
msgid "How can I overload constructors (or methods) in Python?"
|
|
msgstr "Comment puis-je surcharger les constructeurs (ou méthodes) en Python?"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1744
|
|
msgid ""
|
|
"This answer actually applies to all methods, but the question usually comes "
|
|
"up first in the context of constructors."
|
|
msgstr ""
|
|
"Cette réponse s'applique en fait à toutes les méthodes, mais la question "
|
|
"vient généralement en premier dans le contexte des constructeurs."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1747
|
|
msgid "In C++ you'd write"
|
|
msgstr "In C++ you'd write"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1756
|
|
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::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1766
|
|
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."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1768
|
|
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 ::"
|
|
|
|
#: ../src/Doc/faq/programming.rst:1773
|
|
msgid "The same approach works for all method definitions."
|
|
msgstr "La même approche fonctionne pour toutes les définitions de méthode."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1777
|
|
msgid "I try to use __spam and I get an error about _SomeClassName__spam."
|
|
msgstr ""
|
|
"J'essaie d'utiliser __spam et j'obtiens une erreur à propos de "
|
|
"_SomeClassName__spam."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1779
|
|
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 avec le double de soulignement sont «déformés» pour "
|
|
"fournir un moyen simple mais efficace de définir variables privées à la "
|
|
"classe. Tout identificateur de la forme ``__spam`` (au moins deux traits de "
|
|
"soulignement préfixe, au plus un soulignement suffix) est textuellement "
|
|
"remplacé par ``_classname__spam``, où ``classname`` est le nom de la classe "
|
|
"en cours avec les traits de soulignement dépouillés."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1785
|
|
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 ""
|
|
"Cela ne garantit pas la privauté de l'accès : un utilisateur extérieur peut "
|
|
"encore délibérément acceder à 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ée."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1792
|
|
msgid "My class defines __del__ but it is not called when I delete the object."
|
|
msgstr ""
|
|
"Ma classe définit __del__ mais il n'est pas appelé lorsque je supprime "
|
|
"l'objet."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1794
|
|
msgid "There are several possible reasons for this."
|
|
msgstr "Il y a plusieurs raisons possibles pour cela."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1796
|
|
msgid ""
|
|
"The del statement does not necessarily call :meth:`__del__` -- it simply "
|
|
"decrements the object's reference count, and if this reaches zero :meth:"
|
|
"`__del__` is called."
|
|
msgstr ""
|
|
"La commande del n'appelle pas forcément: meth: `__del__` - il 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."
|
|
|
|
#: ../src/Doc/faq/programming.rst:1800
|
|
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__` "
|
|
"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 "
|
|
"run :func:`gc.collect` to force a collection, but there *are* pathological "
|
|
"cases where objects will never be collected."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1811
|
|
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. "
|
|
"The ``close()`` method can then remove attributes that refer to subobjecs. "
|
|
"Don't call :meth:`__del__` directly -- :meth:`__del__` should call "
|
|
"``close()`` and ``close()`` should make sure that it can be called more than "
|
|
"once for the same object."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1818
|
|
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 ""
|
|
|
|
# b4b0759b65604b06bde8e32f69de4d3b
|
|
#: ../src/Doc/faq/programming.rst:1823
|
|
msgid ""
|
|
"If the object has ever been a local variable in a function that caught an "
|
|
"expression in an except clause, chances are that a reference to the object "
|
|
"still exists in that function's stack frame as contained in the stack trace. "
|
|
"Normally, calling :func:`sys.exc_clear` will take care of this by clearing "
|
|
"the last recorded exception."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1829
|
|
msgid ""
|
|
"Finally, if your :meth:`__del__` method raises an exception, a warning "
|
|
"message is printed to :data:`sys.stderr`."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1834
|
|
msgid "How do I get a list of all instances of a given class?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1836
|
|
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 ""
|
|
|
|
# cf90e9f3b4064c549dfbec4909638712
|
|
#: ../src/Doc/faq/programming.rst:1842
|
|
msgid "Why does the result of ``id()`` appear to be not unique?"
|
|
msgstr ""
|
|
|
|
# f61b99b4126f49fe955ab0fa86ba17b4
|
|
#: ../src/Doc/faq/programming.rst:1844
|
|
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 ""
|
|
|
|
# b3a195c4502f46088e88298fe469109c
|
|
#: ../src/Doc/faq/programming.rst:1855
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1868
|
|
msgid "Modules"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1871
|
|
msgid "How do I create a .pyc file?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1873
|
|
msgid ""
|
|
"When a module is imported for the first time (or when the source is more "
|
|
"recent than the current compiled file) a ``.pyc`` file containing the "
|
|
"compiled code should be created in the same directory as the ``.py`` file."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1877
|
|
msgid ""
|
|
"One reason that a ``.pyc`` file may not be created is permissions problems "
|
|
"with the directory. 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. Creation "
|
|
"of a .pyc file is automatic if you're importing a module and Python has the "
|
|
"ability (permissions, free space, etc...) to write the compiled module back "
|
|
"to the directory."
|
|
msgstr ""
|
|
|
|
# 03d92f68c7e349ccabb520f05c0d88d4
|
|
#: ../src/Doc/faq/programming.rst:1884
|
|
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``, ``xyz."
|
|
"pyc`` will be created since ``xyz`` is imported, but no ``foo.pyc`` file "
|
|
"will be created since ``foo.py`` isn't being imported."
|
|
msgstr ""
|
|
|
|
# 8b7c0689fc08464b8f5080f3fc41c75b
|
|
#: ../src/Doc/faq/programming.rst:1890
|
|
msgid ""
|
|
"If you need to create ``foo.pyc`` -- 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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1894
|
|
msgid ""
|
|
"The :mod:`py_compile` module can manually compile any module. One way is to "
|
|
"use the ``compile()`` function in that module interactively::"
|
|
msgstr ""
|
|
|
|
# 6d7165204d3741dfa3edb6045c2e4ab9
|
|
#: ../src/Doc/faq/programming.rst:1900
|
|
msgid ""
|
|
"This will write the ``.pyc`` to the same location as ``foo.py`` (or you can "
|
|
"override that with the optional parameter ``cfile``)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1903
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1912
|
|
msgid "How do I find the current module name?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1914
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1929
|
|
msgid "How can I have modules that mutually import each other?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1931
|
|
msgid "Suppose you have the following modules:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1933
|
|
msgid "foo.py::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1938
|
|
msgid "bar.py::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1943
|
|
msgid "The problem is that the interpreter will perform the following steps:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1945
|
|
msgid "main imports foo"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1946
|
|
msgid "Empty globals for foo are created"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1947
|
|
msgid "foo is compiled and starts executing"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1948
|
|
msgid "foo imports bar"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1949
|
|
msgid "Empty globals for bar are created"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1950
|
|
msgid "bar is compiled and starts executing"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1951
|
|
msgid ""
|
|
"bar imports foo (which is a no-op since there already is a module named foo)"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1952
|
|
msgid "bar.foo_var = foo.foo_var"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1954
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1957
|
|
msgid ""
|
|
"The same thing happens when you use ``import foo``, and then try to access "
|
|
"``foo.foo_var`` in global code."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1960
|
|
msgid "There are (at least) three possible workarounds for this problem."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1962
|
|
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 ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1967
|
|
msgid ""
|
|
"Jim Roskind suggests performing steps in the following order in each module:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1969
|
|
msgid ""
|
|
"exports (globals, functions, and classes that don't need imported base "
|
|
"classes)"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1971
|
|
msgid "``import`` statements"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1972
|
|
msgid ""
|
|
"active code (including globals that are initialized from imported values)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1974
|
|
msgid ""
|
|
"van Rossum doesn't like this approach much because the imports appear in a "
|
|
"strange place, but it does work."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1977
|
|
msgid ""
|
|
"Matthias Urlichs recommends restructuring your code so that the recursive "
|
|
"import is not necessary in the first place."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1980
|
|
msgid "These solutions are not mutually exclusive."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1984
|
|
msgid "__import__('x.y.z') returns <module 'x'>; how do I get z?"
|
|
msgstr ""
|
|
|
|
# e48fce842ecb4de4838850cae5fbd306
|
|
#: ../src/Doc/faq/programming.rst:1986
|
|
msgid ""
|
|
"Consider using the convenience function :func:`~importlib.import_module` "
|
|
"from :mod:`importlib` instead::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1993
|
|
msgid ""
|
|
"When I edit an imported module and reimport it, the changes don't show up. "
|
|
"Why does this happen?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:1995
|
|
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 "
|
|
"rereading of a changed module, do this::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:2004
|
|
msgid ""
|
|
"Warning: this technique is not 100% fool-proof. In particular, modules "
|
|
"containing statements like ::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/programming.rst:2009
|
|
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 "
|
|
"paradoxical behaviour:"
|
|
msgstr ""
|
|
|
|
# 702dbe1732aa493f8a0b6bb56cb2522c
|
|
#: ../src/Doc/faq/programming.rst:2021
|
|
msgid ""
|
|
"The nature of the problem is made clear if you print out the class objects:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:7
|
|
msgid "Python on Windows FAQ"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:14
|
|
msgid "How do I run a Python program under Windows?"
|
|
msgstr ""
|
|
|
|
# 53ef8c8cd2b8484c88c64aab2a4e1a36
|
|
#: ../src/Doc/faq/windows.rst:16
|
|
msgid ""
|
|
"This is not necessarily a straightforward question. If you are already "
|
|
"familiar with running programs from the Windows command line then everything "
|
|
"will seem obvious; otherwise, you might need a little more guidance."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:23
|
|
msgid ""
|
|
"This series of screencasts aims to get you up and running with Python on "
|
|
"Windows XP. The knowledge is distilled into 1.5 hours and will get you up "
|
|
"and running with the right Python distribution, coding in your choice of "
|
|
"IDE, and debugging and writing solid code with unit-tests."
|
|
msgstr ""
|
|
|
|
# 9d7948e6038a4a51a4bad91ca4fc7931
|
|
#: ../src/Doc/faq/windows.rst:32
|
|
msgid ""
|
|
"Unless you use some sort of integrated development environment, you will end "
|
|
"up *typing* Windows commands into what is variously referred to as a \"DOS "
|
|
"window\" or \"Command prompt window\". Usually you can create such a window "
|
|
"from your Start menu; under Windows 7 the menu selection is :menuselection:"
|
|
"`Start --> Programs --> Accessories --> Command Prompt`. You should be able "
|
|
"to recognize when you have started such a window because you will see a "
|
|
"Windows \"command prompt\", which usually looks like this::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:42
|
|
msgid ""
|
|
"The letter may be different, and there might be other things after it, so "
|
|
"you might just as easily see something like::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:47
|
|
msgid ""
|
|
"depending on how your computer has been set up and what else you have "
|
|
"recently done with it. Once you have started such a window, you are well on "
|
|
"the way to running Python programs."
|
|
msgstr ""
|
|
|
|
# 6c03998a0a844db1971bea8cd63765fa
|
|
#: ../src/Doc/faq/windows.rst:51
|
|
msgid ""
|
|
"You need to realize that your Python scripts have to be processed by another "
|
|
"program called the Python *interpreter*. The interpreter reads your script, "
|
|
"compiles it into bytecodes, and then executes the bytecodes to run your "
|
|
"program. So, how do you arrange for the interpreter to handle your Python?"
|
|
msgstr ""
|
|
|
|
# 4eb0edada5ae45ad99a255b0db73a830
|
|
#: ../src/Doc/faq/windows.rst:56
|
|
msgid ""
|
|
"First, you need to make sure that your command window recognises the word "
|
|
"\"python\" as an instruction to start the interpreter. If you have opened a "
|
|
"command window, you should try entering the command ``python`` and hitting "
|
|
"return.::"
|
|
msgstr ""
|
|
|
|
# 4f609a87bff2442ca7cd1ff9bd7cdaf8
|
|
#: ../src/Doc/faq/windows.rst:63
|
|
msgid "You should then see something like::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:69
|
|
msgid ""
|
|
"You have started the interpreter in \"interactive mode\". That means you can "
|
|
"enter Python statements or expressions interactively and have them executed "
|
|
"or evaluated while you wait. This is one of Python's strongest features. "
|
|
"Check it by entering a few expressions of your choice and seeing the "
|
|
"results::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:79
|
|
msgid ""
|
|
"Many people use the interactive mode as a convenient yet highly programmable "
|
|
"calculator. When you want to end your interactive Python session, hold the "
|
|
"Ctrl key down while you enter a Z, then hit the \"Enter\" key to get back to "
|
|
"your Windows command prompt."
|
|
msgstr ""
|
|
|
|
# 7bd42cac219b40848c7921867591430f
|
|
#: ../src/Doc/faq/windows.rst:84
|
|
msgid ""
|
|
"You may also find that you have a Start-menu entry such as :menuselection:"
|
|
"`Start --> Programs --> Python 2.7 --> Python (command line)` that results "
|
|
"in you seeing the ``>>>`` prompt in a new window. If so, the window will "
|
|
"disappear after you enter the Ctrl-Z character; Windows is running a single "
|
|
"\"python\" command in the window, and closes it when you terminate the "
|
|
"interpreter."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:90
|
|
msgid ""
|
|
"If the ``python`` command, instead of displaying the interpreter prompt "
|
|
"``>>>``, gives you a message like::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:98
|
|
msgid ""
|
|
"Python is not added to the DOS path by default. This screencast will walk "
|
|
"you through the steps to add the correct entry to the `System Path`, "
|
|
"allowing Python to be executed from the command-line by all users."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:111
|
|
msgid ""
|
|
"then you need to make sure that your computer knows where to find the Python "
|
|
"interpreter. To do this you will have to modify a setting called PATH, "
|
|
"which is a list of directories where Windows will look for programs."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:115
|
|
msgid ""
|
|
"You should arrange for Python's installation directory to be added to the "
|
|
"PATH of every command window as it starts. If you installed Python fairly "
|
|
"recently then the command ::"
|
|
msgstr ""
|
|
|
|
# f46c3c06a6614fd7a3f399a789a6f00f
|
|
#: ../src/Doc/faq/windows.rst:121
|
|
msgid ""
|
|
"will probably tell you where it is installed; the usual location is "
|
|
"something like ``C:\\Python27``. Otherwise you will be reduced to a search "
|
|
"of your whole disk ... use :menuselection:`Tools --> Find` or hit the :"
|
|
"guilabel:`Search` button and look for \"python.exe\". Supposing you "
|
|
"discover that Python is installed in the ``C:\\Python27`` directory (the "
|
|
"default at the time of writing), you should make sure that entering the "
|
|
"command ::"
|
|
msgstr ""
|
|
|
|
# a999141b52e441e189824b2293f0481e
|
|
#: ../src/Doc/faq/windows.rst:130
|
|
msgid ""
|
|
"starts up the interpreter as above (and don't forget you'll need a \"CTRL-Z"
|
|
"\" and an \"Enter\" to get out of it). Once you have verified the directory, "
|
|
"you can add it to the system path to make it easier to start Python by just "
|
|
"running the ``python`` command. This is currently an option in the installer "
|
|
"as of CPython 2.7."
|
|
msgstr ""
|
|
|
|
# ed7403dd874946cdbc3f3918c7d74c16
|
|
#: ../src/Doc/faq/windows.rst:136
|
|
msgid ""
|
|
"More information about environment variables can be found on the :ref:`Using "
|
|
"Python on Windows <setting-envvars>` page."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:140
|
|
msgid "How do I make Python scripts executable?"
|
|
msgstr ""
|
|
|
|
# 507a227f35bb44819a7430bc0380a3fa
|
|
#: ../src/Doc/faq/windows.rst:142
|
|
msgid ""
|
|
"On Windows, the standard Python installer already associates the .py "
|
|
"extension with a file type (Python.File) and gives that file type an open "
|
|
"command that runs the interpreter (``D:\\Program Files\\Python\\python.exe "
|
|
"\"%1\" %*``). This is enough to make scripts executable from the command "
|
|
"prompt as 'foo.py'. If you'd rather be able to execute the script by simple "
|
|
"typing 'foo' with no extension you need to add .py to the PATHEXT "
|
|
"environment variable."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:150
|
|
msgid "Why does Python sometimes take so long to start?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:152
|
|
msgid ""
|
|
"Usually Python starts very quickly on Windows, but occasionally there are "
|
|
"bug reports that Python suddenly begins to take a long time to start up. "
|
|
"This is made even more puzzling because Python will work fine on other "
|
|
"Windows systems which appear to be configured identically."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:157
|
|
msgid ""
|
|
"The problem may be caused by a misconfiguration of virus checking software "
|
|
"on the problem machine. Some virus scanners have been known to introduce "
|
|
"startup overhead of two orders of magnitude when the scanner is configured "
|
|
"to monitor all reads from the filesystem. Try checking the configuration of "
|
|
"virus scanning software on your systems to ensure that they are indeed "
|
|
"configured identically. McAfee, when configured to scan all file system read "
|
|
"activity, is a particular offender."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:167
|
|
#, fuzzy
|
|
msgid "How do I make an executable from a Python script?"
|
|
msgstr "Comment construire un tableau en Python?"
|
|
|
|
# a187634c79d7479a9b909794ef6cfe9f
|
|
#: ../src/Doc/faq/windows.rst:169
|
|
msgid ""
|
|
"See http://www.py2exe.org/ for a distutils extension that allows you to "
|
|
"create console and GUI executables from Python code."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:173
|
|
msgid "Is a ``*.pyd`` file the same as a DLL?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:177
|
|
msgid ""
|
|
"Yes, .pyd files are dll's, but there are a few differences. If you have a "
|
|
"DLL named ``foo.pyd``, then it must have a function ``initfoo()``. You can "
|
|
"then write Python \"import foo\", and Python will search for foo.pyd (as "
|
|
"well as foo.py, foo.pyc) and if it finds it, will attempt to call "
|
|
"``initfoo()`` to initialize it. You do not link your .exe with foo.lib, as "
|
|
"that would cause Windows to require the DLL to be present."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:184
|
|
msgid ""
|
|
"Note that the search path for foo.pyd is PYTHONPATH, not the same as the "
|
|
"path that Windows uses to search for foo.dll. Also, foo.pyd need not be "
|
|
"present to run your program, whereas if you linked your program with a dll, "
|
|
"the dll is required. Of course, foo.pyd is required if you want to say "
|
|
"``import foo``. In a DLL, linkage is declared in the source code with "
|
|
"``__declspec(dllexport)``. In a .pyd, linkage is defined in a list of "
|
|
"available functions."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:193
|
|
msgid "How can I embed Python into a Windows application?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:195
|
|
msgid ""
|
|
"Embedding the Python interpreter in a Windows app can be summarized as "
|
|
"follows:"
|
|
msgstr ""
|
|
|
|
# ffbbe3340bc0406bb54039da3a8b1fac
|
|
#: ../src/Doc/faq/windows.rst:197
|
|
msgid ""
|
|
"Do _not_ build Python into your .exe file directly. On Windows, Python must "
|
|
"be a DLL to handle importing modules that are themselves DLL's. (This is "
|
|
"the first key undocumented fact.) Instead, link to :file:`python{NN}.dll`; "
|
|
"it is typically installed in ``C:\\Windows\\System``. *NN* is the Python "
|
|
"version, a number such as \"27\" for Python 2.7."
|
|
msgstr ""
|
|
|
|
# ccc0def2b7d84a97a01196cbd172917b
|
|
#: ../src/Doc/faq/windows.rst:203
|
|
msgid ""
|
|
"You can link to Python in two different ways. Load-time linking means "
|
|
"linking against :file:`python{NN}.lib`, while run-time linking means linking "
|
|
"against :file:`python{NN}.dll`. (General note: :file:`python{NN}.lib` is "
|
|
"the so-called \"import lib\" corresponding to :file:`python{NN}.dll`. It "
|
|
"merely defines symbols for the linker.)"
|
|
msgstr ""
|
|
|
|
# b83fc8f27fe84320990b94a26419a932
|
|
#: ../src/Doc/faq/windows.rst:209
|
|
msgid ""
|
|
"Run-time linking greatly simplifies link options; everything happens at run "
|
|
"time. Your code must load :file:`python{NN}.dll` using the Windows "
|
|
"``LoadLibraryEx()`` routine. The code must also use access routines and "
|
|
"data in :file:`python{NN}.dll` (that is, Python's C API's) using pointers "
|
|
"obtained by the Windows ``GetProcAddress()`` routine. Macros can make using "
|
|
"these pointers transparent to any C code that calls routines in Python's C "
|
|
"API."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:216
|
|
msgid ""
|
|
"Borland note: convert :file:`python{NN}.lib` to OMF format using Coff2Omf."
|
|
"exe first."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:221
|
|
msgid ""
|
|
"If you use SWIG, it is easy to create a Python \"extension module\" that "
|
|
"will make the app's data and methods available to Python. SWIG will handle "
|
|
"just about all the grungy details for you. The result is C code that you "
|
|
"link *into* your .exe file (!) You do _not_ have to create a DLL file, and "
|
|
"this also simplifies linking."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:227
|
|
msgid ""
|
|
"SWIG will create an init function (a C function) whose name depends on the "
|
|
"name of the extension module. For example, if the name of the module is "
|
|
"leo, the init function will be called initleo(). If you use SWIG shadow "
|
|
"classes, as you should, the init function will be called initleoc(). This "
|
|
"initializes a mostly hidden helper class used by the shadow class."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:233
|
|
msgid ""
|
|
"The reason you can link the C code in step 2 into your .exe file is that "
|
|
"calling the initialization function is equivalent to importing the module "
|
|
"into Python! (This is the second key undocumented fact.)"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:237
|
|
msgid ""
|
|
"In short, you can use the following code to initialize the Python "
|
|
"interpreter with your extension module."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:248
|
|
msgid ""
|
|
"There are two problems with Python's C API which will become apparent if you "
|
|
"use a compiler other than MSVC, the compiler used to build pythonNN.dll."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:251
|
|
msgid ""
|
|
"Problem 1: The so-called \"Very High Level\" functions that take FILE * "
|
|
"arguments will not work in a multi-compiler environment because each "
|
|
"compiler's notion of a struct FILE will be different. From an "
|
|
"implementation standpoint these are very _low_ level functions."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:256
|
|
msgid ""
|
|
"Problem 2: SWIG generates the following code when generating wrappers to "
|
|
"void functions:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:265
|
|
msgid ""
|
|
"Alas, Py_None is a macro that expands to a reference to a complex data "
|
|
"structure called _Py_NoneStruct inside pythonNN.dll. Again, this code will "
|
|
"fail in a mult-compiler environment. Replace such code by:"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:273
|
|
msgid ""
|
|
"It may be possible to use SWIG's ``%typemap`` command to make the change "
|
|
"automatically, though I have not been able to get this to work (I'm a "
|
|
"complete SWIG newbie)."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:277
|
|
msgid ""
|
|
"Using a Python shell script to put up a Python interpreter window from "
|
|
"inside your Windows app is not a good idea; the resulting window will be "
|
|
"independent of your app's windowing system. Rather, you (or the "
|
|
"wxPythonWindow class) should create a \"native\" interpreter window. It is "
|
|
"easy to connect that window to the Python interpreter. You can redirect "
|
|
"Python's i/o to _any_ object that supports read and write, so all you need "
|
|
"is a Python object (defined in your extension module) that contains read() "
|
|
"and write() methods."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:286
|
|
msgid "How do I keep editors from inserting tabs into my Python source?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:288
|
|
msgid ""
|
|
"The FAQ does not recommend using tabs, and the Python style guide, :pep:`8`, "
|
|
"recommends 4 spaces for distributed Python code; this is also the Emacs "
|
|
"python-mode default."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:292
|
|
msgid ""
|
|
"Under any editor, mixing tabs and spaces is a bad idea. MSVC is no "
|
|
"different in this respect, and is easily configured to use spaces: Take :"
|
|
"menuselection:`Tools --> Options --> Tabs`, and for file type \"Default\" "
|
|
"set \"Tab size\" and \"Indent size\" to 4, and select the \"Insert spaces\" "
|
|
"radio button."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:297
|
|
msgid ""
|
|
"If you suspect mixed tabs and spaces are causing problems in leading "
|
|
"whitespace, run Python with the :option:`-t` switch or run ``Tools/Scripts/"
|
|
"tabnanny.py`` to check a directory tree in batch mode."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:303
|
|
msgid "How do I check for a keypress without blocking?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:305
|
|
msgid ""
|
|
"Use the msvcrt module. This is a standard Windows-specific extension "
|
|
"module. It defines a function ``kbhit()`` which checks whether a keyboard "
|
|
"hit is present, and ``getch()`` which gets one character without echoing it."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:311
|
|
msgid "How do I emulate os.kill() in Windows?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:313
|
|
msgid ""
|
|
"Prior to Python 2.7 and 3.2, to terminate a process, you can use :mod:"
|
|
"`ctypes`::"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:323
|
|
msgid ""
|
|
"In 2.7 and 3.2, :func:`os.kill` is implemented similar to the above "
|
|
"function, with the additional feature of being able to send CTRL+C and CTRL"
|
|
"+BREAK to console subprocesses which are designed to handle those signals. "
|
|
"See :func:`os.kill` for further details."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:329
|
|
msgid "How do I extract the downloaded documentation on Windows?"
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:331
|
|
msgid ""
|
|
"Sometimes, when you download the documentation package to a Windows machine "
|
|
"using a web browser, the file extension of the saved file ends up being ."
|
|
"EXE. This is a mistake; the extension should be .TGZ."
|
|
msgstr ""
|
|
|
|
#: ../src/Doc/faq/windows.rst:335
|
|
msgid ""
|
|
"Simply rename the downloaded file to have the .TGZ extension, and WinZip "
|
|
"will be able to handle it. (If your copy of WinZip doesn't, get a newer one "
|
|
"from http://www.winzip.com.)"
|
|
msgstr ""
|
|
|
|
#~ msgid ""
|
|
#~ "In many cases you can mimic ``a ? b : c`` with ``a and b or c``, but "
|
|
#~ "there's a flaw: if *b* is zero (or empty, or ``None`` -- anything that "
|
|
#~ "tests false) then *c* will be selected instead. In many cases you can "
|
|
#~ "prove by looking at the code that this can't happen (e.g. because *b* is "
|
|
#~ "a constant or has a type that can never be false), but in general this "
|
|
#~ "can be a problem."
|
|
#~ msgstr ""
|
|
#~ "Dans de nombreux cas vous pouvez imiter ``a ? b : c`` par ``a and b or "
|
|
#~ "c``, mais il y a une faille: si *b* est zéro (ou vide ou None -- "
|
|
#~ "n'importe quoi qui soit assimilé à False) alors *c* sera choisit à la "
|
|
#~ "place. Dans de nombreux cas vous pouvez montrer que ça ne peux pas "
|
|
#~ "arriver par observation du code (par exemple si *b* est une constante ou "
|
|
#~ "est d'un type ne pouvant être assimilé à False), mais dans le cas général "
|
|
#~ "cela peut être un problème."
|
|
|
|
#~ msgid ""
|
|
#~ "Tim Peters (who wishes it was Steve Majewski) suggested the following "
|
|
#~ "solution: ``(a and [b] or [c])[0]``. Because ``[b]`` is a singleton list "
|
|
#~ "it is never false, so the wrong path is never taken; then applying "
|
|
#~ "``[0]`` to the whole thing gets the *b* or *c* that you really wanted. "
|
|
#~ "Ugly, but it gets you there in the rare cases where it is really "
|
|
#~ "inconvenient to rewrite your code using 'if'."
|
|
#~ msgstr ""
|
|
#~ "Tim Peters (qui aurait souhaité que ce soit Steve Majewski) a suggéré la "
|
|
#~ "solution suivante: ``(a and [b] or [c])[0]``. Comme ``[b]`` est une liste "
|
|
#~ "d'un seul élément, il n'est jamais évalué à faux, le mauvais chemin n'est "
|
|
#~ "donc jamais prit, et appliquer ``[0]`` à l'ensemble vous donne le *b* ou "
|
|
#~ "*c* qque vous vouliez vraiment. Peu élégant, mais cela vous donne une "
|
|
#~ "solution pour les rares cas où il est vraiment peu pratique de réécrire "
|
|
#~ "le code sur une base de ``if``."
|
|
|
|
#~ msgid ""
|
|
#~ "The best course is usually to write a simple ``if...else`` statement. "
|
|
#~ "Another solution is to implement the ``?:`` operator as a function::"
|
|
#~ msgstr ""
|
|
#~ "La meilleure solution est souvent d'écrire un simple ``if…else``. Une "
|
|
#~ "autre solution est d'implémenter l'opérateur ``?:`` comme une fonction::"
|
|
|
|
#~ msgid ""
|
|
#~ "In most cases you'll pass b and c directly: ``q(a, b, c)``. To avoid "
|
|
#~ "evaluating b or c when they shouldn't be, encapsulate them within a "
|
|
#~ "lambda function, e.g.: ``q(a, lambda: b, lambda: c)``."
|
|
#~ msgstr ""
|
|
#~ "Dans la plupart des cas vous pourrez passer b et c directement: ``q(a,b,"
|
|
#~ "c)``. Pour éviter d'évaluer b et c quand il ne faut pas, encapsulez les "
|
|
#~ "dans une fonction lambda, exemple:``q(a, lambda: b, lambda: c)``."
|
|
|
|
#~ msgid ""
|
|
#~ "It has been asked *why* Python has no if-then-else expression. There are "
|
|
#~ "several answers: many languages do just fine without one; it can easily "
|
|
#~ "lead to less readable code; no sufficiently \"Pythonic\" syntax has been "
|
|
#~ "discovered; a search of the standard library found remarkably few places "
|
|
#~ "where using an if-then-else expression would make the code more "
|
|
#~ "understandable."
|
|
#~ msgstr ""
|
|
#~ "Il a souvent été demandé *pourquoi* Python n'avait pas d'expression if-"
|
|
#~ "the-else. Il y a plusieurs réponses à cette question: beaucoup de "
|
|
#~ "langages s'en sertent très bien sans en avoir une; elle peut aisément "
|
|
#~ "conduire à du code moins lisible; aucune syntaxe suffisamment \"Pythonique"
|
|
#~ "\" n'a été trouvée; une recherche dans la librairie standard à trouvé "
|
|
#~ "remarquablement peu d'endroit ou utiliser une expression if-then-else "
|
|
#~ "aurait rendu le code plus compréhensible."
|
|
|
|
#~ msgid ""
|
|
#~ "In 2002, :pep:`308` was written proposing several possible syntaxes and "
|
|
#~ "the community was asked to vote on the issue. The vote was "
|
|
#~ "inconclusive. Most people liked one of the syntaxes, but also hated "
|
|
#~ "other syntaxes; many votes implied that people preferred no ternary "
|
|
#~ "operator rather than having a syntax they hated."
|
|
#~ msgstr ""
|
|
#~ "En 2002, la :pep:`308` à été écrite, proposant plusieurs syntaxes et la "
|
|
#~ "communauté fut invité à voter. Le vote ne permit pas de tirer de "
|
|
#~ "conséquences. La plupart des gens aimaient une des syntaxes, mais "
|
|
#~ "détestaient les autres syntaxes; de nombreux votent exprimaient que les "
|
|
#~ "gens préféraient ne pas avoir d'opérateur ternaire que d'avoir une "
|
|
#~ "syntaxe qu'il détestent."
|
|
|
|
#~ msgid "if (x <= y) x++; y--; z++;"
|
|
#~ msgstr "if (x <= y) x++; y--; z++;"
|
|
|
|
#~ msgid ">>> 1.2 - 1.0 0.199999999999999996"
|
|
#~ msgstr ">>> 1.2 - 1.0 0.199999999999999996"
|
|
|
|
#~ msgid ">>> 1.1 - 0.9 0.20000000000000007 >>> print(1.1 - 0.9) 0.2"
|
|
#~ msgstr ">>> 1.1 - 0.9 0.20000000000000007 >>> print(1.1 - 0.9) 0.2"
|
|
|
|
#~ msgid "while (line = readline(f)) { // do something with line }"
|
|
#~ msgstr "while (line = readline(f)) { // faire quelque chose avec line }"
|
|
|
|
#~ msgid ""
|
|
#~ "while True: line = f.readline() if not line: "
|
|
#~ "break ... # do something with line"
|
|
#~ msgstr ""
|
|
#~ "while True: line = f.readline() if not line: break ... # faire quelque "
|
|
#~ "chose avec line"
|
|
|
|
#~ msgid ""
|
|
#~ "if (x = 0) { // error handling } else { // code that only works "
|
|
#~ "for nonzero x }"
|
|
#~ msgstr ""
|
|
#~ "if (x = 0) { // prise en charge de l'erreur } else { // code qui ne "
|
|
#~ "fonctionne que quand x est non-zéro }"
|
|
|
|
#~ msgid ""
|
|
#~ "line = f.readline() while line: ... # do something with line... "
|
|
#~ "line = f.readline()"
|
|
#~ msgstr ""
|
|
#~ "line = f.readline() while line: ... # faire quelque chose avec line... "
|
|
#~ "line = f.readline()"
|
|
|
|
#~ msgid "for line in f: ... # do something with line..."
|
|
#~ msgstr "for line in f: ... # faire quelque chose avec line..."
|
|
|
|
#~ msgid "\", \".join(['1', '2', '4', '8', '16'])"
|
|
#~ msgstr "\", \".join(['1', '2', '4', '8', '16'])"
|
|
|
|
#~ msgid "\"1, 2, 4, 8, 16\""
|
|
#~ msgstr "\"1, 2, 4, 8, 16\""
|
|
|
|
#~ msgid "\"1, 2, 4, 8, 16\".split(\", \")"
|
|
#~ msgstr "\"1, 2, 4, 8, 16\".split(\", \")"
|
|
|
|
#~ msgid ""
|
|
#~ "def linear(a, b): def result(x): return a * x + b return "
|
|
#~ "result"
|
|
#~ msgstr "def linear(a, b): def result(x): return a * x + b return result"
|
|
|
|
#~ msgid "newdict = olddict.copy()"
|
|
#~ msgstr "newdict = olddict.copy()"
|
|
|
|
#~ msgid "new_l = l[:]"
|
|
#~ msgstr "new_l = l[:]"
|
|
|
|
#~ msgid ">>> \"a\" in \"b\", \"a\" (False, 'a')"
|
|
#~ msgstr ">>> \"a\" in \"b\", \"a\" (False, 'a')"
|
|
|
|
#~ msgid ">>> (\"a\" in \"b\"), \"a\""
|
|
#~ msgstr ">>> (\"a\" in \"b\"), \"a\""
|
|
|
|
#~ msgid ">>> \"a\" in (\"b\", \"a\")"
|
|
#~ msgstr ">>> \"a\" in (\"b\", \"a\")"
|
|
|
|
#~ msgid ""
|
|
#~ "[on_true] if [expression] else [on_false] x, y = 50, 25 small = x if x "
|
|
#~ "< y else y"
|
|
#~ msgstr ""
|
|
#~ "[on_true] if [expression] else [on_false] x, y = 50, 25 small = x if x < "
|
|
#~ "y else y"
|
|
|
|
#~ msgid ""
|
|
#~ "def q(cond, on_true, on_false): if cond: if not "
|
|
#~ "isfunction(on_true): return on_true else: "
|
|
#~ "return on_true() else: if not "
|
|
#~ "isfunction(on_false): return on_false "
|
|
#~ "else: return on_false()"
|
|
#~ msgstr ""
|
|
#~ "def q(cond, on_true, on_false): if cond: if not "
|
|
#~ "isfunction(on_true): return on_true else: "
|
|
#~ "return on_true() else: if not isfunction(on_false): "
|
|
#~ "return on_false else: return on_false()"
|
|
|
|
#~ msgid ""
|
|
#~ "from functools import reduce # Primes < 1000 print(list(filter(None,"
|
|
#~ "map(lambda y:y*reduce(lambda x,y:x*y!=0, map(lambda x,y=y:y%x,range(2,"
|
|
#~ "int(pow(y,0.5)+1))),1),range(2,1000))))) # First 10 Fibonacci numbers "
|
|
#~ "print(list(map(lambda x,f=lambda x,f:(f(x-1,f)+f(x-2,f)) if x>1 else 1: "
|
|
#~ "f(x,f), range(10)))) # Mandelbrot set print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:"
|
|
#~ "reduce(lambda x,y:x+y,map(lambda y, Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,"
|
|
#~ "L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM, Sx=Sx,Sy=Sy:reduce(lambda x,y:x"
|
|
#~ "+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro, i=i,Sx=Sx,F=lambda xc,yc,x,y,k,"
|
|
#~ "f=lambda xc,yc,x,y,k,f:(k<=0)or (x*x+y*y >=4.0) or 1+f(xc,yc,x*x-y*y"
|
|
#~ "+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr( 64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,"
|
|
#~ "i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy ))))(-2.1, 0.7, -1.2, 1.2, "
|
|
#~ "30, 80, 24)) # \\___ ___/ \\___ ___/ | | |__ lines on screen "
|
|
#~ "# V V | |______ columns on screen # "
|
|
#~ "| | |__________ maximum of \"iterations\" # "
|
|
#~ "| |_________________ range on y axis # |"
|
|
#~ "____________________________ range on x axis"
|
|
#~ msgstr ""
|
|
#~ "from functools import reduce # Primes < 1000 print(list(filter(None,"
|
|
#~ "map(lambda y:y*reduce(lambda x,y:x*y!=0, map(lambda x,y=y:y%x,range(2,"
|
|
#~ "int(pow(y,0.5)+1))),1),range(2,1000))))) # First 10 Fibonacci numbers "
|
|
#~ "print(list(map(lambda x,f=lambda x,f:(f(x-1,f)+f(x-2,f)) if x>1 else 1: "
|
|
#~ "f(x,f), range(10)))) # Mandelbrot set print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:"
|
|
#~ "reduce(lambda x,y:x+y,map(lambda y, Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,"
|
|
#~ "L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM, Sx=Sx,Sy=Sy:reduce(lambda x,y:x"
|
|
#~ "+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro, i=i,Sx=Sx,F=lambda xc,yc,x,y,k,"
|
|
#~ "f=lambda xc,yc,x,y,k,f:(k<=0)or (x*x+y*y >=4.0) or 1+f(xc,yc,x*x-y*y"
|
|
#~ "+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr( 64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,"
|
|
#~ "i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy ))))(-2.1, 0.7, -1.2, 1.2, "
|
|
#~ "30, 80, 24)) # \\___ ___/ \\___ ___/ | | |__ lines on screen # V V | |"
|
|
#~ "______ columns on screen # | | |__________ maximum of \"iterations\" # | |"
|
|
#~ "_________________ range on y axis # |____________________________ range "
|
|
#~ "on x axis"
|
|
|
|
#~ msgid ">>> a = 0o10 >>> a 8"
|
|
#~ msgstr ">>> a = 0o10>>> a 8"
|
|
|
|
#~ msgid ">>> a = 0xa5 >>> a 165 >>> b = 0XB2 >>> b 178"
|
|
#~ msgstr ">>> a = 0xa5 >>> a 165 >>> b = 0XB2 >>> b 178"
|
|
|
|
#~ msgid "i == (i // j) * j + (i % j)"
|
|
#~ msgstr "i == (i // j) * j + (i % j)"
|
|
|
|
#~ msgid ""
|
|
#~ ">>> s = \"Hello, world\" >>> a = list(s) >>> print(a) ['H', 'e', 'l', "
|
|
#~ "'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'] >>> a[7:] = list(\"there!\") "
|
|
#~ ">>> ''.join(a) 'Hello, there!' >>> import array >>> a = array.array('u', "
|
|
#~ "s) >>> print(a) array('u', 'Hello, world') >>> a[0] = 'y' >>> print(a) "
|
|
#~ "array('u', 'yello world') >>> a.tounicode() 'yello, world'"
|
|
#~ msgstr ""
|
|
#~ ">>> s = \"Hello, world\" >>> a = list(s) >>> print(a) ['H', 'e', 'l', "
|
|
#~ "'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'] >>> a[7:] = list(\"there!\") "
|
|
#~ ">>> ''.join(a) 'Hello, there!' >>> import array >>> a = array.array('u', "
|
|
#~ "s) >>> print(a) array('u', 'Hello, world') >>> a[0] = 'y' >>> print(a) "
|
|
#~ "array('u', 'yello world') >>> a.tounicode() 'yello, world'"
|
|
|
|
#~ msgid ""
|
|
#~ "def a(): pass def b(): pass dispatch = {'go': a, 'stop': b} # "
|
|
#~ "Note lack of parens for funcs dispatch[get_input()]() # Note trailing "
|
|
#~ "parens to call function"
|
|
#~ msgstr ""
|
|
#~ "def a(): pass def b(): pass dispatch = {'go': a, 'stop': b} # Note lack "
|
|
#~ "of parens for funcs dispatch[get_input()]() # Note trailing parens to "
|
|
#~ "call function"
|
|
|
|
#~ msgid "import foo getattr(foo, 'bar')()"
|
|
#~ msgstr "import foo getattr(foo, 'bar')()"
|
|
|
|
#~ msgid ""
|
|
#~ "class Foo: def do_foo(self): ... def "
|
|
#~ "do_bar(self): ... f = getattr(foo_instance, 'do_' + opname) f()"
|
|
#~ msgstr ""
|
|
#~ "class Foo: def do_foo(self): ... def do_bar(self): ... f = "
|
|
#~ "getattr(foo_instance, 'do_' + opname) f()"
|
|
|
|
#~ msgid ""
|
|
#~ "def myFunc(): print(\"hello\") fname = \"myFunc\" f = locals()"
|
|
#~ "[fname] f() f = eval(fname) f()"
|
|
#~ msgstr ""
|
|
#~ "def myFunc(): print(\"hello\") fname = \"myFunc\" f = locals()[fname] f() "
|
|
#~ "f = eval(fname) f()"
|
|
|
|
#~ msgid ""
|
|
#~ ">>> lines = (\"line 1 \\r\\n\" ... \"\\r\\n\" ... \"\\r"
|
|
#~ "\\n\") >>> lines.rstrip(\"\\n\\r\") 'line 1 '"
|
|
#~ msgstr ""
|
|
#~ ">>> lines = (\"line 1 \r\n"
|
|
#~ "\" ... \"\r\n"
|
|
#~ "\" ... \"\r\n"
|
|
#~ "\") >>> lines.rstrip(\"\n"
|
|
#~ "\r\") 'line 1 '"
|
|
|
|
# traduire la référence?
|
|
#, fuzzy
|
|
#~ msgid "See the :ref:`unicode-howto`."
|
|
#~ msgstr "Regardez le :ref:`unicode-howto`."
|
|
|
|
#~ msgid "for x in reversed(sequence): ... # do something with x..."
|
|
#~ msgstr "for x in reversed(sequence): ... # do something with x..."
|
|
|
|
#~ msgid "for x in sequence[::-1]: ... # do something with x..."
|
|
#~ msgstr "for x in sequence[::-1]: ... # do something with x..."
|
|
|
|
#~ msgid ""
|
|
#~ "if mylist: mylist.sort() last = mylist[-1] for i in "
|
|
#~ "range(len(mylist)-2, -1, -1): if last == mylist[i]: "
|
|
#~ "del mylist[i] else: last = mylist[i]"
|
|
#~ msgstr ""
|
|
#~ "if mylist: mylist.sort() last = mylist[-1] for i in "
|
|
#~ "range(len(mylist)-2, -1, -1): if last == mylist[i]: "
|
|
#~ "del mylist[i] else: last = mylist[i]"
|
|
|
|
#~ msgid "d = {} for x in mylist: d[x] = 1 mylist = list(d.keys())"
|
|
#~ msgstr "d = {} for x in mylist: d[x] = 1 mylist = list(d.keys())"
|
|
|
|
#~ msgid "mylist = list(set(mylist))"
|
|
#~ msgstr "mylist = list(set(mylist))"
|
|
|
|
#~ msgid "[\"this\", 1, \"is\", \"an\", \"array\"]"
|
|
#~ msgstr "[\"ceci\", 1, \"est\", \"un\", \"tableau\"]"
|
|
|
|
#~ msgid "lisp_list = (\"like\", (\"this\", (\"example\", None) ) )"
|
|
#~ msgstr "lisp_list = (\"like\", (\"this\", (\"example\", None) ) )"
|
|
|
|
#~ msgid "A = [[None] * 2] * 3"
|
|
#~ msgstr "A = [[None] * 2] * 3"
|
|
|
|
#~ msgid ">>> A [[None, None], [None, None], [None, None]]"
|
|
#~ msgstr ">>> A [[None, None], [None, None], [None, None]]"
|
|
|
|
#~ msgid ">>> A[0][0] = 5 >>> A [[5, None], [5, None], [5, None]]"
|
|
#~ msgstr ">>> A[0][0] = 5 >>> A [[5, None], [5, None], [5, None]]"
|
|
|
|
#~ msgid "A = [None] * 3 for i in range(3): A[i] = [None] * 2"
|
|
#~ msgstr "A = [None] * 3 for i in range(3): A[i] = [None] * 2"
|
|
|
|
#~ msgid "w, h = 2, 3 A = [[None] * w for i in range(h)]"
|
|
#~ msgstr "w, h = 2, 3 A = [[None] * w for i in range(h)]"
|
|
|
|
#~ msgid "result = [obj.method() for obj in mylist]"
|
|
#~ msgstr "result = [obj.method() for obj in mylist]"
|
|
|
|
#~ msgid ""
|
|
#~ "class SortedDict(dict): def __repr__(self): keys = "
|
|
#~ "sorted(self.keys()) result = (\"{!r}: {!r}\".format(k, self[k]) "
|
|
#~ "for k in keys) return \"{{{}}}\".format(\", \".join(result)) "
|
|
#~ "__str__ = __repr__"
|
|
#~ msgstr ""
|
|
#~ "class SortedDict(dict): def __repr__(self): keys = "
|
|
#~ "sorted(self.keys()) result = (\"{!r}: {!r}\".format(k, self[k]) "
|
|
#~ "for k in keys) return \"{{{}}}\".format(\", \".join(result)) "
|
|
#~ "__str__ = __repr__"
|
|
|
|
#~ msgid "Isorted = L[:] Isorted.sort(key=lambda s: int(s[10:15]))"
|
|
#~ msgstr "Isorted = L[:] Isorted.sort(key=lambda s: int(s[10:15]))"
|
|
|
|
#~ msgid ""
|
|
#~ "tmp1 = [(x.upper(), x) for x in L] # Schwartzian transform tmp1.sort() "
|
|
#~ "Usorted = [x[1] for x in tmp1]"
|
|
#~ msgstr ""
|
|
#~ "tmp1 = [(x.upper(), x) for x in L] # Schwartzian transform tmp1.sort() "
|
|
#~ "Usorted = [x[1] for x in tmp1]"
|
|
|
|
#~ msgid ""
|
|
#~ "tmp2 = [(int(s[10:15]), s) for s in L] # Schwartzian transform tmp2."
|
|
#~ "sort() Isorted = [x[1] for x in tmp2]"
|
|
#~ msgstr ""
|
|
#~ "tmp2 = [(int(s[10:15]), s) for s in L] # Schwartzian transform tmp2."
|
|
#~ "sort() Isorted = [x[1] for x in tmp2]"
|
|
|
|
#~ msgid ""
|
|
#~ "def intfield(s): return int(s[10:15]) def Icmp(s1, s2): return "
|
|
#~ "cmp(intfield(s1), intfield(s2)) Isorted = L[:] Isorted.sort(Icmp)"
|
|
#~ msgstr ""
|
|
#~ "def intfield(s): return int(s[10:15]) def Icmp(s1, s2): return "
|
|
#~ "cmp(intfield(s1), intfield(s2)) Isorted = L[:] Isorted.sort(Icmp)"
|
|
|
|
#~ msgid ""
|
|
#~ ">>> list1 = [\"what\", \"I'm\", \"sorting\", \"by\"] >>> list2 = "
|
|
#~ "[\"something\", \"else\", \"to\", \"sort\"] >>> pairs = zip(list1, list2) "
|
|
#~ ">>> pairs = sorted(pairs) >>> pairs [(\"I'm\", 'else'), ('by', 'sort'), "
|
|
#~ "('sorting', 'to'), ('what', 'something')] >>> result = [x[1] for x in "
|
|
#~ "pairs] >>> result ['else', 'sort', 'to', 'something']"
|
|
#~ msgstr ""
|
|
#~ ">>> list1 = [\"what\", \"I'm\", \"sorting\", \"by\"] >>> list2 = "
|
|
#~ "[\"something\", \"else\", \"to\", \"sort\"] >>> pairs = zip(list1, list2) "
|
|
#~ ">>> pairs = sorted(pairs) >>> pairs [(\"I'm\", 'else'), ('by', 'sort'), "
|
|
#~ "('sorting', 'to'), ('what', 'something')] >>> result = [x[1] for x in "
|
|
#~ "pairs] >>> result ['else', 'sort', 'to', 'something']"
|
|
|
|
#~ msgid ">>> result = [] >>> for p in pairs: result.append(p[1])"
|
|
#~ msgstr ">>> result = [] >>> for p in pairs: result.append(p[1])"
|
|
|
|
#~ msgid ""
|
|
#~ "class C: def meth (self, arg): return arg * 2 + self.attribute"
|
|
#~ msgstr ""
|
|
#~ "class C: def meth (self, arg): return arg * 2 + self.attribute"
|
|
|
|
#~ msgid ""
|
|
#~ "def search(obj): if isinstance(obj, Mailbox): # ... code to "
|
|
#~ "search a mailbox elif isinstance(obj, Document): # ... code "
|
|
#~ "to search a document elif ..."
|
|
#~ msgstr ""
|
|
#~ "def search(obj): if isinstance(obj, Mailbox): # ... code to "
|
|
#~ "search a mailbox elif isinstance(obj, Document): # ... code "
|
|
#~ "to search a document elif ..."
|
|
|
|
#~ msgid ""
|
|
#~ "class Mailbox: def search(self): # ... code to search a "
|
|
#~ "mailbox class Document: def search(self): # ... code to "
|
|
#~ "search a document obj.search()"
|
|
#~ msgstr ""
|
|
#~ "class Mailbox: def search(self): # ... code to search a "
|
|
#~ "mailbox class Document: def search(self): # ... code to "
|
|
#~ "search a document obj.search()"
|
|
|
|
#~ msgid ""
|
|
#~ "class UpperOut: def __init__(self, outfile): self._outfile = "
|
|
#~ "outfile def write(self, s): self._outfile.write(s."
|
|
#~ "upper()) def __getattr__(self, name): return getattr(self."
|
|
#~ "_outfile, name)"
|
|
#~ msgstr ""
|
|
#~ "class UpperOut: def __init__(self, outfile): self._outfile = "
|
|
#~ "outfile def write(self, s): self._outfile.write(s."
|
|
#~ "upper()) def __getattr__(self, name): return getattr(self."
|
|
#~ "_outfile, name)"
|
|
|
|
#~ msgid ""
|
|
#~ "class X: ... def __setattr__(self, name, value): self."
|
|
#~ "__dict__[name] = value ..."
|
|
#~ msgstr ""
|
|
#~ "class X: ... def __setattr__(self, name, value): self."
|
|
#~ "__dict__[name] = value ..."
|
|
|
|
#~ msgid ""
|
|
#~ "class Derived(Base): def meth (self): super(Derived, self)."
|
|
#~ "meth()"
|
|
#~ msgstr ""
|
|
#~ "class Derived(Base): def meth (self): super(Derived, self)."
|
|
#~ "meth()"
|
|
|
|
#~ msgid ""
|
|
#~ "BaseAlias = <real base class> class Derived(BaseAlias): def "
|
|
#~ "meth(self): BaseAlias.meth(self) ..."
|
|
#~ msgstr ""
|
|
#~ "BaseAlias = <real base class> class Derived(BaseAlias): def "
|
|
#~ "meth(self): BaseAlias.meth(self) ..."
|
|
|
|
#~ msgid ""
|
|
#~ "class C: count = 0 # number of times C.__init__ called def "
|
|
#~ "__init__(self): C.count = C.count + 1 def "
|
|
#~ "getcount(self): return C.count # or return self.count"
|
|
#~ msgstr ""
|
|
#~ "class C: count = 0 # number of times C.__init__ called def "
|
|
#~ "__init__(self): C.count = C.count + 1 def "
|
|
#~ "getcount(self): return C.count # or return self.count"
|
|
|
|
#~ msgid "C.count = 314"
|
|
#~ msgstr "C.count = 314"
|
|
|
|
#~ msgid ""
|
|
#~ "class C: def static(arg1, arg2, arg3): # No 'self' "
|
|
#~ "parameter! ... static = staticmethod(static)"
|
|
#~ msgstr ""
|
|
#~ "class C: def static(arg1, arg2, arg3): # No 'self' "
|
|
#~ "parameter! ... static = staticmethod(static)"
|
|
|
|
#~ msgid ""
|
|
#~ "class C: @staticmethod def static(arg1, arg2, arg3): # No "
|
|
#~ "'self' parameter! ..."
|
|
#~ msgstr ""
|
|
#~ "class C: @staticmethod def static(arg1, arg2, arg3): # No "
|
|
#~ "'self' parameter! ..."
|
|
|
|
#~ msgid "def getcount(): return C.count"
|
|
#~ msgstr "def getcount(): return C.count"
|
|
|
|
#~ msgid ""
|
|
#~ "class C { C() { cout << \"No arguments\\n\"; } C(int i) { cout << "
|
|
#~ "\"Argument is \" << i << \"\\n\"; } }"
|
|
#~ msgstr ""
|
|
#~ "class C { C() { cout << \"No arguments\\n\"; } C(int i) { cout << "
|
|
#~ "\"Argument is \" << i << \"\\n\"; } }"
|
|
|
|
#~ msgid ""
|
|
#~ "class C: def __init__(self, i=None): if i is "
|
|
#~ "None: print(\"No arguments\") else: "
|
|
#~ "print(\"Argument is\", i)"
|
|
#~ msgstr ""
|
|
#~ "class C: def __init__(self, i=None): if i is "
|
|
#~ "None: print(\"No arguments\") else: "
|
|
#~ "print(\"Argument is\", i)"
|
|
|
|
#~ msgid "def __init__(self, *args): ..."
|
|
#~ msgstr "def __init__(self, *args): ..."
|