From c75925b0aa009f7e421a5a5e2590980e3b9ba2da Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 12 Oct 2021 19:09:13 +0000 Subject: [PATCH 1/6] sync with cpython 6d4d4ec5 --- library/hashlib.po | 7 ++--- library/html.entities.po | 6 ++-- library/http.cookiejar.po | 4 +-- library/ipaddress.po | 4 +-- library/json.po | 24 ++++++++-------- library/xml.dom.minidom.po | 59 +++++++++++++++++++++----------------- 6 files changed, 55 insertions(+), 49 deletions(-) diff --git a/library/hashlib.po b/library/hashlib.po index 64c7992fd6..a2e3953533 100644 --- a/library/hashlib.po +++ b/library/hashlib.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.7\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-09-29 00:11+0000\n" +"POT-Creation-Date: 2021-10-12 19:07+0000\n" "PO-Revision-Date: 2018-05-23 16:03+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -584,9 +584,8 @@ msgstr "" msgid "" "Keyed hashing can be used for authentication as a faster and simpler " "replacement for `Hash-based message authentication code `_ (HMAC). BLAKE2 " -"can be securely used in prefix-MAC mode thanks to the indifferentiability " -"property inherited from BLAKE." +"wikipedia.org/wiki/HMAC>`_ (HMAC). BLAKE2 can be securely used in prefix-MAC " +"mode thanks to the indifferentiability property inherited from BLAKE." msgstr "" #: ../../library/hashlib.rst:503 diff --git a/library/html.entities.po b/library/html.entities.po index 34c87914a8..75117c4560 100644 --- a/library/html.entities.po +++ b/library/html.entities.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.7\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-06-26 18:54+0800\n" +"POT-Creation-Date: 2021-10-12 19:07+0000\n" "PO-Revision-Date: 2017-09-22 18:26+0000\n" "Last-Translator: Liang-Bo Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -61,5 +61,7 @@ msgid "Footnotes" msgstr "註解" #: ../../library/html.entities.rst:47 -msgid "See https://www.w3.org/TR/html5/syntax.html#named-character-references" +msgid "" +"See https://html.spec.whatwg.org/multipage/syntax.html#named-character-" +"references" msgstr "" diff --git a/library/http.cookiejar.po b/library/http.cookiejar.po index 1005383785..2759989ccb 100644 --- a/library/http.cookiejar.po +++ b/library/http.cookiejar.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.7\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-06-20 18:08+0800\n" +"POT-Creation-Date: 2021-10-12 19:07+0000\n" "PO-Revision-Date: 2016-11-19 00:31+0000\n" "Last-Translator: Liang-Bo Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -165,7 +165,7 @@ msgid "" msgstr "" #: ../../library/http.cookiejar.rst:129 -msgid "https://curl.haxx.se/rfc/cookie_spec.html" +msgid "https://curl.se/rfc/cookie_spec.html" msgstr "" #: ../../library/http.cookiejar.rst:126 diff --git a/library/ipaddress.po b/library/ipaddress.po index 735c7bb159..fb3c3c2626 100644 --- a/library/ipaddress.po +++ b/library/ipaddress.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.7\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-09-29 00:11+0000\n" +"POT-Creation-Date: 2021-10-12 19:07+0000\n" "PO-Revision-Date: 2018-05-23 16:04+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -674,7 +674,7 @@ msgstr "" #: ../../library/ipaddress.rst:683 msgid "" "Note that currently expanded netmasks are not supported. That means ``2001:" -"db00::0/24`` is a valid argument while ``2001:db00::0/ffff:ff00::`` not." +"db00::0/24`` is a valid argument while ``2001:db00::0/ffff:ff00::`` is not." msgstr "" #: ../../library/ipaddress.rst:687 diff --git a/library/json.po b/library/json.po index 4274c24a9a..a169910e09 100644 --- a/library/json.po +++ b/library/json.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.7\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-09-13 00:11+0000\n" +"POT-Creation-Date: 2021-10-12 19:07+0000\n" "PO-Revision-Date: 2018-05-23 16:04+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -29,12 +29,12 @@ msgstr "" #: ../../library/json.rst:14 msgid "" -"`JSON (JavaScript Object Notation) `_, specified by :rfc:" -"`7159` (which obsoletes :rfc:`4627`) and by `ECMA-404 `_, is a lightweight " -"data interchange format inspired by `JavaScript `_ object literal syntax (although it is not a strict subset " -"of JavaScript [#rfc-errata]_ )." +"`JSON (JavaScript Object Notation) `_, specified by :rfc:" +"`7159` (which obsoletes :rfc:`4627`) and by `ECMA-404 `_, is a " +"lightweight data interchange format inspired by `JavaScript `_ object literal syntax (although it is not a " +"strict subset of JavaScript [#rfc-errata]_ )." msgstr "" #: ../../library/json.rst:21 @@ -582,11 +582,11 @@ msgstr "" #: ../../library/json.rst:546 msgid "" -"The JSON format is specified by :rfc:`7159` and by `ECMA-404 `_. This section " -"details this module's level of compliance with the RFC. For simplicity, :" -"class:`JSONEncoder` and :class:`JSONDecoder` subclasses, and parameters " -"other than those explicitly mentioned, are not considered." +"The JSON format is specified by :rfc:`7159` and by `ECMA-404 `_. " +"This section details this module's level of compliance with the RFC. For " +"simplicity, :class:`JSONEncoder` and :class:`JSONDecoder` subclasses, and " +"parameters other than those explicitly mentioned, are not considered." msgstr "" #: ../../library/json.rst:552 diff --git a/library/xml.dom.minidom.po b/library/xml.dom.minidom.po index 4414f64cf9..83b9ba5781 100644 --- a/library/xml.dom.minidom.po +++ b/library/xml.dom.minidom.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.7\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-09-13 00:11+0000\n" +"POT-Creation-Date: 2021-10-12 19:07+0000\n" "PO-Revision-Date: 2018-05-23 16:15+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -189,13 +189,18 @@ msgid "" "the user." msgstr "" -#: ../../library/xml.dom.minidom.rst:161 +#: ../../library/xml.dom.minidom.rst:159 ../../library/xml.dom.minidom.rst:180 +#: ../../library/xml.dom.minidom.rst:199 +msgid "The *standalone* parameter was added." +msgstr "" + +#: ../../library/xml.dom.minidom.rst:164 msgid "" "Return a string or byte string containing the XML represented by the DOM " "node." msgstr "" -#: ../../library/xml.dom.minidom.rst:164 +#: ../../library/xml.dom.minidom.rst:167 msgid "" "With an explicit *encoding* [1]_ argument, the result is a byte string in " "the specified encoding. With no *encoding* argument, the result is a Unicode " @@ -204,63 +209,63 @@ msgid "" "incorrect, since UTF-8 is the default encoding of XML." msgstr "" -#: ../../library/xml.dom.minidom.rst:171 ../../library/xml.dom.minidom.rst:187 +#: ../../library/xml.dom.minidom.rst:174 ../../library/xml.dom.minidom.rst:193 msgid "The *standalone* argument behaves exactly as in :meth:`writexml`." msgstr "" -#: ../../library/xml.dom.minidom.rst:173 +#: ../../library/xml.dom.minidom.rst:176 msgid "" "The :meth:`toxml` method now preserves the attribute order specified by the " "user." msgstr "" -#: ../../library/xml.dom.minidom.rst:180 +#: ../../library/xml.dom.minidom.rst:186 msgid "" "Return a pretty-printed version of the document. *indent* specifies the " "indentation string and defaults to a tabulator; *newl* specifies the string " "emitted at the end of each line and defaults to ``\\n``." msgstr "" -#: ../../library/xml.dom.minidom.rst:184 +#: ../../library/xml.dom.minidom.rst:190 msgid "" "The *encoding* argument behaves like the corresponding argument of :meth:" "`toxml`." msgstr "" -#: ../../library/xml.dom.minidom.rst:189 +#: ../../library/xml.dom.minidom.rst:195 msgid "" "The :meth:`toprettyxml` method now preserves the attribute order specified " "by the user." msgstr "" -#: ../../library/xml.dom.minidom.rst:197 +#: ../../library/xml.dom.minidom.rst:205 msgid "DOM Example" msgstr "" -#: ../../library/xml.dom.minidom.rst:199 +#: ../../library/xml.dom.minidom.rst:207 msgid "" "This example program is a fairly realistic example of a simple program. In " "this particular case, we do not take much advantage of the flexibility of " "the DOM." msgstr "" -#: ../../library/xml.dom.minidom.rst:208 +#: ../../library/xml.dom.minidom.rst:216 msgid "minidom and the DOM standard" msgstr "" -#: ../../library/xml.dom.minidom.rst:210 +#: ../../library/xml.dom.minidom.rst:218 msgid "" "The :mod:`xml.dom.minidom` module is essentially a DOM 1.0-compatible DOM " "with some DOM 2 features (primarily namespace features)." msgstr "" -#: ../../library/xml.dom.minidom.rst:213 +#: ../../library/xml.dom.minidom.rst:221 msgid "" "Usage of the DOM interface in Python is straight-forward. The following " "mapping rules apply:" msgstr "" -#: ../../library/xml.dom.minidom.rst:216 +#: ../../library/xml.dom.minidom.rst:224 msgid "" "Interfaces are accessed through instance objects. Applications should not " "instantiate the classes themselves; they should use the creator functions " @@ -269,14 +274,14 @@ msgid "" "operations." msgstr "" -#: ../../library/xml.dom.minidom.rst:221 +#: ../../library/xml.dom.minidom.rst:229 msgid "" "Operations are used as methods. Since the DOM uses only :keyword:`in` " "parameters, the arguments are passed in normal order (from left to right). " "There are no optional arguments. ``void`` operations return ``None``." msgstr "" -#: ../../library/xml.dom.minidom.rst:225 +#: ../../library/xml.dom.minidom.rst:233 msgid "" "IDL attributes map to instance attributes. For compatibility with the OMG " "IDL language mapping for Python, an attribute ``foo`` can also be accessed " @@ -284,13 +289,13 @@ msgid "" "``readonly`` attributes must not be changed; this is not enforced at runtime." msgstr "" -#: ../../library/xml.dom.minidom.rst:230 +#: ../../library/xml.dom.minidom.rst:238 msgid "" "The types ``short int``, ``unsigned int``, ``unsigned long long``, and " "``boolean`` all map to Python integer objects." msgstr "" -#: ../../library/xml.dom.minidom.rst:233 +#: ../../library/xml.dom.minidom.rst:241 msgid "" "The type ``DOMString`` maps to Python strings. :mod:`xml.dom.minidom` " "supports either bytes or strings, but will normally produce strings. Values " @@ -298,21 +303,21 @@ msgid "" "``null`` value by the DOM specification from the W3C." msgstr "" -#: ../../library/xml.dom.minidom.rst:238 +#: ../../library/xml.dom.minidom.rst:246 msgid "" "``const`` declarations map to variables in their respective scope (e.g. " "``xml.dom.minidom.Node.PROCESSING_INSTRUCTION_NODE``); they must not be " "changed." msgstr "" -#: ../../library/xml.dom.minidom.rst:241 +#: ../../library/xml.dom.minidom.rst:249 msgid "" "``DOMException`` is currently not supported in :mod:`xml.dom.minidom`. " "Instead, :mod:`xml.dom.minidom` uses standard Python exceptions such as :exc:" "`TypeError` and :exc:`AttributeError`." msgstr "" -#: ../../library/xml.dom.minidom.rst:245 +#: ../../library/xml.dom.minidom.rst:253 msgid "" ":class:`NodeList` objects are implemented using Python's built-in list type. " "These objects provide the interface defined in the DOM specification, but " @@ -321,30 +326,30 @@ msgid "" "recommendations." msgstr "" -#: ../../library/xml.dom.minidom.rst:251 +#: ../../library/xml.dom.minidom.rst:259 msgid "" "The following interfaces have no implementation in :mod:`xml.dom.minidom`:" msgstr "" -#: ../../library/xml.dom.minidom.rst:253 +#: ../../library/xml.dom.minidom.rst:261 msgid ":class:`DOMTimeStamp`" msgstr "" -#: ../../library/xml.dom.minidom.rst:255 +#: ../../library/xml.dom.minidom.rst:263 msgid ":class:`EntityReference`" msgstr "" -#: ../../library/xml.dom.minidom.rst:257 +#: ../../library/xml.dom.minidom.rst:265 msgid "" "Most of these reflect information in the XML document that is not of general " "utility to most DOM users." msgstr "" -#: ../../library/xml.dom.minidom.rst:261 +#: ../../library/xml.dom.minidom.rst:269 msgid "Footnotes" msgstr "註解" -#: ../../library/xml.dom.minidom.rst:262 +#: ../../library/xml.dom.minidom.rst:270 msgid "" "The encoding name included in the XML output should conform to the " "appropriate standards. For example, \"UTF-8\" is valid, but \"UTF8\" is not " From f3fea4fec1f0bc6fbad171dc934ae6757e6fb122 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 13 Oct 2021 20:23:00 +0000 Subject: [PATCH 2/6] sync with cpython 9210eff6 --- faq/programming.po | 446 +++++++++++++++++++++++---------------------- 1 file changed, 231 insertions(+), 215 deletions(-) diff --git a/faq/programming.po b/faq/programming.po index 6a63b9dba6..16a9b3d023 100644 --- a/faq/programming.po +++ b/faq/programming.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.7\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-07 00:10+0000\n" +"POT-Creation-Date: 2021-10-13 20:21+0000\n" "PO-Revision-Date: 2018-05-23 14:35+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -937,17 +937,33 @@ msgid "" msgstr "" #: ../../faq/programming.rst:840 -msgid "How do I convert a string to a number?" +msgid "How do I get int literal attribute instead of SyntaxError?" msgstr "" #: ../../faq/programming.rst:842 msgid "" +"Trying to lookup an ``int`` literal attribute in the normal manner gives a " +"syntax error because the period is seen as a decimal point::" +msgstr "" + +#: ../../faq/programming.rst:851 +msgid "" +"The solution is to separate the literal from the period with either a space " +"or parentheses." +msgstr "" + +#: ../../faq/programming.rst:861 +msgid "How do I convert a string to a number?" +msgstr "" + +#: ../../faq/programming.rst:863 +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 "" -#: ../../faq/programming.rst:846 +#: ../../faq/programming.rst:867 msgid "" "By default, these interpret the number as decimal, so that ``int('0144') == " "144`` holds true, and ``int('0x144')`` raises :exc:`ValueError`. " @@ -957,7 +973,7 @@ msgid "" "octal, and '0x' indicates a hex number." msgstr "" -#: ../../faq/programming.rst:853 +#: ../../faq/programming.rst:874 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 " @@ -967,18 +983,18 @@ msgid "" "directory." msgstr "" -#: ../../faq/programming.rst:860 +#: ../../faq/programming.rst:881 msgid "" ":func:`eval` also has the effect of interpreting numbers as Python " "expressions, so that e.g. ``eval('09')`` gives a syntax error because Python " "does not allow leading '0' in a decimal number (except '0')." msgstr "" -#: ../../faq/programming.rst:866 +#: ../../faq/programming.rst:887 msgid "How do I convert a number to a string?" msgstr "" -#: ../../faq/programming.rst:868 +#: ../../faq/programming.rst:889 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, " @@ -988,11 +1004,11 @@ msgid "" "format(1.0/3.0)`` yields ``'0.333'``." msgstr "" -#: ../../faq/programming.rst:877 +#: ../../faq/programming.rst:898 msgid "How do I modify a string in place?" msgstr "" -#: ../../faq/programming.rst:879 +#: ../../faq/programming.rst:900 msgid "" "You can't, because strings are immutable. In most situations, you should " "simply construct a new string from the various parts you want to assemble it " @@ -1001,15 +1017,15 @@ msgid "" "module::" msgstr "" -#: ../../faq/programming.rst:909 +#: ../../faq/programming.rst:930 msgid "How do I use strings to call functions/methods?" msgstr "" -#: ../../faq/programming.rst:911 +#: ../../faq/programming.rst:932 msgid "There are various techniques." msgstr "" -#: ../../faq/programming.rst:913 +#: ../../faq/programming.rst:934 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 " @@ -1017,31 +1033,31 @@ msgid "" "a case construct::" msgstr "" -#: ../../faq/programming.rst:928 +#: ../../faq/programming.rst:949 msgid "Use the built-in function :func:`getattr`::" msgstr "" -#: ../../faq/programming.rst:933 +#: ../../faq/programming.rst:954 msgid "" "Note that :func:`getattr` works on any object, including classes, class " "instances, modules, and so on." msgstr "" -#: ../../faq/programming.rst:936 +#: ../../faq/programming.rst:957 msgid "This is used in several places in the standard library, like this::" msgstr "" -#: ../../faq/programming.rst:949 +#: ../../faq/programming.rst:970 msgid "Use :func:`locals` to resolve the function name::" msgstr "" -#: ../../faq/programming.rst:961 +#: ../../faq/programming.rst:982 msgid "" "Is there an equivalent to Perl's chomp() for removing trailing newlines from " "strings?" msgstr "" -#: ../../faq/programming.rst:963 +#: ../../faq/programming.rst:984 msgid "" "You can use ``S.rstrip(\"\\r\\n\")`` to remove all occurrences of any line " "terminator from the end of the string ``S`` without removing other trailing " @@ -1050,21 +1066,21 @@ msgid "" "removed::" msgstr "" -#: ../../faq/programming.rst:975 +#: ../../faq/programming.rst:996 msgid "" "Since this is typically only desired when reading text one line at a time, " "using ``S.rstrip()`` this way works well." msgstr "" -#: ../../faq/programming.rst:980 +#: ../../faq/programming.rst:1001 msgid "Is there a scanf() or sscanf() equivalent?" msgstr "" -#: ../../faq/programming.rst:982 +#: ../../faq/programming.rst:1003 msgid "Not as such." msgstr "" -#: ../../faq/programming.rst:984 +#: ../../faq/programming.rst:1005 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 " @@ -1074,86 +1090,86 @@ msgid "" "as a separator." msgstr "" -#: ../../faq/programming.rst:990 +#: ../../faq/programming.rst:1011 msgid "" "For more complicated input parsing, regular expressions are more powerful " "than C's :c:func:`sscanf` and better suited for the task." msgstr "" -#: ../../faq/programming.rst:995 +#: ../../faq/programming.rst:1016 msgid "What does 'UnicodeDecodeError' or 'UnicodeEncodeError' error mean?" msgstr "" -#: ../../faq/programming.rst:997 +#: ../../faq/programming.rst:1018 msgid "See the :ref:`unicode-howto`." msgstr "" -#: ../../faq/programming.rst:1001 +#: ../../faq/programming.rst:1022 msgid "Performance" msgstr "" -#: ../../faq/programming.rst:1004 +#: ../../faq/programming.rst:1025 msgid "My program is too slow. How do I speed it up?" msgstr "" -#: ../../faq/programming.rst:1006 +#: ../../faq/programming.rst:1027 msgid "" "That's a tough one, in general. First, here are a list of things to " "remember before diving further:" msgstr "" -#: ../../faq/programming.rst:1009 +#: ../../faq/programming.rst:1030 msgid "" "Performance characteristics vary across Python implementations. This FAQ " "focuses on :term:`CPython`." msgstr "" -#: ../../faq/programming.rst:1011 +#: ../../faq/programming.rst:1032 msgid "" "Behaviour can vary across operating systems, especially when talking about I/" "O or multi-threading." msgstr "" -#: ../../faq/programming.rst:1013 +#: ../../faq/programming.rst:1034 msgid "" "You should always find the hot spots in your program *before* attempting to " "optimize any code (see the :mod:`profile` module)." msgstr "" -#: ../../faq/programming.rst:1015 +#: ../../faq/programming.rst:1036 msgid "" "Writing benchmark scripts will allow you to iterate quickly when searching " "for improvements (see the :mod:`timeit` module)." msgstr "" -#: ../../faq/programming.rst:1017 +#: ../../faq/programming.rst:1038 msgid "" "It is highly recommended to have good code coverage (through unit testing or " "any other technique) before potentially introducing regressions hidden in " "sophisticated optimizations." msgstr "" -#: ../../faq/programming.rst:1021 +#: ../../faq/programming.rst:1042 msgid "" "That being said, there are many tricks to speed up Python code. Here are " "some general principles which go a long way towards reaching acceptable " "performance levels:" msgstr "" -#: ../../faq/programming.rst:1025 +#: ../../faq/programming.rst:1046 msgid "" "Making your algorithms faster (or changing to faster ones) can yield much " "larger benefits than trying to sprinkle micro-optimization tricks all over " "your code." msgstr "" -#: ../../faq/programming.rst:1029 +#: ../../faq/programming.rst:1050 msgid "" "Use the right data structures. Study documentation for the :ref:`bltin-" "types` and the :mod:`collections` module." msgstr "" -#: ../../faq/programming.rst:1032 +#: ../../faq/programming.rst:1053 msgid "" "When the standard library provides a primitive for doing something, it is " "likely (although not guaranteed) to be faster than any alternative you may " @@ -1164,7 +1180,7 @@ msgid "" "advanced usage)." msgstr "" -#: ../../faq/programming.rst:1040 +#: ../../faq/programming.rst:1061 msgid "" "Abstractions tend to create indirections and force the interpreter to work " "more. If the levels of indirection outweigh the amount of useful work done, " @@ -1173,7 +1189,7 @@ msgid "" "detrimental to readability)." msgstr "" -#: ../../faq/programming.rst:1046 +#: ../../faq/programming.rst:1067 msgid "" "If you have reached the limit of what pure Python can allow, there are tools " "to take you further away. For example, `Cython `_ can " @@ -1185,17 +1201,17 @@ msgid "" "yourself." msgstr "" -#: ../../faq/programming.rst:1056 +#: ../../faq/programming.rst:1077 msgid "" "The wiki page devoted to `performance tips `_." msgstr "" -#: ../../faq/programming.rst:1062 +#: ../../faq/programming.rst:1083 msgid "What is the most efficient way to concatenate many strings together?" msgstr "" -#: ../../faq/programming.rst:1064 +#: ../../faq/programming.rst:1085 msgid "" ":class:`str` and :class:`bytes` objects are immutable, therefore " "concatenating many strings together is inefficient as each concatenation " @@ -1203,38 +1219,38 @@ msgid "" "quadratic in the total string length." msgstr "" -#: ../../faq/programming.rst:1069 +#: ../../faq/programming.rst:1090 msgid "" "To accumulate many :class:`str` objects, the recommended idiom is to place " "them into a list and call :meth:`str.join` at the end::" msgstr "" -#: ../../faq/programming.rst:1077 +#: ../../faq/programming.rst:1098 msgid "(another reasonably efficient idiom is to use :class:`io.StringIO`)" msgstr "" -#: ../../faq/programming.rst:1079 +#: ../../faq/programming.rst:1100 msgid "" "To accumulate many :class:`bytes` objects, the recommended idiom is to " "extend a :class:`bytearray` object using in-place concatenation (the ``+=`` " "operator)::" msgstr "" -#: ../../faq/programming.rst:1088 +#: ../../faq/programming.rst:1109 msgid "Sequences (Tuples/Lists)" msgstr "" -#: ../../faq/programming.rst:1091 +#: ../../faq/programming.rst:1112 msgid "How do I convert between tuples and lists?" msgstr "" -#: ../../faq/programming.rst:1093 +#: ../../faq/programming.rst:1114 msgid "" "The type constructor ``tuple(seq)`` converts any sequence (actually, any " "iterable) into a tuple with the same items in the same order." msgstr "" -#: ../../faq/programming.rst:1096 +#: ../../faq/programming.rst:1117 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 " @@ -1242,7 +1258,7 @@ msgid "" "you aren't sure that an object is already a tuple." msgstr "" -#: ../../faq/programming.rst:1101 +#: ../../faq/programming.rst:1122 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, " @@ -1250,11 +1266,11 @@ msgid "" "If the argument is a list, it makes a copy just like ``seq[:]`` would." msgstr "" -#: ../../faq/programming.rst:1108 +#: ../../faq/programming.rst:1129 msgid "What's a negative index?" msgstr "" -#: ../../faq/programming.rst:1110 +#: ../../faq/programming.rst:1131 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 " @@ -1263,62 +1279,62 @@ msgid "" "``seq[len(seq)-n]``." msgstr "" -#: ../../faq/programming.rst:1115 +#: ../../faq/programming.rst:1136 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 "" -#: ../../faq/programming.rst:1121 +#: ../../faq/programming.rst:1142 msgid "How do I iterate over a sequence in reverse order?" msgstr "" -#: ../../faq/programming.rst:1123 +#: ../../faq/programming.rst:1144 msgid "Use the :func:`reversed` built-in function::" msgstr "" -#: ../../faq/programming.rst:1128 +#: ../../faq/programming.rst:1149 msgid "" "This won't touch your original sequence, but build a new copy with reversed " "order to iterate over." msgstr "" -#: ../../faq/programming.rst:1133 +#: ../../faq/programming.rst:1154 msgid "How do you remove duplicates from a list?" msgstr "" -#: ../../faq/programming.rst:1135 +#: ../../faq/programming.rst:1156 msgid "See the Python Cookbook for a long discussion of many ways to do this:" msgstr "" -#: ../../faq/programming.rst:1137 +#: ../../faq/programming.rst:1158 msgid "https://code.activestate.com/recipes/52560/" msgstr "" -#: ../../faq/programming.rst:1139 +#: ../../faq/programming.rst:1160 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 "" -#: ../../faq/programming.rst:1151 +#: ../../faq/programming.rst:1172 msgid "" "If all elements of the list may be used as set keys (i.e. they are all :term:" "`hashable`) this is often faster ::" msgstr "" -#: ../../faq/programming.rst:1156 +#: ../../faq/programming.rst:1177 msgid "" "This converts the list into a set, thereby removing duplicates, and then " "back into a list." msgstr "" -#: ../../faq/programming.rst:1161 +#: ../../faq/programming.rst:1182 msgid "How do you remove multiple items from a list" msgstr "" -#: ../../faq/programming.rst:1163 +#: ../../faq/programming.rst:1184 msgid "" "As with removing duplicates, explicitly iterating in reverse with a delete " "condition is one possibility. However, it is easier and faster to use slice " @@ -1326,26 +1342,26 @@ msgid "" "variations.::" msgstr "" -#: ../../faq/programming.rst:1172 +#: ../../faq/programming.rst:1193 msgid "The list comprehension may be fastest." msgstr "" -#: ../../faq/programming.rst:1176 +#: ../../faq/programming.rst:1197 msgid "How do you make an array in Python?" msgstr "" -#: ../../faq/programming.rst:1178 +#: ../../faq/programming.rst:1199 msgid "Use a list::" msgstr "" -#: ../../faq/programming.rst:1182 +#: ../../faq/programming.rst:1203 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 "" -#: ../../faq/programming.rst:1185 +#: ../../faq/programming.rst:1206 msgid "" "The ``array`` module also provides methods for creating arrays of fixed " "types with compact representations, but they are slower to index than " @@ -1353,12 +1369,12 @@ msgid "" "like structures with various characteristics as well." msgstr "" -#: ../../faq/programming.rst:1190 +#: ../../faq/programming.rst:1211 msgid "" "To get Lisp-style linked lists, you can emulate cons cells using tuples::" msgstr "" -#: ../../faq/programming.rst:1194 +#: ../../faq/programming.rst:1215 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 " @@ -1366,23 +1382,23 @@ msgid "" "it's usually a lot slower than using Python lists." msgstr "" -#: ../../faq/programming.rst:1203 +#: ../../faq/programming.rst:1224 msgid "How do I create a multidimensional list?" msgstr "" -#: ../../faq/programming.rst:1205 +#: ../../faq/programming.rst:1226 msgid "You probably tried to make a multidimensional array like this::" msgstr "" -#: ../../faq/programming.rst:1209 +#: ../../faq/programming.rst:1230 msgid "This looks correct if you print it:" msgstr "" -#: ../../faq/programming.rst:1220 +#: ../../faq/programming.rst:1241 msgid "But when you assign a value, it shows up in multiple places:" msgstr "" -#: ../../faq/programming.rst:1232 +#: ../../faq/programming.rst:1253 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 " @@ -1390,56 +1406,56 @@ msgid "" "will show in all rows, which is almost certainly not what you want." msgstr "" -#: ../../faq/programming.rst:1237 +#: ../../faq/programming.rst:1258 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 "" -#: ../../faq/programming.rst:1244 +#: ../../faq/programming.rst:1265 msgid "" "This generates a list containing 3 different lists of length two. You can " "also use a list comprehension::" msgstr "" -#: ../../faq/programming.rst:1250 +#: ../../faq/programming.rst:1271 msgid "" "Or, you can use an extension that provides a matrix datatype; `NumPy `_ is the best known." msgstr "" -#: ../../faq/programming.rst:1255 +#: ../../faq/programming.rst:1276 msgid "How do I apply a method to a sequence of objects?" msgstr "" -#: ../../faq/programming.rst:1257 +#: ../../faq/programming.rst:1278 msgid "Use a list comprehension::" msgstr "" -#: ../../faq/programming.rst:1264 +#: ../../faq/programming.rst:1285 msgid "" "Why does a_tuple[i] += ['item'] raise an exception when the addition works?" msgstr "" -#: ../../faq/programming.rst:1266 +#: ../../faq/programming.rst:1287 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 "" -#: ../../faq/programming.rst:1270 +#: ../../faq/programming.rst:1291 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 "" -#: ../../faq/programming.rst:1274 +#: ../../faq/programming.rst:1295 msgid "If you wrote::" msgstr "" -#: ../../faq/programming.rst:1282 +#: ../../faq/programming.rst:1303 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, " @@ -1448,29 +1464,29 @@ msgid "" "an element of a tuple points to." msgstr "" -#: ../../faq/programming.rst:1288 +#: ../../faq/programming.rst:1309 msgid "" "Under the covers, what this augmented assignment statement is doing is " "approximately this::" msgstr "" -#: ../../faq/programming.rst:1297 +#: ../../faq/programming.rst:1318 msgid "" "It is the assignment part of the operation that produces the error, since a " "tuple is immutable." msgstr "" -#: ../../faq/programming.rst:1300 +#: ../../faq/programming.rst:1321 msgid "When you write something like::" msgstr "" -#: ../../faq/programming.rst:1308 +#: ../../faq/programming.rst:1329 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 "" -#: ../../faq/programming.rst:1314 +#: ../../faq/programming.rst:1335 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 " @@ -1480,11 +1496,11 @@ msgid "" "that for lists, ``+=`` is a \"shorthand\" for ``list.extend``::" msgstr "" -#: ../../faq/programming.rst:1326 +#: ../../faq/programming.rst:1347 msgid "This is equivalent to::" msgstr "" -#: ../../faq/programming.rst:1331 +#: ../../faq/programming.rst:1352 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 " @@ -1492,11 +1508,11 @@ msgid "" "``a_list`` was previously pointing to, but the assignment still happens." msgstr "" -#: ../../faq/programming.rst:1336 +#: ../../faq/programming.rst:1357 msgid "Thus, in our tuple example what is happening is equivalent to::" msgstr "" -#: ../../faq/programming.rst:1344 +#: ../../faq/programming.rst:1365 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, " @@ -1504,13 +1520,13 @@ msgid "" "immutable." msgstr "" -#: ../../faq/programming.rst:1350 +#: ../../faq/programming.rst:1371 msgid "" "I want to do a complicated sort: can you do a Schwartzian Transform in " "Python?" msgstr "" -#: ../../faq/programming.rst:1352 +#: ../../faq/programming.rst:1373 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 " @@ -1518,25 +1534,25 @@ msgid "" "method::" msgstr "" -#: ../../faq/programming.rst:1361 +#: ../../faq/programming.rst:1382 msgid "How can I sort one list by values from another list?" msgstr "" -#: ../../faq/programming.rst:1363 +#: ../../faq/programming.rst:1384 msgid "" "Merge them into an iterator of tuples, sort the resulting list, and then " "pick out the element you want. ::" msgstr "" -#: ../../faq/programming.rst:1378 +#: ../../faq/programming.rst:1399 msgid "Objects" msgstr "" -#: ../../faq/programming.rst:1381 +#: ../../faq/programming.rst:1402 msgid "What is a class?" msgstr "" -#: ../../faq/programming.rst:1383 +#: ../../faq/programming.rst:1404 msgid "" "A class is the particular object type created by executing a class " "statement. Class objects are used as templates to create instance objects, " @@ -1544,7 +1560,7 @@ msgid "" "datatype." msgstr "" -#: ../../faq/programming.rst:1387 +#: ../../faq/programming.rst:1408 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. " @@ -1554,22 +1570,22 @@ msgid "" "``OutlookMailbox`` that handle various specific mailbox formats." msgstr "" -#: ../../faq/programming.rst:1396 +#: ../../faq/programming.rst:1417 msgid "What is a method?" msgstr "" -#: ../../faq/programming.rst:1398 +#: ../../faq/programming.rst:1419 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 "" -#: ../../faq/programming.rst:1408 +#: ../../faq/programming.rst:1429 msgid "What is self?" msgstr "" -#: ../../faq/programming.rst:1410 +#: ../../faq/programming.rst:1431 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, " @@ -1577,17 +1593,17 @@ msgid "" "the called method will think it is called as ``meth(x, a, b, c)``." msgstr "" -#: ../../faq/programming.rst:1415 +#: ../../faq/programming.rst:1436 msgid "See also :ref:`why-self`." msgstr "" -#: ../../faq/programming.rst:1419 +#: ../../faq/programming.rst:1440 msgid "" "How do I check if an object is an instance of a given class or of a subclass " "of it?" msgstr "" -#: ../../faq/programming.rst:1421 +#: ../../faq/programming.rst:1442 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 " @@ -1596,7 +1612,7 @@ msgid "" "``isinstance(obj, str)`` or ``isinstance(obj, (int, float, complex))``." msgstr "" -#: ../../faq/programming.rst:1427 +#: ../../faq/programming.rst:1448 msgid "" "Note that :func:`isinstance` also checks for virtual inheritance from an :" "term:`abstract base class`. So, the test will return ``True`` for a " @@ -1604,7 +1620,7 @@ msgid "" "To test for \"true inheritance\", scan the :term:`MRO` of the class:" msgstr "" -#: ../../faq/programming.rst:1462 +#: ../../faq/programming.rst:1483 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 " @@ -1614,17 +1630,17 @@ msgid "" "have a function that does something::" msgstr "" -#: ../../faq/programming.rst:1476 +#: ../../faq/programming.rst:1497 msgid "" "A better approach is to define a ``search()`` method on all the classes and " "just call it::" msgstr "" -#: ../../faq/programming.rst:1491 +#: ../../faq/programming.rst:1512 msgid "What is delegation?" msgstr "" -#: ../../faq/programming.rst:1493 +#: ../../faq/programming.rst:1514 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 " @@ -1633,14 +1649,14 @@ msgid "" "other methods to the corresponding method of ``x``." msgstr "" -#: ../../faq/programming.rst:1499 +#: ../../faq/programming.rst:1520 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 "" -#: ../../faq/programming.rst:1514 +#: ../../faq/programming.rst:1535 msgid "" "Here the ``UpperOut`` class redefines the ``write()`` method to convert the " "argument string to uppercase before calling the underlying ``self._outfile." @@ -1650,7 +1666,7 @@ msgid "" "information about controlling attribute access." msgstr "" -#: ../../faq/programming.rst:1521 +#: ../../faq/programming.rst:1542 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:" @@ -1659,23 +1675,23 @@ msgid "" "following::" msgstr "" -#: ../../faq/programming.rst:1532 +#: ../../faq/programming.rst:1553 msgid "" "Most :meth:`__setattr__` implementations must modify ``self.__dict__`` to " "store local state for self without causing an infinite recursion." msgstr "" -#: ../../faq/programming.rst:1537 +#: ../../faq/programming.rst:1558 msgid "" "How do I call a method defined in a base class from a derived class that " "overrides it?" msgstr "" -#: ../../faq/programming.rst:1539 +#: ../../faq/programming.rst:1560 msgid "Use the built-in :func:`super` function::" msgstr "" -#: ../../faq/programming.rst:1545 +#: ../../faq/programming.rst:1566 msgid "" "For version prior to 3.0, you may be using classic classes: For a class " "definition such as ``class Derived(Base): ...`` you can call method " @@ -1684,11 +1700,11 @@ msgid "" "you need to provide the ``self`` argument." msgstr "" -#: ../../faq/programming.rst:1553 +#: ../../faq/programming.rst:1574 msgid "How can I organize my code to make it easier to change the base class?" msgstr "" -#: ../../faq/programming.rst:1555 +#: ../../faq/programming.rst:1576 msgid "" "You could assign the base class to an alias and derive from the alias. Then " "all you have to change is the value assigned to the alias. Incidentally, " @@ -1696,30 +1712,30 @@ msgid "" "on availability of resources) which base class to use. Example::" msgstr "" -#: ../../faq/programming.rst:1570 +#: ../../faq/programming.rst:1591 msgid "How do I create static class data and static class methods?" msgstr "" -#: ../../faq/programming.rst:1572 +#: ../../faq/programming.rst:1593 msgid "" "Both static data and static methods (in the sense of C++ or Java) are " "supported in Python." msgstr "" -#: ../../faq/programming.rst:1575 +#: ../../faq/programming.rst:1596 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 "" -#: ../../faq/programming.rst:1587 +#: ../../faq/programming.rst:1608 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 "" -#: ../../faq/programming.rst:1591 +#: ../../faq/programming.rst:1612 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 " @@ -1727,59 +1743,59 @@ msgid "" "whether inside a method or not::" msgstr "" -#: ../../faq/programming.rst:1598 +#: ../../faq/programming.rst:1619 msgid "Static methods are possible::" msgstr "" -#: ../../faq/programming.rst:1606 +#: ../../faq/programming.rst:1627 msgid "" "However, a far more straightforward way to get the effect of a static method " "is via a simple module-level function::" msgstr "" -#: ../../faq/programming.rst:1612 +#: ../../faq/programming.rst:1633 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 "" -#: ../../faq/programming.rst:1617 +#: ../../faq/programming.rst:1638 msgid "How can I overload constructors (or methods) in Python?" msgstr "" -#: ../../faq/programming.rst:1619 +#: ../../faq/programming.rst:1640 msgid "" "This answer actually applies to all methods, but the question usually comes " "up first in the context of constructors." msgstr "" -#: ../../faq/programming.rst:1622 +#: ../../faq/programming.rst:1643 msgid "In C++ you'd write" msgstr "" -#: ../../faq/programming.rst:1631 +#: ../../faq/programming.rst:1652 msgid "" "In Python you have to write a single constructor that catches all cases " "using default arguments. For example::" msgstr "" -#: ../../faq/programming.rst:1641 +#: ../../faq/programming.rst:1662 msgid "This is not entirely equivalent, but close enough in practice." msgstr "" -#: ../../faq/programming.rst:1643 +#: ../../faq/programming.rst:1664 msgid "You could also try a variable-length argument list, e.g. ::" msgstr "" -#: ../../faq/programming.rst:1648 +#: ../../faq/programming.rst:1669 msgid "The same approach works for all method definitions." msgstr "" -#: ../../faq/programming.rst:1652 +#: ../../faq/programming.rst:1673 msgid "I try to use __spam and I get an error about _SomeClassName__spam." msgstr "" -#: ../../faq/programming.rst:1654 +#: ../../faq/programming.rst:1675 msgid "" "Variable names with double leading underscores are \"mangled\" to provide a " "simple but effective way to define class private variables. Any identifier " @@ -1789,7 +1805,7 @@ msgid "" "stripped." msgstr "" -#: ../../faq/programming.rst:1660 +#: ../../faq/programming.rst:1681 msgid "" "This doesn't guarantee privacy: an outside user can still deliberately " "access the \"_classname__spam\" attribute, and private values are visible in " @@ -1797,22 +1813,22 @@ msgid "" "private variable names at all." msgstr "" -#: ../../faq/programming.rst:1667 +#: ../../faq/programming.rst:1688 msgid "My class defines __del__ but it is not called when I delete the object." msgstr "" -#: ../../faq/programming.rst:1669 +#: ../../faq/programming.rst:1690 msgid "There are several possible reasons for this." msgstr "" -#: ../../faq/programming.rst:1671 +#: ../../faq/programming.rst:1692 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 "" -#: ../../faq/programming.rst:1675 +#: ../../faq/programming.rst:1696 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 " @@ -1826,7 +1842,7 @@ msgid "" "cases where objects will never be collected." msgstr "" -#: ../../faq/programming.rst:1686 +#: ../../faq/programming.rst:1707 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. " @@ -1836,7 +1852,7 @@ msgid "" "once for the same object." msgstr "" -#: ../../faq/programming.rst:1693 +#: ../../faq/programming.rst:1714 msgid "" "Another way to avoid cyclical references is to use the :mod:`weakref` " "module, which allows you to point to objects without incrementing their " @@ -1844,28 +1860,28 @@ msgid "" "references for their parent and sibling references (if they need them!)." msgstr "" -#: ../../faq/programming.rst:1706 +#: ../../faq/programming.rst:1727 msgid "" "Finally, if your :meth:`__del__` method raises an exception, a warning " "message is printed to :data:`sys.stderr`." msgstr "" -#: ../../faq/programming.rst:1711 +#: ../../faq/programming.rst:1732 msgid "How do I get a list of all instances of a given class?" msgstr "" -#: ../../faq/programming.rst:1713 +#: ../../faq/programming.rst:1734 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 "" -#: ../../faq/programming.rst:1719 +#: ../../faq/programming.rst:1740 msgid "Why does the result of ``id()`` appear to be not unique?" msgstr "" -#: ../../faq/programming.rst:1721 +#: ../../faq/programming.rst:1742 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 " @@ -1874,7 +1890,7 @@ msgid "" "memory. This is illustrated by this example:" msgstr "" -#: ../../faq/programming.rst:1732 +#: ../../faq/programming.rst:1753 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 " @@ -1882,17 +1898,17 @@ msgid "" "reference to the object:" msgstr "" -#: ../../faq/programming.rst:1745 +#: ../../faq/programming.rst:1766 msgid "When can I rely on identity tests with the *is* operator?" msgstr "" -#: ../../faq/programming.rst:1747 +#: ../../faq/programming.rst:1768 msgid "" "The ``is`` operator tests for object identity. The test ``a is b`` is " "equivalent to ``id(a) == id(b)``." msgstr "" -#: ../../faq/programming.rst:1750 +#: ../../faq/programming.rst:1771 msgid "" "The most important property of an identity test is that an object is always " "identical to itself, ``a is a`` always returns ``True``. Identity tests are " @@ -1900,34 +1916,34 @@ msgid "" "tests are guaranteed to return a boolean ``True`` or ``False``." msgstr "" -#: ../../faq/programming.rst:1755 +#: ../../faq/programming.rst:1776 msgid "" "However, identity tests can *only* be substituted for equality tests when " "object identity is assured. Generally, there are three circumstances where " "identity is guaranteed:" msgstr "" -#: ../../faq/programming.rst:1759 +#: ../../faq/programming.rst:1780 msgid "" "1) Assignments create new names but do not change object identity. After " "the assignment ``new = old``, it is guaranteed that ``new is old``." msgstr "" -#: ../../faq/programming.rst:1762 +#: ../../faq/programming.rst:1783 msgid "" "2) Putting an object in a container that stores object references does not " "change object identity. After the list assignment ``s[0] = x``, it is " "guaranteed that ``s[0] is x``." msgstr "" -#: ../../faq/programming.rst:1766 +#: ../../faq/programming.rst:1787 msgid "" "3) If an object is a singleton, it means that only one instance of that " "object can exist. After the assignments ``a = None`` and ``b = None``, it " "is guaranteed that ``a is b`` because ``None`` is a singleton." msgstr "" -#: ../../faq/programming.rst:1770 +#: ../../faq/programming.rst:1791 msgid "" "In most other circumstances, identity tests are inadvisable and equality " "tests are preferred. In particular, identity tests should not be used to " @@ -1935,17 +1951,17 @@ msgid "" "guaranteed to be singletons::" msgstr "" -#: ../../faq/programming.rst:1787 +#: ../../faq/programming.rst:1808 msgid "Likewise, new instances of mutable containers are never identical::" msgstr "" -#: ../../faq/programming.rst:1794 +#: ../../faq/programming.rst:1815 msgid "" "In the standard library code, you will see several common patterns for " "correctly using identity tests:" msgstr "" -#: ../../faq/programming.rst:1797 +#: ../../faq/programming.rst:1818 msgid "" "1) As recommended by :pep:`8`, an identity test is the preferred way to " "check for ``None``. This reads like plain English in code and avoids " @@ -1953,7 +1969,7 @@ msgid "" "false." msgstr "" -#: ../../faq/programming.rst:1801 +#: ../../faq/programming.rst:1822 msgid "" "2) Detecting optional arguments can be tricky when ``None`` is a valid input " "value. In those situations, you can create an singleton sentinel object " @@ -1961,25 +1977,25 @@ msgid "" "implement a method that behaves like :meth:`dict.pop`::" msgstr "" -#: ../../faq/programming.rst:1817 +#: ../../faq/programming.rst:1838 msgid "" "3) Container implementations sometimes need to augment equality tests with " "identity tests. This prevents the code from being confused by objects such " "as ``float('NaN')`` that are not equal to themselves." msgstr "" -#: ../../faq/programming.rst:1821 +#: ../../faq/programming.rst:1842 msgid "" "For example, here is the implementation of :meth:`collections.abc.Sequence." "__contains__`::" msgstr "" -#: ../../faq/programming.rst:1832 +#: ../../faq/programming.rst:1853 msgid "" "How can a subclass control what data is stored in an immutable instance?" msgstr "" -#: ../../faq/programming.rst:1834 +#: ../../faq/programming.rst:1855 msgid "" "When subclassing an immutable type, override the :meth:`__new__` method " "instead of the :meth:`__init__` method. The latter only runs *after* an " @@ -1987,25 +2003,25 @@ msgid "" "instance." msgstr "" -#: ../../faq/programming.rst:1839 +#: ../../faq/programming.rst:1860 msgid "" "All of these immutable classes have a different signature than their parent " "class:" msgstr "" -#: ../../faq/programming.rst:1865 +#: ../../faq/programming.rst:1886 msgid "The classes can be used like this:" msgstr "" -#: ../../faq/programming.rst:1880 +#: ../../faq/programming.rst:1901 msgid "Modules" msgstr "" -#: ../../faq/programming.rst:1883 +#: ../../faq/programming.rst:1904 msgid "How do I create a .pyc file?" msgstr "" -#: ../../faq/programming.rst:1885 +#: ../../faq/programming.rst:1906 msgid "" "When a module is imported for the first time (or when the source file has " "changed since the current compiled file was created) a ``.pyc`` file " @@ -2016,7 +2032,7 @@ msgid "" "particular ``python`` binary that created it. (See :pep:`3147` for details.)" msgstr "" -#: ../../faq/programming.rst:1893 +#: ../../faq/programming.rst:1914 msgid "" "One reason that a ``.pyc`` file may not be created is a permissions problem " "with the directory containing the source file, meaning that the " @@ -2025,7 +2041,7 @@ msgid "" "testing with a web server." msgstr "" -#: ../../faq/programming.rst:1898 +#: ../../faq/programming.rst:1919 msgid "" "Unless the :envvar:`PYTHONDONTWRITEBYTECODE` environment variable is set, " "creation of a .pyc file is automatic if you're importing a module and Python " @@ -2034,7 +2050,7 @@ msgid "" "subdirectory." msgstr "" -#: ../../faq/programming.rst:1903 +#: ../../faq/programming.rst:1924 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." @@ -2044,27 +2060,27 @@ msgid "" "for ``foo`` since ``foo.py`` isn't being imported." msgstr "" -#: ../../faq/programming.rst:1910 +#: ../../faq/programming.rst:1931 msgid "" "If you need to create a ``.pyc`` file for ``foo`` -- that is, to create a ``." "pyc`` file for a module that is not imported -- you can, using the :mod:" "`py_compile` and :mod:`compileall` modules." msgstr "" -#: ../../faq/programming.rst:1914 +#: ../../faq/programming.rst:1935 msgid "" "The :mod:`py_compile` module can manually compile any module. One way is to " "use the ``compile()`` function in that module interactively::" msgstr "" -#: ../../faq/programming.rst:1920 +#: ../../faq/programming.rst:1941 msgid "" "This will write the ``.pyc`` to a ``__pycache__`` subdirectory in the same " "location as ``foo.py`` (or you can override that with the optional parameter " "``cfile``)." msgstr "" -#: ../../faq/programming.rst:1924 +#: ../../faq/programming.rst:1945 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 " @@ -2072,11 +2088,11 @@ msgid "" "Python files to compile::" msgstr "" -#: ../../faq/programming.rst:1933 +#: ../../faq/programming.rst:1954 msgid "How do I find the current module name?" msgstr "" -#: ../../faq/programming.rst:1935 +#: ../../faq/programming.rst:1956 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 " @@ -2085,76 +2101,76 @@ msgid "" "only execute this code after checking ``__name__``::" msgstr "" -#: ../../faq/programming.rst:1950 +#: ../../faq/programming.rst:1971 msgid "How can I have modules that mutually import each other?" msgstr "" -#: ../../faq/programming.rst:1952 +#: ../../faq/programming.rst:1973 msgid "Suppose you have the following modules:" msgstr "" -#: ../../faq/programming.rst:1954 +#: ../../faq/programming.rst:1975 msgid "foo.py::" msgstr "" -#: ../../faq/programming.rst:1959 +#: ../../faq/programming.rst:1980 msgid "bar.py::" msgstr "" -#: ../../faq/programming.rst:1964 +#: ../../faq/programming.rst:1985 msgid "The problem is that the interpreter will perform the following steps:" msgstr "" -#: ../../faq/programming.rst:1966 +#: ../../faq/programming.rst:1987 msgid "main imports foo" msgstr "" -#: ../../faq/programming.rst:1967 +#: ../../faq/programming.rst:1988 msgid "Empty globals for foo are created" msgstr "" -#: ../../faq/programming.rst:1968 +#: ../../faq/programming.rst:1989 msgid "foo is compiled and starts executing" msgstr "" -#: ../../faq/programming.rst:1969 +#: ../../faq/programming.rst:1990 msgid "foo imports bar" msgstr "" -#: ../../faq/programming.rst:1970 +#: ../../faq/programming.rst:1991 msgid "Empty globals for bar are created" msgstr "" -#: ../../faq/programming.rst:1971 +#: ../../faq/programming.rst:1992 msgid "bar is compiled and starts executing" msgstr "" -#: ../../faq/programming.rst:1972 +#: ../../faq/programming.rst:1993 msgid "" "bar imports foo (which is a no-op since there already is a module named foo)" msgstr "" -#: ../../faq/programming.rst:1973 +#: ../../faq/programming.rst:1994 msgid "bar.foo_var = foo.foo_var" msgstr "" -#: ../../faq/programming.rst:1975 +#: ../../faq/programming.rst:1996 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 "" -#: ../../faq/programming.rst:1978 +#: ../../faq/programming.rst:1999 msgid "" "The same thing happens when you use ``import foo``, and then try to access " "``foo.foo_var`` in global code." msgstr "" -#: ../../faq/programming.rst:1981 +#: ../../faq/programming.rst:2002 msgid "There are (at least) three possible workarounds for this problem." msgstr "" -#: ../../faq/programming.rst:1983 +#: ../../faq/programming.rst:2004 msgid "" "Guido van Rossum recommends avoiding all uses of ``from import ..." "``, and placing all code inside functions. Initializations of global " @@ -2163,59 +2179,59 @@ msgid "" "``.``." msgstr "" -#: ../../faq/programming.rst:1988 +#: ../../faq/programming.rst:2009 msgid "" "Jim Roskind suggests performing steps in the following order in each module:" msgstr "" -#: ../../faq/programming.rst:1990 +#: ../../faq/programming.rst:2011 msgid "" "exports (globals, functions, and classes that don't need imported base " "classes)" msgstr "" -#: ../../faq/programming.rst:1992 +#: ../../faq/programming.rst:2013 msgid "``import`` statements" msgstr "" -#: ../../faq/programming.rst:1993 +#: ../../faq/programming.rst:2014 msgid "" "active code (including globals that are initialized from imported values)." msgstr "" -#: ../../faq/programming.rst:1995 +#: ../../faq/programming.rst:2016 msgid "" "van Rossum doesn't like this approach much because the imports appear in a " "strange place, but it does work." msgstr "" -#: ../../faq/programming.rst:1998 +#: ../../faq/programming.rst:2019 msgid "" "Matthias Urlichs recommends restructuring your code so that the recursive " "import is not necessary in the first place." msgstr "" -#: ../../faq/programming.rst:2001 +#: ../../faq/programming.rst:2022 msgid "These solutions are not mutually exclusive." msgstr "" -#: ../../faq/programming.rst:2005 +#: ../../faq/programming.rst:2026 msgid "__import__('x.y.z') returns ; how do I get z?" msgstr "" -#: ../../faq/programming.rst:2007 +#: ../../faq/programming.rst:2028 msgid "" "Consider using the convenience function :func:`~importlib.import_module` " "from :mod:`importlib` instead::" msgstr "" -#: ../../faq/programming.rst:2014 +#: ../../faq/programming.rst:2035 msgid "" "When I edit an imported module and reimport it, the changes don't show up. " "Why does this happen?" msgstr "" -#: ../../faq/programming.rst:2016 +#: ../../faq/programming.rst:2037 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 " @@ -2224,13 +2240,13 @@ msgid "" "re-reading of a changed module, do this::" msgstr "" -#: ../../faq/programming.rst:2026 +#: ../../faq/programming.rst:2047 msgid "" "Warning: this technique is not 100% fool-proof. In particular, modules " "containing statements like ::" msgstr "" -#: ../../faq/programming.rst:2031 +#: ../../faq/programming.rst:2052 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 " @@ -2238,7 +2254,7 @@ msgid "" "paradoxical behaviour::" msgstr "" -#: ../../faq/programming.rst:2044 +#: ../../faq/programming.rst:2065 msgid "" "The nature of the problem is made clear if you print out the \"identity\" of " "the class objects::" From 1b6116945cbf3e1677de46775284d2f6aa960445 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 17 Oct 2021 00:14:40 +0000 Subject: [PATCH 3/6] sync with cpython ac1b7a33 --- reference/executionmodel.po | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/reference/executionmodel.po b/reference/executionmodel.po index 49ca27ec35..10f5b70166 100644 --- a/reference/executionmodel.po +++ b/reference/executionmodel.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.7\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-06-20 18:08+0800\n" +"POT-Creation-Date: 2021-10-17 00:12+0000\n" "PO-Revision-Date: 2018-05-23 16:17+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -143,13 +143,13 @@ msgstr "" #: ../../reference/executionmodel.rst:122 msgid "" "If the :keyword:`global` statement occurs within a block, all uses of the " -"name specified in the statement refer to the binding of that name in the top-" -"level namespace. Names are resolved in the top-level namespace by searching " -"the global namespace, i.e. the namespace of the module containing the code " -"block, and the builtins namespace, the namespace of the module :mod:" -"`builtins`. The global namespace is searched first. If the name is not " +"names specified in the statement refer to the bindings of those names in the " +"top-level namespace. Names are resolved in the top-level namespace by " +"searching the global namespace, i.e. the namespace of the module containing " +"the code block, and the builtins namespace, the namespace of the module :mod:" +"`builtins`. The global namespace is searched first. If the names are not " "found there, the builtins namespace is searched. The :keyword:`!global` " -"statement must precede all uses of the name." +"statement must precede all uses of the listed names." msgstr "" #: ../../reference/executionmodel.rst:131 From 8faf43ce65fda8961855a79d7721b75a02ca287d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 19 Oct 2021 00:13:48 +0000 Subject: [PATCH 4/6] sync with cpython cb34c1ee --- library/random.po | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/library/random.po b/library/random.po index 498a4169c9..ed4f0bf866 100644 --- a/library/random.po +++ b/library/random.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.7\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-09-13 00:11+0000\n" +"POT-Creation-Date: 2021-10-19 00:12+0000\n" "PO-Revision-Date: 2018-05-23 16:09+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -559,7 +559,7 @@ msgid "" "Simulation of arrival times and service deliveries for a multiserver queue::" msgstr "" -#: ../../library/random.rst:531 +#: ../../library/random.rst:532 msgid "" "`Statistics for Hackers `_ a " "video tutorial by `Jake Vanderplas `_ a simulation of a marketplace by `Peter Norvig `_ a tutorial by `Peter " @@ -585,11 +585,11 @@ msgid "" "Python." msgstr "" -#: ../../library/random.rst:552 +#: ../../library/random.rst:553 msgid "Recipes" msgstr "" -#: ../../library/random.rst:554 +#: ../../library/random.rst:555 msgid "" "The default :func:`.random` returns multiples of 2⁻⁵³ in the range *0.0 ≤ x " "< 1.0*. All such numbers are evenly spaced and are exactly representable as " @@ -598,7 +598,7 @@ msgid "" "integer multiple of 2⁻⁵³." msgstr "" -#: ../../library/random.rst:560 +#: ../../library/random.rst:561 msgid "" "The following recipe takes a different approach. All floats in the interval " "are possible selections. The mantissa comes from a uniform distribution of " @@ -607,13 +607,13 @@ msgid "" "often as the next larger exponent." msgstr "" -#: ../../library/random.rst:582 +#: ../../library/random.rst:583 msgid "" "All :ref:`real valued distributions ` in the " "class will use the new method::" msgstr "" -#: ../../library/random.rst:591 +#: ../../library/random.rst:592 msgid "" "The recipe is conceptually equivalent to an algorithm that chooses from all " "the multiples of 2⁻¹⁰⁷⁴ in the range *0.0 ≤ x < 1.0*. All such numbers are " @@ -622,7 +622,7 @@ msgid "" "and is equal to ``math.ulp(0.0)``.)" msgstr "" -#: ../../library/random.rst:600 +#: ../../library/random.rst:601 msgid "" "`Generating Pseudo-random Floating-Point Values `_ a paper by Allen B. Downey describing " From 9df930c454aa732a6024d46f9604e8e34047d56f Mon Sep 17 00:00:00 2001 From: "Matt.Wang" Date: Tue, 19 Oct 2021 15:40:44 +0800 Subject: [PATCH 5/6] chore(license): remove redundant source strings --- license.po | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/license.po b/license.po index 5088a53a9c..87c4c8bf15 100644 --- a/license.po +++ b/license.po @@ -261,26 +261,6 @@ msgstr "" "有些被納入 Python 中的軟體是基於不同的授權。這些授權將會與其授權之程式碼一起" "被列出。關於這些授權的不完整清單,請參閱\\ :ref:`OtherLicenses`\\ 。" -#: ../../license.rst:75 -msgid "" -"Python software and documentation are licensed under the :ref:`PSF License " -"Agreement `." -msgstr "" - -#: ../../license.rst:78 -msgid "" -"Starting with Python 3.8.6, examples, recipes, and other code in the " -"documentation are dual licensed under the PSF License Agreement and the :ref:" -"`Zero-Clause BSD license `." -msgstr "" - -#: ../../license.rst:82 -msgid "" -"Some software incorporated into Python is under different licenses. The " -"licenses are listed with code falling under that license. See :ref:" -"`OtherLicenses` for an incomplete list of these licenses." -msgstr "" - #: ../../license.rst:90 msgid "PSF LICENSE AGREEMENT FOR PYTHON |release|" msgstr "用於 PYTHON |release| 的 PSF 授權合約" @@ -305,10 +285,6 @@ msgstr "用於 PYTHON 0.9.0 至 1.2 的 CWI 授權合約" msgid "ZERO-CLAUSE BSD LICENSE FOR CODE IN THE PYTHON |release| DOCUMENTATION" msgstr "用於 PYTHON |release| 說明文件內程式碼的 ZERO-CLAUSE BSD 授權" -#: ../../license.rst:277 -msgid "ZERO-CLAUSE BSD LICENSE FOR CODE IN THE PYTHON |release| DOCUMENTATION" -msgstr "" - #: ../../license.rst:296 msgid "Licenses and Acknowledgements for Incorporated Software" msgstr "被收錄軟體的授權與致謝" From 97cbfe558b5abd5f5f16e32d7f9b1755b0cfddcd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 19 Oct 2021 07:45:37 +0000 Subject: [PATCH 6/6] sync with cpython cb34c1ee --- license.po | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/license.po b/license.po index 87c4c8bf15..cd5e232933 100644 --- a/license.po +++ b/license.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.9\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-09-24 00:11+0000\n" +"POT-Creation-Date: 2021-10-19 07:44+0000\n" "PO-Revision-Date: 2021-07-04 01:18+0800\n" "Last-Translator: Steven Hsu \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -236,14 +236,14 @@ msgstr "" msgid "Terms and conditions for accessing or otherwise using Python" msgstr "關於存取或以其他方式使用 Python 的合約條款" -#: ../../license.rst:74 +#: ../../license.rst:75 msgid "" "Python software and documentation are licensed under the :ref:`PSF License " "Agreement `." msgstr "" "Python 軟體和說明文件的授權是基於 :ref:`PSF 授權合約 `\\ 。" -#: ../../license.rst:75 +#: ../../license.rst:78 msgid "" "Starting with Python 3.8.6, examples, recipes, and other code in the " "documentation are dual licensed under the PSF License Agreement and the :ref:" @@ -252,7 +252,7 @@ msgstr "" "從 Python 3.8.6 開始,說明文件中的範例、程式庫和其他程式碼,是被雙重授權 " "(dual licensed) 於 PSF 授權合約以及 :ref:`Zero-Clause BSD 授權 `\\ 。" -#: ../../license.rst:76 +#: ../../license.rst:82 msgid "" "Some software incorporated into Python is under different licenses. The " "licenses are listed with code falling under that license. See :ref:" @@ -281,7 +281,7 @@ msgstr "用於 PYTHON 1.6.1 的 CNRI 授權合約" msgid "CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2" msgstr "用於 PYTHON 0.9.0 至 1.2 的 CWI 授權合約" -#: ../../license.rst:252 +#: ../../license.rst:277 msgid "ZERO-CLAUSE BSD LICENSE FOR CODE IN THE PYTHON |release| DOCUMENTATION" msgstr "用於 PYTHON |release| 說明文件內程式碼的 ZERO-CLAUSE BSD 授權" @@ -457,8 +457,8 @@ msgid "" msgstr "" "如果 OpenSSL 函式庫可被作業系統使用,則 :mod:`hashlib`\\ 、\\ :mod:`posix`" "\\ 、\\ :mod:`ssl`\\ 、\\ :mod:`crypt` 模組會使用它來提升效能。此外,因為 " -"Windows 和 macOS 的 Python 安裝程式可能包含 OpenSSL 函式庫的副本,所以我們" -"也在此收錄 OpenSSL 授權的副本:\n" +"Windows 和 macOS 的 Python 安裝程式可能包含 OpenSSL 函式庫的副本,所以我們也" +"在此收錄 OpenSSL 授權的副本:\n" "\n" "::"