diff --git a/faq/programming.po b/faq/programming.po index 38b67b8801..fdf773d83c 100644 --- a/faq/programming.po +++ b/faq/programming.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.11\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-12-23 00:16+0000\n" +"POT-Creation-Date: 2022-12-29 00:16+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-" @@ -1125,72 +1125,112 @@ msgstr "" msgid "See the :ref:`unicode-howto`." msgstr "" -#: ../../faq/programming.rst:1030 +#: ../../faq/programming.rst:1032 +msgid "Can I end a raw string with an odd number of backslashes?" +msgstr "" + +#: ../../faq/programming.rst:1034 +msgid "" +"A raw string ending with an odd number of backslashes will escape the " +"string's quote::" +msgstr "" + +#: ../../faq/programming.rst:1042 +msgid "" +"There are several workarounds for this. One is to use regular strings and " +"double the backslashes::" +msgstr "" + +#: ../../faq/programming.rst:1048 +msgid "" +"Another is to concatenate a regular string containing an escaped backslash " +"to the raw string::" +msgstr "" + +#: ../../faq/programming.rst:1054 +msgid "" +"It is also possible to use :func:`os.path.join` to append a backslash on " +"Windows::" +msgstr "" + +#: ../../faq/programming.rst:1059 +msgid "" +"Note that while a backslash will \"escape\" a quote for the purposes of " +"determining where the raw string ends, no escaping occurs when interpreting " +"the value of the raw string. That is, the backslash remains present in the " +"value of the raw string::" +msgstr "" + +#: ../../faq/programming.rst:1067 +msgid "Also see the specification in the :ref:`language reference `." +msgstr "" + +#: ../../faq/programming.rst:1070 msgid "Performance" msgstr "" -#: ../../faq/programming.rst:1033 +#: ../../faq/programming.rst:1073 msgid "My program is too slow. How do I speed it up?" msgstr "" -#: ../../faq/programming.rst:1035 +#: ../../faq/programming.rst:1075 msgid "" "That's a tough one, in general. First, here are a list of things to " "remember before diving further:" msgstr "" -#: ../../faq/programming.rst:1038 +#: ../../faq/programming.rst:1078 msgid "" "Performance characteristics vary across Python implementations. This FAQ " "focuses on :term:`CPython`." msgstr "" -#: ../../faq/programming.rst:1040 +#: ../../faq/programming.rst:1080 msgid "" "Behaviour can vary across operating systems, especially when talking about I/" "O or multi-threading." msgstr "" -#: ../../faq/programming.rst:1042 +#: ../../faq/programming.rst:1082 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:1044 +#: ../../faq/programming.rst:1084 msgid "" "Writing benchmark scripts will allow you to iterate quickly when searching " "for improvements (see the :mod:`timeit` module)." msgstr "" -#: ../../faq/programming.rst:1046 +#: ../../faq/programming.rst:1086 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:1050 +#: ../../faq/programming.rst:1090 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:1054 +#: ../../faq/programming.rst:1094 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:1058 +#: ../../faq/programming.rst:1098 msgid "" "Use the right data structures. Study documentation for the :ref:`bltin-" "types` and the :mod:`collections` module." msgstr "" -#: ../../faq/programming.rst:1061 +#: ../../faq/programming.rst:1101 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 " @@ -1201,7 +1241,7 @@ msgid "" "advanced usage)." msgstr "" -#: ../../faq/programming.rst:1069 +#: ../../faq/programming.rst:1109 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, " @@ -1210,7 +1250,7 @@ msgid "" "detrimental to readability)." msgstr "" -#: ../../faq/programming.rst:1075 +#: ../../faq/programming.rst:1115 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 " @@ -1222,17 +1262,17 @@ msgid "" "yourself." msgstr "" -#: ../../faq/programming.rst:1085 +#: ../../faq/programming.rst:1125 msgid "" "The wiki page devoted to `performance tips `_." msgstr "" -#: ../../faq/programming.rst:1091 +#: ../../faq/programming.rst:1131 msgid "What is the most efficient way to concatenate many strings together?" msgstr "" -#: ../../faq/programming.rst:1093 +#: ../../faq/programming.rst:1133 msgid "" ":class:`str` and :class:`bytes` objects are immutable, therefore " "concatenating many strings together is inefficient as each concatenation " @@ -1240,38 +1280,38 @@ msgid "" "quadratic in the total string length." msgstr "" -#: ../../faq/programming.rst:1098 +#: ../../faq/programming.rst:1138 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:1106 +#: ../../faq/programming.rst:1146 msgid "(another reasonably efficient idiom is to use :class:`io.StringIO`)" msgstr "" -#: ../../faq/programming.rst:1108 +#: ../../faq/programming.rst:1148 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:1117 +#: ../../faq/programming.rst:1157 msgid "Sequences (Tuples/Lists)" msgstr "" -#: ../../faq/programming.rst:1120 +#: ../../faq/programming.rst:1160 msgid "How do I convert between tuples and lists?" msgstr "" -#: ../../faq/programming.rst:1122 +#: ../../faq/programming.rst:1162 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:1125 +#: ../../faq/programming.rst:1165 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 " @@ -1279,7 +1319,7 @@ msgid "" "you aren't sure that an object is already a tuple." msgstr "" -#: ../../faq/programming.rst:1130 +#: ../../faq/programming.rst:1170 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, " @@ -1287,11 +1327,11 @@ msgid "" "If the argument is a list, it makes a copy just like ``seq[:]`` would." msgstr "" -#: ../../faq/programming.rst:1137 +#: ../../faq/programming.rst:1177 msgid "What's a negative index?" msgstr "" -#: ../../faq/programming.rst:1139 +#: ../../faq/programming.rst:1179 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 " @@ -1300,62 +1340,62 @@ msgid "" "``seq[len(seq)-n]``." msgstr "" -#: ../../faq/programming.rst:1144 +#: ../../faq/programming.rst:1184 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:1150 +#: ../../faq/programming.rst:1190 msgid "How do I iterate over a sequence in reverse order?" msgstr "" -#: ../../faq/programming.rst:1152 +#: ../../faq/programming.rst:1192 msgid "Use the :func:`reversed` built-in function::" msgstr "" -#: ../../faq/programming.rst:1157 +#: ../../faq/programming.rst:1197 msgid "" "This won't touch your original sequence, but build a new copy with reversed " "order to iterate over." msgstr "" -#: ../../faq/programming.rst:1162 +#: ../../faq/programming.rst:1202 msgid "How do you remove duplicates from a list?" msgstr "" -#: ../../faq/programming.rst:1164 +#: ../../faq/programming.rst:1204 msgid "See the Python Cookbook for a long discussion of many ways to do this:" msgstr "" -#: ../../faq/programming.rst:1166 +#: ../../faq/programming.rst:1206 msgid "https://code.activestate.com/recipes/52560/" msgstr "https://code.activestate.com/recipes/52560/" -#: ../../faq/programming.rst:1168 +#: ../../faq/programming.rst:1208 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:1180 +#: ../../faq/programming.rst:1220 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:1185 +#: ../../faq/programming.rst:1225 msgid "" "This converts the list into a set, thereby removing duplicates, and then " "back into a list." msgstr "" -#: ../../faq/programming.rst:1190 +#: ../../faq/programming.rst:1230 msgid "How do you remove multiple items from a list" msgstr "" -#: ../../faq/programming.rst:1192 +#: ../../faq/programming.rst:1232 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 " @@ -1363,26 +1403,26 @@ msgid "" "variations.::" msgstr "" -#: ../../faq/programming.rst:1201 +#: ../../faq/programming.rst:1241 msgid "The list comprehension may be fastest." msgstr "" -#: ../../faq/programming.rst:1205 +#: ../../faq/programming.rst:1245 msgid "How do you make an array in Python?" msgstr "" -#: ../../faq/programming.rst:1207 +#: ../../faq/programming.rst:1247 msgid "Use a list::" msgstr "" -#: ../../faq/programming.rst:1211 +#: ../../faq/programming.rst:1251 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:1214 +#: ../../faq/programming.rst:1254 msgid "" "The ``array`` module also provides methods for creating arrays of fixed " "types with compact representations, but they are slower to index than " @@ -1390,12 +1430,12 @@ msgid "" "packages define array-like structures with various characteristics as well." msgstr "" -#: ../../faq/programming.rst:1220 +#: ../../faq/programming.rst:1260 msgid "" "To get Lisp-style linked lists, you can emulate *cons cells* using tuples::" msgstr "" -#: ../../faq/programming.rst:1224 +#: ../../faq/programming.rst:1264 msgid "" "If mutability is desired, you could use lists instead of tuples. Here the " "analogue of a Lisp *car* is ``lisp_list[0]`` and the analogue of *cdr* is " @@ -1403,23 +1443,23 @@ msgid "" "it's usually a lot slower than using Python lists." msgstr "" -#: ../../faq/programming.rst:1233 +#: ../../faq/programming.rst:1273 msgid "How do I create a multidimensional list?" msgstr "" -#: ../../faq/programming.rst:1235 +#: ../../faq/programming.rst:1275 msgid "You probably tried to make a multidimensional array like this::" msgstr "" -#: ../../faq/programming.rst:1239 +#: ../../faq/programming.rst:1279 msgid "This looks correct if you print it:" msgstr "" -#: ../../faq/programming.rst:1250 +#: ../../faq/programming.rst:1290 msgid "But when you assign a value, it shows up in multiple places:" msgstr "" -#: ../../faq/programming.rst:1262 +#: ../../faq/programming.rst:1302 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 " @@ -1427,64 +1467,64 @@ msgid "" "will show in all rows, which is almost certainly not what you want." msgstr "" -#: ../../faq/programming.rst:1267 +#: ../../faq/programming.rst:1307 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:1274 +#: ../../faq/programming.rst:1314 msgid "" "This generates a list containing 3 different lists of length two. You can " "also use a list comprehension::" msgstr "" -#: ../../faq/programming.rst:1280 +#: ../../faq/programming.rst:1320 msgid "" "Or, you can use an extension that provides a matrix datatype; `NumPy " "`_ is the best known." msgstr "" -#: ../../faq/programming.rst:1285 +#: ../../faq/programming.rst:1325 msgid "How do I apply a method or function to a sequence of objects?" msgstr "" -#: ../../faq/programming.rst:1287 +#: ../../faq/programming.rst:1327 msgid "" "To call a method or function and accumulate the return values is a list, a :" "term:`list comprehension` is an elegant solution::" msgstr "" -#: ../../faq/programming.rst:1294 +#: ../../faq/programming.rst:1334 msgid "" "To just run the method or function without saving the return values, a " "plain :keyword:`for` loop will suffice::" msgstr "" -#: ../../faq/programming.rst:1306 +#: ../../faq/programming.rst:1346 msgid "" "Why does a_tuple[i] += ['item'] raise an exception when the addition works?" msgstr "" -#: ../../faq/programming.rst:1308 +#: ../../faq/programming.rst:1348 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:1312 +#: ../../faq/programming.rst:1352 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:1316 +#: ../../faq/programming.rst:1356 msgid "If you wrote::" msgstr "" -#: ../../faq/programming.rst:1324 +#: ../../faq/programming.rst:1364 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, " @@ -1493,29 +1533,29 @@ msgid "" "an element of a tuple points to." msgstr "" -#: ../../faq/programming.rst:1330 +#: ../../faq/programming.rst:1370 msgid "" "Under the covers, what this augmented assignment statement is doing is " "approximately this::" msgstr "" -#: ../../faq/programming.rst:1339 +#: ../../faq/programming.rst:1379 msgid "" "It is the assignment part of the operation that produces the error, since a " "tuple is immutable." msgstr "" -#: ../../faq/programming.rst:1342 +#: ../../faq/programming.rst:1382 msgid "When you write something like::" msgstr "" -#: ../../faq/programming.rst:1350 +#: ../../faq/programming.rst:1390 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:1356 +#: ../../faq/programming.rst:1396 msgid "" "To see why this happens, you need to know that (a) if an object implements " "an :meth:`~object.__iadd__` magic method, it gets called when the ``+=`` " @@ -1526,14 +1566,14 @@ msgid "" "extend`::" msgstr "" -#: ../../faq/programming.rst:1369 +#: ../../faq/programming.rst:1409 msgid "This is equivalent to::" msgstr "" "這等價於:\n" "\n" "::" -#: ../../faq/programming.rst:1374 +#: ../../faq/programming.rst:1414 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 " @@ -1541,11 +1581,11 @@ msgid "" "``a_list`` was previously pointing to, but the assignment still happens." msgstr "" -#: ../../faq/programming.rst:1379 +#: ../../faq/programming.rst:1419 msgid "Thus, in our tuple example what is happening is equivalent to::" msgstr "" -#: ../../faq/programming.rst:1387 +#: ../../faq/programming.rst:1427 msgid "" "The :meth:`!__iadd__` succeeds, and thus the list is extended, but even " "though ``result`` points to the same object that ``a_tuple[0]`` already " @@ -1553,13 +1593,13 @@ msgid "" "are immutable." msgstr "" -#: ../../faq/programming.rst:1393 +#: ../../faq/programming.rst:1433 msgid "" "I want to do a complicated sort: can you do a Schwartzian Transform in " "Python?" msgstr "" -#: ../../faq/programming.rst:1395 +#: ../../faq/programming.rst:1435 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 " @@ -1567,25 +1607,25 @@ msgid "" "method::" msgstr "" -#: ../../faq/programming.rst:1404 +#: ../../faq/programming.rst:1444 msgid "How can I sort one list by values from another list?" msgstr "" -#: ../../faq/programming.rst:1406 +#: ../../faq/programming.rst:1446 msgid "" "Merge them into an iterator of tuples, sort the resulting list, and then " "pick out the element you want. ::" msgstr "" -#: ../../faq/programming.rst:1421 +#: ../../faq/programming.rst:1461 msgid "Objects" msgstr "" -#: ../../faq/programming.rst:1424 +#: ../../faq/programming.rst:1464 msgid "What is a class?" msgstr "" -#: ../../faq/programming.rst:1426 +#: ../../faq/programming.rst:1466 msgid "" "A class is the particular object type created by executing a class " "statement. Class objects are used as templates to create instance objects, " @@ -1593,7 +1633,7 @@ msgid "" "datatype." msgstr "" -#: ../../faq/programming.rst:1430 +#: ../../faq/programming.rst:1470 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. " @@ -1603,22 +1643,22 @@ msgid "" "``OutlookMailbox`` that handle various specific mailbox formats." msgstr "" -#: ../../faq/programming.rst:1439 +#: ../../faq/programming.rst:1479 msgid "What is a method?" msgstr "" -#: ../../faq/programming.rst:1441 +#: ../../faq/programming.rst:1481 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:1451 +#: ../../faq/programming.rst:1491 msgid "What is self?" msgstr "" -#: ../../faq/programming.rst:1453 +#: ../../faq/programming.rst:1493 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, " @@ -1626,17 +1666,17 @@ msgid "" "the called method will think it is called as ``meth(x, a, b, c)``." msgstr "" -#: ../../faq/programming.rst:1458 +#: ../../faq/programming.rst:1498 msgid "See also :ref:`why-self`." msgstr "另請參閱 :ref:`why-self`\\ 。" -#: ../../faq/programming.rst:1462 +#: ../../faq/programming.rst:1502 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:1464 +#: ../../faq/programming.rst:1504 msgid "" "Use the built-in function :func:`isinstance(obj, cls) `. You " "can check if an object is an instance of any of a number of classes by " @@ -1646,7 +1686,7 @@ msgid "" "float, complex))``." msgstr "" -#: ../../faq/programming.rst:1471 +#: ../../faq/programming.rst:1511 msgid "" "Note that :func:`isinstance` also checks for virtual inheritance from an :" "term:`abstract base class`. So, the test will return ``True`` for a " @@ -1654,7 +1694,7 @@ msgid "" "To test for \"true inheritance\", scan the :term:`MRO` of the class:" msgstr "" -#: ../../faq/programming.rst:1506 +#: ../../faq/programming.rst:1546 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 " @@ -1664,17 +1704,17 @@ msgid "" "have a function that does something::" msgstr "" -#: ../../faq/programming.rst:1520 +#: ../../faq/programming.rst:1560 msgid "" "A better approach is to define a ``search()`` method on all the classes and " "just call it::" msgstr "" -#: ../../faq/programming.rst:1535 +#: ../../faq/programming.rst:1575 msgid "What is delegation?" msgstr "" -#: ../../faq/programming.rst:1537 +#: ../../faq/programming.rst:1577 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 " @@ -1683,14 +1723,14 @@ msgid "" "other methods to the corresponding method of ``x``." msgstr "" -#: ../../faq/programming.rst:1543 +#: ../../faq/programming.rst:1583 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:1558 +#: ../../faq/programming.rst:1598 msgid "" "Here the ``UpperOut`` class redefines the ``write()`` method to convert the " "argument string to uppercase before calling the underlying ``self._outfile." @@ -1700,7 +1740,7 @@ msgid "" "access>` for more information about controlling attribute access." msgstr "" -#: ../../faq/programming.rst:1565 +#: ../../faq/programming.rst:1605 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:" @@ -1709,24 +1749,24 @@ msgid "" "following::" msgstr "" -#: ../../faq/programming.rst:1576 +#: ../../faq/programming.rst:1616 msgid "" "Most :meth:`!__setattr__` implementations must modify :meth:`self.__dict__ " "` to store local state for self without causing an infinite " "recursion." msgstr "" -#: ../../faq/programming.rst:1582 +#: ../../faq/programming.rst:1622 msgid "" "How do I call a method defined in a base class from a derived class that " "extends it?" msgstr "" -#: ../../faq/programming.rst:1584 +#: ../../faq/programming.rst:1624 msgid "Use the built-in :func:`super` function::" msgstr "" -#: ../../faq/programming.rst:1590 +#: ../../faq/programming.rst:1630 msgid "" "In the example, :func:`super` will automatically determine the instance from " "which it was called (the ``self`` value), look up the :term:`method " @@ -1734,11 +1774,11 @@ msgid "" "line after ``Derived`` in the MRO: ``Base``." msgstr "" -#: ../../faq/programming.rst:1597 +#: ../../faq/programming.rst:1637 msgid "How can I organize my code to make it easier to change the base class?" msgstr "" -#: ../../faq/programming.rst:1599 +#: ../../faq/programming.rst:1639 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, " @@ -1746,30 +1786,30 @@ msgid "" "on availability of resources) which base class to use. Example::" msgstr "" -#: ../../faq/programming.rst:1614 +#: ../../faq/programming.rst:1654 msgid "How do I create static class data and static class methods?" msgstr "" -#: ../../faq/programming.rst:1616 +#: ../../faq/programming.rst:1656 msgid "" "Both static data and static methods (in the sense of C++ or Java) are " "supported in Python." msgstr "" -#: ../../faq/programming.rst:1619 +#: ../../faq/programming.rst:1659 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:1631 +#: ../../faq/programming.rst:1671 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:1635 +#: ../../faq/programming.rst:1675 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 " @@ -1777,59 +1817,59 @@ msgid "" "whether inside a method or not::" msgstr "" -#: ../../faq/programming.rst:1642 +#: ../../faq/programming.rst:1682 msgid "Static methods are possible::" msgstr "" -#: ../../faq/programming.rst:1650 +#: ../../faq/programming.rst:1690 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:1656 +#: ../../faq/programming.rst:1696 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:1661 +#: ../../faq/programming.rst:1701 msgid "How can I overload constructors (or methods) in Python?" msgstr "" -#: ../../faq/programming.rst:1663 +#: ../../faq/programming.rst:1703 msgid "" "This answer actually applies to all methods, but the question usually comes " "up first in the context of constructors." msgstr "" -#: ../../faq/programming.rst:1666 +#: ../../faq/programming.rst:1706 msgid "In C++ you'd write" msgstr "" -#: ../../faq/programming.rst:1675 +#: ../../faq/programming.rst:1715 msgid "" "In Python you have to write a single constructor that catches all cases " "using default arguments. For example::" msgstr "" -#: ../../faq/programming.rst:1685 +#: ../../faq/programming.rst:1725 msgid "This is not entirely equivalent, but close enough in practice." msgstr "" -#: ../../faq/programming.rst:1687 +#: ../../faq/programming.rst:1727 msgid "You could also try a variable-length argument list, e.g. ::" msgstr "" -#: ../../faq/programming.rst:1692 +#: ../../faq/programming.rst:1732 msgid "The same approach works for all method definitions." msgstr "" -#: ../../faq/programming.rst:1696 +#: ../../faq/programming.rst:1736 msgid "I try to use __spam and I get an error about _SomeClassName__spam." msgstr "" -#: ../../faq/programming.rst:1698 +#: ../../faq/programming.rst:1738 msgid "" "Variable names with double leading underscores are \"mangled\" to provide a " "simple but effective way to define class private variables. Any identifier " @@ -1839,7 +1879,7 @@ msgid "" "stripped." msgstr "" -#: ../../faq/programming.rst:1704 +#: ../../faq/programming.rst:1744 msgid "" "This doesn't guarantee privacy: an outside user can still deliberately " "access the \"_classname__spam\" attribute, and private values are visible in " @@ -1847,22 +1887,22 @@ msgid "" "private variable names at all." msgstr "" -#: ../../faq/programming.rst:1711 +#: ../../faq/programming.rst:1751 msgid "My class defines __del__ but it is not called when I delete the object." msgstr "" -#: ../../faq/programming.rst:1713 +#: ../../faq/programming.rst:1753 msgid "There are several possible reasons for this." msgstr "" -#: ../../faq/programming.rst:1715 +#: ../../faq/programming.rst:1755 msgid "" "The :keyword:`del` statement does not necessarily call :meth:`~object." "__del__` -- it simply decrements the object's reference count, and if this " "reaches zero :meth:`!__del__` is called." msgstr "" -#: ../../faq/programming.rst:1719 +#: ../../faq/programming.rst:1759 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 " @@ -1876,7 +1916,7 @@ msgid "" "cases where objects will never be collected." msgstr "" -#: ../../faq/programming.rst:1730 +#: ../../faq/programming.rst:1770 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. " @@ -1886,7 +1926,7 @@ msgid "" "once for the same object." msgstr "" -#: ../../faq/programming.rst:1737 +#: ../../faq/programming.rst:1777 msgid "" "Another way to avoid cyclical references is to use the :mod:`weakref` " "module, which allows you to point to objects without incrementing their " @@ -1894,28 +1934,28 @@ msgid "" "references for their parent and sibling references (if they need them!)." msgstr "" -#: ../../faq/programming.rst:1750 +#: ../../faq/programming.rst:1790 msgid "" "Finally, if your :meth:`!__del__` method raises an exception, a warning " "message is printed to :data:`sys.stderr`." msgstr "" -#: ../../faq/programming.rst:1755 +#: ../../faq/programming.rst:1795 msgid "How do I get a list of all instances of a given class?" msgstr "" -#: ../../faq/programming.rst:1757 +#: ../../faq/programming.rst:1797 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:1763 +#: ../../faq/programming.rst:1803 msgid "Why does the result of ``id()`` appear to be not unique?" msgstr "" -#: ../../faq/programming.rst:1765 +#: ../../faq/programming.rst:1805 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 " @@ -1924,7 +1964,7 @@ msgid "" "memory. This is illustrated by this example:" msgstr "" -#: ../../faq/programming.rst:1776 +#: ../../faq/programming.rst:1816 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 " @@ -1932,17 +1972,17 @@ msgid "" "reference to the object:" msgstr "" -#: ../../faq/programming.rst:1789 +#: ../../faq/programming.rst:1829 msgid "When can I rely on identity tests with the *is* operator?" msgstr "" -#: ../../faq/programming.rst:1791 +#: ../../faq/programming.rst:1831 msgid "" "The ``is`` operator tests for object identity. The test ``a is b`` is " "equivalent to ``id(a) == id(b)``." msgstr "" -#: ../../faq/programming.rst:1794 +#: ../../faq/programming.rst:1834 msgid "" "The most important property of an identity test is that an object is always " "identical to itself, ``a is a`` always returns ``True``. Identity tests are " @@ -1950,34 +1990,34 @@ msgid "" "tests are guaranteed to return a boolean ``True`` or ``False``." msgstr "" -#: ../../faq/programming.rst:1799 +#: ../../faq/programming.rst:1839 msgid "" "However, identity tests can *only* be substituted for equality tests when " "object identity is assured. Generally, there are three circumstances where " "identity is guaranteed:" msgstr "" -#: ../../faq/programming.rst:1803 +#: ../../faq/programming.rst:1843 msgid "" "1) Assignments create new names but do not change object identity. After " "the assignment ``new = old``, it is guaranteed that ``new is old``." msgstr "" -#: ../../faq/programming.rst:1806 +#: ../../faq/programming.rst:1846 msgid "" "2) Putting an object in a container that stores object references does not " "change object identity. After the list assignment ``s[0] = x``, it is " "guaranteed that ``s[0] is x``." msgstr "" -#: ../../faq/programming.rst:1810 +#: ../../faq/programming.rst:1850 msgid "" "3) If an object is a singleton, it means that only one instance of that " "object can exist. After the assignments ``a = None`` and ``b = None``, it " "is guaranteed that ``a is b`` because ``None`` is a singleton." msgstr "" -#: ../../faq/programming.rst:1814 +#: ../../faq/programming.rst:1854 msgid "" "In most other circumstances, identity tests are inadvisable and equality " "tests are preferred. In particular, identity tests should not be used to " @@ -1985,17 +2025,17 @@ msgid "" "guaranteed to be singletons::" msgstr "" -#: ../../faq/programming.rst:1831 +#: ../../faq/programming.rst:1871 msgid "Likewise, new instances of mutable containers are never identical::" msgstr "" -#: ../../faq/programming.rst:1838 +#: ../../faq/programming.rst:1878 msgid "" "In the standard library code, you will see several common patterns for " "correctly using identity tests:" msgstr "" -#: ../../faq/programming.rst:1841 +#: ../../faq/programming.rst:1881 msgid "" "1) As recommended by :pep:`8`, an identity test is the preferred way to " "check for ``None``. This reads like plain English in code and avoids " @@ -2003,7 +2043,7 @@ msgid "" "false." msgstr "" -#: ../../faq/programming.rst:1845 +#: ../../faq/programming.rst:1885 msgid "" "2) Detecting optional arguments can be tricky when ``None`` is a valid input " "value. In those situations, you can create a singleton sentinel object " @@ -2011,25 +2051,25 @@ msgid "" "implement a method that behaves like :meth:`dict.pop`::" msgstr "" -#: ../../faq/programming.rst:1861 +#: ../../faq/programming.rst:1901 msgid "" "3) Container implementations sometimes need to augment equality tests with " "identity tests. This prevents the code from being confused by objects such " "as ``float('NaN')`` that are not equal to themselves." msgstr "" -#: ../../faq/programming.rst:1865 +#: ../../faq/programming.rst:1905 msgid "" "For example, here is the implementation of :meth:`collections.abc.Sequence." "__contains__`::" msgstr "" -#: ../../faq/programming.rst:1876 +#: ../../faq/programming.rst:1916 msgid "" "How can a subclass control what data is stored in an immutable instance?" msgstr "" -#: ../../faq/programming.rst:1878 +#: ../../faq/programming.rst:1918 msgid "" "When subclassing an immutable type, override the :meth:`~object.__new__` " "method instead of the :meth:`~object.__init__` method. The latter only runs " @@ -2037,35 +2077,35 @@ msgid "" "immutable instance." msgstr "" -#: ../../faq/programming.rst:1883 +#: ../../faq/programming.rst:1923 msgid "" "All of these immutable classes have a different signature than their parent " "class:" msgstr "" -#: ../../faq/programming.rst:1909 +#: ../../faq/programming.rst:1949 msgid "The classes can be used like this:" msgstr "" -#: ../../faq/programming.rst:1926 +#: ../../faq/programming.rst:1966 msgid "How do I cache method calls?" msgstr "" -#: ../../faq/programming.rst:1928 +#: ../../faq/programming.rst:1968 msgid "" "The two principal tools for caching methods are :func:`functools." "cached_property` and :func:`functools.lru_cache`. The former stores results " "at the instance level and the latter at the class level." msgstr "" -#: ../../faq/programming.rst:1933 +#: ../../faq/programming.rst:1973 msgid "" "The *cached_property* approach only works with methods that do not take any " "arguments. It does not create a reference to the instance. The cached " "method result will be kept only as long as the instance is alive." msgstr "" -#: ../../faq/programming.rst:1937 +#: ../../faq/programming.rst:1977 msgid "" "The advantage is that when an instance is no longer used, the cached method " "result will be released right away. The disadvantage is that if instances " @@ -2073,47 +2113,47 @@ msgid "" "without bound." msgstr "" -#: ../../faq/programming.rst:1942 +#: ../../faq/programming.rst:1982 msgid "" "The *lru_cache* approach works with methods that have hashable arguments. " "It creates a reference to the instance unless special efforts are made to " "pass in weak references." msgstr "" -#: ../../faq/programming.rst:1946 +#: ../../faq/programming.rst:1986 msgid "" "The advantage of the least recently used algorithm is that the cache is " "bounded by the specified *maxsize*. The disadvantage is that instances are " "kept alive until they age out of the cache or until the cache is cleared." msgstr "" -#: ../../faq/programming.rst:1951 +#: ../../faq/programming.rst:1991 msgid "This example shows the various techniques::" msgstr "" -#: ../../faq/programming.rst:1975 +#: ../../faq/programming.rst:2015 msgid "" "The above example assumes that the *station_id* never changes. If the " "relevant instance attributes are mutable, the *cached_property* approach " "can't be made to work because it cannot detect changes to the attributes." msgstr "" -#: ../../faq/programming.rst:1980 +#: ../../faq/programming.rst:2020 msgid "" "To make the *lru_cache* approach work when the *station_id* is mutable, the " "class needs to define the :meth:`~object.__eq__` and :meth:`~object." "__hash__` methods so that the cache can detect relevant attribute updates::" msgstr "" -#: ../../faq/programming.rst:2006 +#: ../../faq/programming.rst:2046 msgid "Modules" msgstr "模組" -#: ../../faq/programming.rst:2009 +#: ../../faq/programming.rst:2049 msgid "How do I create a .pyc file?" msgstr "" -#: ../../faq/programming.rst:2011 +#: ../../faq/programming.rst:2051 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 " @@ -2124,7 +2164,7 @@ msgid "" "particular ``python`` binary that created it. (See :pep:`3147` for details.)" msgstr "" -#: ../../faq/programming.rst:2019 +#: ../../faq/programming.rst:2059 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 " @@ -2133,7 +2173,7 @@ msgid "" "testing with a web server." msgstr "" -#: ../../faq/programming.rst:2024 +#: ../../faq/programming.rst:2064 msgid "" "Unless the :envvar:`PYTHONDONTWRITEBYTECODE` environment variable is set, " "creation of a .pyc file is automatic if you're importing a module and Python " @@ -2142,7 +2182,7 @@ msgid "" "subdirectory." msgstr "" -#: ../../faq/programming.rst:2029 +#: ../../faq/programming.rst:2069 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." @@ -2152,27 +2192,27 @@ msgid "" "for ``foo`` since ``foo.py`` isn't being imported." msgstr "" -#: ../../faq/programming.rst:2036 +#: ../../faq/programming.rst:2076 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:2040 +#: ../../faq/programming.rst:2080 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:2046 +#: ../../faq/programming.rst:2086 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:2050 +#: ../../faq/programming.rst:2090 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 " @@ -2180,11 +2220,11 @@ msgid "" "Python files to compile::" msgstr "" -#: ../../faq/programming.rst:2059 +#: ../../faq/programming.rst:2099 msgid "How do I find the current module name?" msgstr "" -#: ../../faq/programming.rst:2061 +#: ../../faq/programming.rst:2101 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 " @@ -2193,85 +2233,85 @@ msgid "" "only execute this code after checking ``__name__``::" msgstr "" -#: ../../faq/programming.rst:2076 +#: ../../faq/programming.rst:2116 msgid "How can I have modules that mutually import each other?" msgstr "" -#: ../../faq/programming.rst:2078 +#: ../../faq/programming.rst:2118 msgid "Suppose you have the following modules:" msgstr "" -#: ../../faq/programming.rst:2080 +#: ../../faq/programming.rst:2120 msgid ":file:`foo.py`::" msgstr "" ":file:`foo.py`:\n" "\n" "::" -#: ../../faq/programming.rst:2085 +#: ../../faq/programming.rst:2125 msgid ":file:`bar.py`::" msgstr "" ":file:`bar.py`:\n" "\n" "::" -#: ../../faq/programming.rst:2090 +#: ../../faq/programming.rst:2130 msgid "The problem is that the interpreter will perform the following steps:" msgstr "" -#: ../../faq/programming.rst:2092 +#: ../../faq/programming.rst:2132 msgid "main imports ``foo``" msgstr "" -#: ../../faq/programming.rst:2093 +#: ../../faq/programming.rst:2133 msgid "Empty globals for ``foo`` are created" msgstr "" -#: ../../faq/programming.rst:2094 +#: ../../faq/programming.rst:2134 msgid "``foo`` is compiled and starts executing" msgstr "" -#: ../../faq/programming.rst:2095 +#: ../../faq/programming.rst:2135 msgid "``foo`` imports ``bar``" msgstr "" -#: ../../faq/programming.rst:2096 +#: ../../faq/programming.rst:2136 msgid "Empty globals for ``bar`` are created" msgstr "" -#: ../../faq/programming.rst:2097 +#: ../../faq/programming.rst:2137 msgid "``bar`` is compiled and starts executing" msgstr "" -#: ../../faq/programming.rst:2098 +#: ../../faq/programming.rst:2138 msgid "" "``bar`` imports ``foo`` (which is a no-op since there already is a module " "named ``foo``)" msgstr "" -#: ../../faq/programming.rst:2099 +#: ../../faq/programming.rst:2139 msgid "" "The import mechanism tries to read ``foo_var`` from ``foo`` globals, to set " "``bar.foo_var = foo.foo_var``" msgstr "" -#: ../../faq/programming.rst:2101 +#: ../../faq/programming.rst:2141 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:2104 +#: ../../faq/programming.rst:2144 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:2107 +#: ../../faq/programming.rst:2147 msgid "There are (at least) three possible workarounds for this problem." msgstr "" -#: ../../faq/programming.rst:2109 +#: ../../faq/programming.rst:2149 msgid "" "Guido van Rossum recommends avoiding all uses of ``from import ..." "``, and placing all code inside functions. Initializations of global " @@ -2280,59 +2320,59 @@ msgid "" "``.``." msgstr "" -#: ../../faq/programming.rst:2114 +#: ../../faq/programming.rst:2154 msgid "" "Jim Roskind suggests performing steps in the following order in each module:" msgstr "" -#: ../../faq/programming.rst:2116 +#: ../../faq/programming.rst:2156 msgid "" "exports (globals, functions, and classes that don't need imported base " "classes)" msgstr "" -#: ../../faq/programming.rst:2118 +#: ../../faq/programming.rst:2158 msgid "``import`` statements" msgstr "" -#: ../../faq/programming.rst:2119 +#: ../../faq/programming.rst:2159 msgid "" "active code (including globals that are initialized from imported values)." msgstr "" -#: ../../faq/programming.rst:2121 +#: ../../faq/programming.rst:2161 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:2124 +#: ../../faq/programming.rst:2164 msgid "" "Matthias Urlichs recommends restructuring your code so that the recursive " "import is not necessary in the first place." msgstr "" -#: ../../faq/programming.rst:2127 +#: ../../faq/programming.rst:2167 msgid "These solutions are not mutually exclusive." msgstr "" -#: ../../faq/programming.rst:2131 +#: ../../faq/programming.rst:2171 msgid "__import__('x.y.z') returns ; how do I get z?" msgstr "" -#: ../../faq/programming.rst:2133 +#: ../../faq/programming.rst:2173 msgid "" "Consider using the convenience function :func:`~importlib.import_module` " "from :mod:`importlib` instead::" msgstr "" -#: ../../faq/programming.rst:2140 +#: ../../faq/programming.rst:2180 msgid "" "When I edit an imported module and reimport it, the changes don't show up. " "Why does this happen?" msgstr "" -#: ../../faq/programming.rst:2142 +#: ../../faq/programming.rst:2182 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 " @@ -2341,13 +2381,13 @@ msgid "" "re-reading of a changed module, do this::" msgstr "" -#: ../../faq/programming.rst:2152 +#: ../../faq/programming.rst:2192 msgid "" "Warning: this technique is not 100% fool-proof. In particular, modules " "containing statements like ::" msgstr "" -#: ../../faq/programming.rst:2157 +#: ../../faq/programming.rst:2197 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 " @@ -2355,7 +2395,7 @@ msgid "" "paradoxical behaviour::" msgstr "" -#: ../../faq/programming.rst:2170 +#: ../../faq/programming.rst:2210 msgid "" "The nature of the problem is made clear if you print out the \"identity\" of " "the class objects::" diff --git a/library/functions.po b/library/functions.po index 362b021866..9ad0322d69 100644 --- a/library/functions.po +++ b/library/functions.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.11\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-12-25 00:16+0000\n" +"POT-Creation-Date: 2022-12-29 00:16+0000\n" "PO-Revision-Date: 2022-12-26 23:06+0800\n" "Last-Translator: Phil Lin \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -2915,35 +2915,35 @@ msgstr "" #: ../../library/functions.rst:1921 msgid "" -"Unlike the default behavior, it checks that the lengths of iterables are " -"identical, raising a :exc:`ValueError` if they aren't:" +"Unlike the default behavior, it raises a :exc:`ValueError` if one iterable " +"is exhausted before the others:" msgstr "" -#: ../../library/functions.rst:1929 +#: ../../library/functions.rst:1939 msgid "" "Without the ``strict=True`` argument, any bug that results in iterables of " "different lengths will be silenced, possibly manifesting as a hard-to-find " "bug in another part of the program." msgstr "" -#: ../../library/functions.rst:1933 +#: ../../library/functions.rst:1943 msgid "" "Shorter iterables can be padded with a constant value to make all the " "iterables have the same length. This is done by :func:`itertools." "zip_longest`." msgstr "" -#: ../../library/functions.rst:1937 +#: ../../library/functions.rst:1947 msgid "" "Edge cases: With a single iterable argument, :func:`zip` returns an iterator " "of 1-tuples. With no arguments, it returns an empty iterator." msgstr "" -#: ../../library/functions.rst:1940 +#: ../../library/functions.rst:1950 msgid "Tips and tricks:" msgstr "" -#: ../../library/functions.rst:1942 +#: ../../library/functions.rst:1952 msgid "" "The left-to-right evaluation order of the iterables is guaranteed. This " "makes possible an idiom for clustering a data series into n-length groups " @@ -2952,23 +2952,23 @@ msgid "" "iterator. This has the effect of dividing the input into n-length chunks." msgstr "" -#: ../../library/functions.rst:1948 +#: ../../library/functions.rst:1958 msgid "" ":func:`zip` in conjunction with the ``*`` operator can be used to unzip a " "list::" msgstr "" -#: ../../library/functions.rst:1959 +#: ../../library/functions.rst:1969 msgid "Added the ``strict`` argument." msgstr "增加了 ``strict`` 引數。" -#: ../../library/functions.rst:1971 +#: ../../library/functions.rst:1981 msgid "" "This is an advanced function that is not needed in everyday Python " "programming, unlike :func:`importlib.import_module`." msgstr "" -#: ../../library/functions.rst:1974 +#: ../../library/functions.rst:1984 msgid "" "This function is invoked by the :keyword:`import` statement. It can be " "replaced (by importing the :mod:`builtins` module and assigning to " @@ -2980,7 +2980,7 @@ msgid "" "discouraged in favor of :func:`importlib.import_module`." msgstr "" -#: ../../library/functions.rst:1983 +#: ../../library/functions.rst:1993 msgid "" "The function imports the module *name*, potentially using the given " "*globals* and *locals* to determine how to interpret the name in a package " @@ -2990,7 +2990,7 @@ msgid "" "determine the package context of the :keyword:`import` statement." msgstr "" -#: ../../library/functions.rst:1990 +#: ../../library/functions.rst:2000 msgid "" "*level* specifies whether to use absolute or relative imports. ``0`` (the " "default) means only perform absolute imports. Positive values for *level* " @@ -2999,7 +2999,7 @@ msgid "" "details)." msgstr "" -#: ../../library/functions.rst:1996 +#: ../../library/functions.rst:2006 msgid "" "When the *name* variable is of the form ``package.module``, normally, the " "top-level package (the name up till the first dot) is returned, *not* the " @@ -3007,58 +3007,58 @@ msgid "" "given, the module named by *name* is returned." msgstr "" -#: ../../library/functions.rst:2001 +#: ../../library/functions.rst:2011 msgid "" "For example, the statement ``import spam`` results in bytecode resembling " "the following code::" msgstr "" -#: ../../library/functions.rst:2006 +#: ../../library/functions.rst:2016 msgid "The statement ``import spam.ham`` results in this call::" msgstr "" -#: ../../library/functions.rst:2010 +#: ../../library/functions.rst:2020 msgid "" "Note how :func:`__import__` returns the toplevel module here because this is " "the object that is bound to a name by the :keyword:`import` statement." msgstr "" -#: ../../library/functions.rst:2013 +#: ../../library/functions.rst:2023 msgid "" "On the other hand, the statement ``from spam.ham import eggs, sausage as " "saus`` results in ::" msgstr "" -#: ../../library/functions.rst:2020 +#: ../../library/functions.rst:2030 msgid "" "Here, the ``spam.ham`` module is returned from :func:`__import__`. From " "this object, the names to import are retrieved and assigned to their " "respective names." msgstr "" -#: ../../library/functions.rst:2024 +#: ../../library/functions.rst:2034 msgid "" "If you simply want to import a module (potentially within a package) by " "name, use :func:`importlib.import_module`." msgstr "" -#: ../../library/functions.rst:2027 +#: ../../library/functions.rst:2037 msgid "" "Negative values for *level* are no longer supported (which also changes the " "default value to 0)." msgstr "" -#: ../../library/functions.rst:2031 +#: ../../library/functions.rst:2041 msgid "" "When the command line options :option:`-E` or :option:`-I` are being used, " "the environment variable :envvar:`PYTHONCASEOK` is now ignored." msgstr "" -#: ../../library/functions.rst:2036 +#: ../../library/functions.rst:2046 msgid "Footnotes" msgstr "註解" -#: ../../library/functions.rst:2037 +#: ../../library/functions.rst:2047 msgid "" "Note that the parser only accepts the Unix-style end of line convention. If " "you are reading the code from a file, make sure to use newline conversion " diff --git a/library/pydoc.po b/library/pydoc.po index 2d4bc4fffd..2ff4f04c55 100644 --- a/library/pydoc.po +++ b/library/pydoc.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.11\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-26 16:47+0000\n" +"POT-Creation-Date: 2022-12-30 00:15+0000\n" "PO-Revision-Date: 2015-12-09 17:51+0000\n" "Last-Translator: Liang-Bo Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -99,27 +99,27 @@ msgstr "" msgid "" "You can also use :program:`pydoc` to start an HTTP server on the local " "machine that will serve documentation to visiting web browsers. :program:" -"`pydoc -p 1234` will start a HTTP server on port 1234, allowing you to " -"browse the documentation at ``http://localhost:1234/`` in your preferred web " -"browser. Specifying ``0`` as the port number will select an arbitrary unused " -"port." +"`python -m pydoc -p 1234` will start a HTTP server on port 1234, allowing " +"you to browse the documentation at ``http://localhost:1234/`` in your " +"preferred web browser. Specifying ``0`` as the port number will select an " +"arbitrary unused port." msgstr "" #: ../../library/pydoc.rst:73 msgid "" -":program:`pydoc -n ` will start the server listening at the given " -"hostname. By default the hostname is 'localhost' but if you want the server " -"to be reached from other machines, you may want to change the host name that " -"the server responds to. During development this is especially useful if you " -"want to run pydoc from within a container." +":program:`python -m pydoc -n ` will start the server listening at " +"the given hostname. By default the hostname is 'localhost' but if you want " +"the server to be reached from other machines, you may want to change the " +"host name that the server responds to. During development this is " +"especially useful if you want to run pydoc from within a container." msgstr "" #: ../../library/pydoc.rst:79 msgid "" -":program:`pydoc -b` will start the server and additionally open a web " -"browser to a module index page. Each served page has a navigation bar at " -"the top where you can *Get* help on an individual item, *Search* all modules " -"with a keyword in their synopsis line, and go to the *Module index*, " +":program:`python -m pydoc -b` will start the server and additionally open a " +"web browser to a module index page. Each served page has a navigation bar " +"at the top where you can *Get* help on an individual item, *Search* all " +"modules with a keyword in their synopsis line, and go to the *Module index*, " "*Topics* and *Keywords* pages." msgstr "" diff --git a/tutorial/introduction.po b/tutorial/introduction.po index 570d1d93a5..efbc82663e 100644 --- a/tutorial/introduction.po +++ b/tutorial/introduction.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.11\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-10-11 00:23+0000\n" +"POT-Creation-Date: 2022-12-29 00:16+0000\n" "PO-Revision-Date: 2022-10-16 03:20+0800\n" "Last-Translator: Steven Hsu \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -209,8 +209,8 @@ msgid "" "to escape quotes::" msgstr "" "除了數字之外,Python 也可以操作字串,而表達字串有數種方式。它們可以用包含在單" -"引號 (``'...'``) 或雙引號 (``\"...\"``) 之中,兩者會得到相同的結果\\ [#]_" -"\\ 。使用 ``\\`` 跳脫出現於字串中的引號:\n" +"引號 (``'...'``) 或雙引號 (``\"...\"``) 之中,兩者會得到相同的結果\\ " +"[#]_\\ 。使用 ``\\`` 跳脫出現於字串中的引號:\n" "\n" "::" @@ -246,24 +246,31 @@ msgstr "" #: ../../tutorial/introduction.rst:192 msgid "" -"String literals can span multiple lines. One way is using triple-quotes: ``" -"\"\"\"...\"\"\"`` or ``'''...'''``. End of lines are automatically included " -"in the string, but it's possible to prevent this by adding a ``\\`` at the " -"end of the line. The following example::" +"There is one subtle aspect to raw strings: a raw string may not end in an " +"odd number of ``\\`` characters; see :ref:`the FAQ entry ` for more information and workarounds." +msgstr "" + +#: ../../tutorial/introduction.rst:197 +msgid "" +"String literals can span multiple lines. One way is using triple-quotes: " +"``\"\"\"...\"\"\"`` or ``'''...'''``. End of lines are automatically " +"included in the string, but it's possible to prevent this by adding a ``\\`` " +"at the end of the line. The following example::" msgstr "" "字串文本可以跨越數行。其中一方式是使用三個重覆引號:\\ ``\"\"\"...\"\"\"`` " -"或 ``'''...'''``\\ 。此時換行會被自動加入字串值中,但也可以在換行前加入 ``" -"\\`` 來取消這個行為。在以下的例子中:\n" +"或 ``'''...'''``\\ 。此時換行會被自動加入字串值中,但也可以在換行前加入 " +"``\\`` 來取消這個行為。在以下的例子中:\n" "\n" "::" -#: ../../tutorial/introduction.rst:203 +#: ../../tutorial/introduction.rst:208 msgid "" "produces the following output (note that the initial newline is not " "included):" msgstr "會產生以下的輸出(注意第一個換行並沒有被包含進字串值中):" -#: ../../tutorial/introduction.rst:211 +#: ../../tutorial/introduction.rst:216 msgid "" "Strings can be concatenated (glued together) with the ``+`` operator, and " "repeated with ``*``::" @@ -272,7 +279,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:218 +#: ../../tutorial/introduction.rst:223 msgid "" "Two or more *string literals* (i.e. the ones enclosed between quotes) next " "to each other are automatically concatenated. ::" @@ -282,7 +289,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:224 +#: ../../tutorial/introduction.rst:229 msgid "" "This feature is particularly useful when you want to break long strings::" msgstr "" @@ -290,7 +297,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:231 +#: ../../tutorial/introduction.rst:236 msgid "" "This only works with two literals though, not with variables or expressions::" msgstr "" @@ -298,7 +305,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:245 +#: ../../tutorial/introduction.rst:250 msgid "" "If you want to concatenate variables or a variable and a literal, use ``+``::" msgstr "" @@ -306,7 +313,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:250 +#: ../../tutorial/introduction.rst:255 msgid "" "Strings can be *indexed* (subscripted), with the first character having " "index 0. There is no separate character type; a character is simply a string " @@ -317,7 +324,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:260 +#: ../../tutorial/introduction.rst:265 msgid "" "Indices may also be negative numbers, to start counting from the right::" msgstr "" @@ -325,11 +332,11 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:269 +#: ../../tutorial/introduction.rst:274 msgid "Note that since -0 is the same as 0, negative indices start from -1." msgstr "注意到因為 -0 等同於 0,負的索引值由 -1 開始。" -#: ../../tutorial/introduction.rst:271 +#: ../../tutorial/introduction.rst:276 msgid "" "In addition to indexing, *slicing* is also supported. While indexing is " "used to obtain individual characters, *slicing* allows you to obtain " @@ -340,7 +347,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:279 +#: ../../tutorial/introduction.rst:284 msgid "" "Slice indices have useful defaults; an omitted first index defaults to zero, " "an omitted second index defaults to the size of the string being sliced. ::" @@ -350,7 +357,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:289 +#: ../../tutorial/introduction.rst:294 msgid "" "Note how the start is always included, and the end always excluded. This " "makes sure that ``s[:i] + s[i:]`` is always equal to ``s``::" @@ -360,7 +367,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:297 +#: ../../tutorial/introduction.rst:302 msgid "" "One way to remember how slices work is to think of the indices as pointing " "*between* characters, with the left edge of the first character numbered 0. " @@ -373,7 +380,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:308 +#: ../../tutorial/introduction.rst:313 msgid "" "The first row of numbers gives the position of the indices 0...6 in the " "string; the second row gives the corresponding negative indices. The slice " @@ -383,7 +390,7 @@ msgstr "" "第一行數字給定字串索引值為 0...6 的位置;第二行則標示了負索引值的位置。由 " "*i* 至 *j* 的 slice 包含了標示 *i* 和 *j* 邊緣間的所有字元。" -#: ../../tutorial/introduction.rst:313 +#: ../../tutorial/introduction.rst:318 msgid "" "For non-negative indices, the length of a slice is the difference of the " "indices, if both are within bounds. For example, the length of " @@ -392,14 +399,14 @@ msgstr "" "對非負數的索引值而言,一個 slice 的長度等於其索引值之差,如果索引值落在字串邊" "界內。例如,``word[1:3]`` 的長度是 2。" -#: ../../tutorial/introduction.rst:317 +#: ../../tutorial/introduction.rst:322 msgid "Attempting to use an index that is too large will result in an error::" msgstr "" "嘗試使用一個過大的索引值會造成錯誤:\n" "\n" "::" -#: ../../tutorial/introduction.rst:324 +#: ../../tutorial/introduction.rst:329 msgid "" "However, out of range slice indexes are handled gracefully when used for " "slicing::" @@ -408,7 +415,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:332 +#: ../../tutorial/introduction.rst:337 msgid "" "Python strings cannot be changed --- they are :term:`immutable`. Therefore, " "assigning to an indexed position in the string results in an error::" @@ -418,61 +425,61 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:344 +#: ../../tutorial/introduction.rst:349 msgid "If you need a different string, you should create a new one::" msgstr "" "如果你需要一個不一樣的字串,你必須建立一個新的:\n" "\n" "::" -#: ../../tutorial/introduction.rst:351 +#: ../../tutorial/introduction.rst:356 msgid "The built-in function :func:`len` returns the length of a string::" msgstr "" "內建的函式 :func:`len` 回傳一個字串的長度:\n" "\n" "::" -#: ../../tutorial/introduction.rst:362 +#: ../../tutorial/introduction.rst:367 msgid ":ref:`textseq`" msgstr ":ref:`textseq`" -#: ../../tutorial/introduction.rst:361 +#: ../../tutorial/introduction.rst:366 msgid "" "Strings are examples of *sequence types*, and support the common operations " "supported by such types." msgstr "字串是 *sequence 型別*\\ 的範例之一,並支援該型別常用的操作。" -#: ../../tutorial/introduction.rst:366 +#: ../../tutorial/introduction.rst:371 msgid ":ref:`string-methods`" msgstr ":ref:`string-methods`" -#: ../../tutorial/introduction.rst:365 +#: ../../tutorial/introduction.rst:370 msgid "" "Strings support a large number of methods for basic transformations and " "searching." msgstr "字串支援非常多種基本轉換和搜尋的 method(方法)。" -#: ../../tutorial/introduction.rst:369 +#: ../../tutorial/introduction.rst:374 msgid ":ref:`f-strings`" msgstr ":ref:`f-strings`" -#: ../../tutorial/introduction.rst:369 +#: ../../tutorial/introduction.rst:374 msgid "String literals that have embedded expressions." msgstr "包含有運算式的字串文本。" -#: ../../tutorial/introduction.rst:372 +#: ../../tutorial/introduction.rst:377 msgid ":ref:`formatstrings`" msgstr ":ref:`formatstrings`" -#: ../../tutorial/introduction.rst:372 +#: ../../tutorial/introduction.rst:377 msgid "Information about string formatting with :meth:`str.format`." msgstr "關於透過 :meth:`str.format` 字串格式化 (string formatting) 的資訊。" -#: ../../tutorial/introduction.rst:375 +#: ../../tutorial/introduction.rst:380 msgid ":ref:`old-string-formatting`" msgstr ":ref:`old-string-formatting`" -#: ../../tutorial/introduction.rst:375 +#: ../../tutorial/introduction.rst:380 msgid "" "The old formatting operations invoked when strings are the left operand of " "the ``%`` operator are described in more detail here." @@ -480,11 +487,11 @@ msgstr "" "在字串為 ``%`` 運算子的左運算元時,將觸發舊的字串格式化操作,更多的細節在本連" "結中介紹。" -#: ../../tutorial/introduction.rst:382 +#: ../../tutorial/introduction.rst:387 msgid "Lists" msgstr "List(串列)" -#: ../../tutorial/introduction.rst:384 +#: ../../tutorial/introduction.rst:389 msgid "" "Python knows a number of *compound* data types, used to group together other " "values. The most versatile is the *list*, which can be written as a list of " @@ -497,7 +504,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:393 +#: ../../tutorial/introduction.rst:398 msgid "" "Like strings (and all other built-in :term:`sequence` types), lists can be " "indexed and sliced::" @@ -507,7 +514,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:403 +#: ../../tutorial/introduction.rst:408 msgid "" "All slice operations return a new list containing the requested elements. " "This means that the following slice returns a :ref:`shallow copy " @@ -518,14 +525,14 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:410 +#: ../../tutorial/introduction.rst:415 msgid "Lists also support operations like concatenation::" msgstr "" "List 對支援如接合 (concatenation) 等操作:\n" "\n" "::" -#: ../../tutorial/introduction.rst:415 +#: ../../tutorial/introduction.rst:420 msgid "" "Unlike strings, which are :term:`immutable`, lists are a :term:`mutable` " "type, i.e. it is possible to change their content::" @@ -535,7 +542,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:425 +#: ../../tutorial/introduction.rst:430 msgid "" "You can also add new items at the end of the list, by using the :meth:`~list." "append` *method* (we will see more about methods later)::" @@ -545,7 +552,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:433 +#: ../../tutorial/introduction.rst:438 msgid "" "Assignment to slices is also possible, and this can even change the size of " "the list or clear it entirely::" @@ -554,14 +561,14 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:452 +#: ../../tutorial/introduction.rst:457 msgid "The built-in function :func:`len` also applies to lists::" msgstr "" "內建的函式 :func:`len` 亦可以作用在 list 上:\n" "\n" "::" -#: ../../tutorial/introduction.rst:458 +#: ../../tutorial/introduction.rst:463 msgid "" "It is possible to nest lists (create lists containing other lists), for " "example::" @@ -570,11 +577,11 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:474 +#: ../../tutorial/introduction.rst:479 msgid "First Steps Towards Programming" msgstr "初探程式設計的前幾步" -#: ../../tutorial/introduction.rst:476 +#: ../../tutorial/introduction.rst:481 msgid "" "Of course, we can use Python for more complicated tasks than adding two and " "two together. For instance, we can write an initial sub-sequence of the " @@ -587,11 +594,11 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:496 +#: ../../tutorial/introduction.rst:501 msgid "This example introduces several new features." msgstr "這例子引入了許多新的特性。" -#: ../../tutorial/introduction.rst:498 +#: ../../tutorial/introduction.rst:503 msgid "" "The first line contains a *multiple assignment*: the variables ``a`` and " "``b`` simultaneously get the new values 0 and 1. On the last line this is " @@ -603,7 +610,7 @@ msgstr "" "同樣的賦值再被使用了一次,示範了等號的右項運算 (expression) 會先被計算 " "(evaluate),賦值再發生。右項的運算式由左至右依序被計算。" -#: ../../tutorial/introduction.rst:504 +#: ../../tutorial/introduction.rst:509 msgid "" "The :keyword:`while` loop executes as long as the condition (here: ``a < " "10``) remains true. In Python, like in C, any non-zero integer value is " @@ -622,7 +629,7 @@ msgstr "" "``==``\\ (等於)、\\ ``<=``\\ (小於等於)、\\ ``>=``\\ (大於等於)以及 ``!" "=``\\ (不等於)。" -#: ../../tutorial/introduction.rst:513 +#: ../../tutorial/introduction.rst:518 msgid "" "The *body* of the loop is *indented*: indentation is Python's way of " "grouping statements. At the interactive prompt, you have to type a tab or " @@ -640,7 +647,7 @@ msgstr "" "法剖析器無法判斷你何時輸入複合陳述的最後一行)。注意在一個縮排段落內的縮排方" "式與數量必須維持一致。" -#: ../../tutorial/introduction.rst:522 +#: ../../tutorial/introduction.rst:527 msgid "" "The :func:`print` function writes the value of the argument(s) it is given. " "It differs from just writing the expression you want to write (as we did " @@ -656,7 +663,7 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:533 +#: ../../tutorial/introduction.rst:538 msgid "" "The keyword argument *end* can be used to avoid the newline after the " "output, or end the output with a different string::" @@ -666,21 +673,21 @@ msgstr "" "\n" "::" -#: ../../tutorial/introduction.rst:545 +#: ../../tutorial/introduction.rst:550 msgid "Footnotes" msgstr "註解" -#: ../../tutorial/introduction.rst:546 +#: ../../tutorial/introduction.rst:551 msgid "" "Since ``**`` has higher precedence than ``-``, ``-3**2`` will be interpreted " "as ``-(3**2)`` and thus result in ``-9``. To avoid this and get ``9``, you " "can use ``(-3)**2``." msgstr "" "因為 ``**`` 擁有較 ``-`` 高的優先次序,\\ ``-3**2`` 會被解釋為 ``-(3**2)`` 並" -"得到 ``-9``\\ 。如果要避免這樣的優先順序以得到 ``9``,你可以使用 ``(-3)**2``" -"\\ 。" +"得到 ``-9``\\ 。如果要避免這樣的優先順序以得到 ``9``,你可以使用 " +"``(-3)**2``\\ 。" -#: ../../tutorial/introduction.rst:550 +#: ../../tutorial/introduction.rst:555 msgid "" "Unlike other languages, special characters such as ``\\n`` have the same " "meaning with both single (``'...'``) and double (``\"...\"``) quotes. The "