diff --git a/c-api/frame.po b/c-api/frame.po index 80c27bccfc2..362d78c8340 100644 --- a/c-api/frame.po +++ b/c-api/frame.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-11-11 00:15+0000\n" +"POT-Creation-Date: 2026-02-28 00:16+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -76,81 +76,83 @@ msgid "Get the *frame* next outer frame." msgstr "" #: ../../c-api/frame.rst:51 +#, fuzzy msgid "" -"Return a :term:`strong reference`, or ``NULL`` if *frame* has no outer frame." -msgstr "" +"Return a :term:`strong reference`, or ``NULL`` if *frame* has no outer " +"frame. This raises no exceptions." +msgstr "回傳 :term:`strong reference` 或 ``NULL``。" -#: ../../c-api/frame.rst:59 +#: ../../c-api/frame.rst:60 msgid "Get the *frame*'s :attr:`~frame.f_builtins` attribute." msgstr "取得 *frame* 的 :attr:`~frame.f_builtins` 屬性。" -#: ../../c-api/frame.rst:61 ../../c-api/frame.rst:92 +#: ../../c-api/frame.rst:62 ../../c-api/frame.rst:93 msgid "Return a :term:`strong reference`. The result cannot be ``NULL``." msgstr "回傳 :term:`strong reference`。結果不能為 ``NULL``。" -#: ../../c-api/frame.rst:68 +#: ../../c-api/frame.rst:69 msgid "Get the *frame* code." msgstr "" -#: ../../c-api/frame.rst:70 ../../c-api/frame.rst:136 +#: ../../c-api/frame.rst:71 ../../c-api/frame.rst:137 msgid "Return a :term:`strong reference`." msgstr "回傳 :term:`strong reference`。" -#: ../../c-api/frame.rst:72 +#: ../../c-api/frame.rst:73 msgid "The result (frame code) cannot be ``NULL``." msgstr "" -#: ../../c-api/frame.rst:79 +#: ../../c-api/frame.rst:80 msgid "" "Get the generator, coroutine, or async generator that owns this frame, or " "``NULL`` if this frame is not owned by a generator. Does not raise an " "exception, even if the return value is ``NULL``." msgstr "" -#: ../../c-api/frame.rst:83 +#: ../../c-api/frame.rst:84 msgid "Return a :term:`strong reference`, or ``NULL``." msgstr "回傳 :term:`strong reference` 或 ``NULL``。" -#: ../../c-api/frame.rst:90 +#: ../../c-api/frame.rst:91 msgid "Get the *frame*'s :attr:`~frame.f_globals` attribute." msgstr "取得 *frame* 的 :attr:`~frame.f_globals` 屬性。" -#: ../../c-api/frame.rst:99 +#: ../../c-api/frame.rst:100 msgid "Get the *frame*'s :attr:`~frame.f_lasti` attribute." msgstr "取得 *frame* 的 :attr:`~frame.f_lasti` 屬性。" -#: ../../c-api/frame.rst:101 +#: ../../c-api/frame.rst:102 msgid "Returns -1 if ``frame.f_lasti`` is ``None``." msgstr "如果 ``frame.f_lasti`` 是 ``None`` 則回傳 -1。" -#: ../../c-api/frame.rst:108 +#: ../../c-api/frame.rst:109 msgid "Get the variable *name* of *frame*." msgstr "取得 *frame* 的變數 *name*。" -#: ../../c-api/frame.rst:110 +#: ../../c-api/frame.rst:111 msgid "Return a :term:`strong reference` to the variable value on success." msgstr "在成功時回傳變數值的 :term:`strong reference`。" -#: ../../c-api/frame.rst:111 +#: ../../c-api/frame.rst:112 msgid "" "Raise :exc:`NameError` and return ``NULL`` if the variable does not exist." msgstr "如果變數不存在,則引發 :exc:`NameError` 並回傳 ``NULL``。" -#: ../../c-api/frame.rst:112 +#: ../../c-api/frame.rst:113 msgid "Raise an exception and return ``NULL`` on error." msgstr "在錯誤時引發例外並回傳 ``NULL``。" -#: ../../c-api/frame.rst:114 +#: ../../c-api/frame.rst:115 msgid "*name* type must be a :class:`str`." msgstr "*name* 的型別必須是 :class:`str`。" -#: ../../c-api/frame.rst:121 +#: ../../c-api/frame.rst:122 msgid "" "Similar to :c:func:`PyFrame_GetVar`, but the variable name is a C string " "encoded in UTF-8." msgstr "" -#: ../../c-api/frame.rst:129 +#: ../../c-api/frame.rst:130 msgid "" "Get the *frame*'s :attr:`~frame.f_locals` attribute. If the frame refers to " "an :term:`optimized scope`, this returns a write-through proxy object that " @@ -159,21 +161,21 @@ msgid "" "directly (as described for :func:`locals`)." msgstr "" -#: ../../c-api/frame.rst:140 +#: ../../c-api/frame.rst:141 msgid "" "As part of :pep:`667`, return an instance of :c:var:" "`PyFrameLocalsProxy_Type`." msgstr "" -#: ../../c-api/frame.rst:146 +#: ../../c-api/frame.rst:147 msgid "Return the line number that *frame* is currently executing." msgstr "" -#: ../../c-api/frame.rst:150 +#: ../../c-api/frame.rst:151 msgid "Frame Locals Proxies" msgstr "" -#: ../../c-api/frame.rst:154 +#: ../../c-api/frame.rst:155 msgid "" "The :attr:`~frame.f_locals` attribute on a :ref:`frame object ` is an instance of a \"frame-locals proxy\". The proxy object " @@ -182,34 +184,34 @@ msgid "" "to date with the live local variables in the frame itself." msgstr "" -#: ../../c-api/frame.rst:160 +#: ../../c-api/frame.rst:161 msgid "See :pep:`667` for more information." msgstr "更多資訊請參閱 :pep:`667`。" -#: ../../c-api/frame.rst:164 +#: ../../c-api/frame.rst:165 msgid "The type of frame :func:`locals` proxy objects." msgstr "" -#: ../../c-api/frame.rst:168 +#: ../../c-api/frame.rst:169 msgid "Return non-zero if *obj* is a frame :func:`locals` proxy." msgstr "" -#: ../../c-api/frame.rst:172 +#: ../../c-api/frame.rst:173 msgid "Legacy Local Variable APIs" msgstr "" -#: ../../c-api/frame.rst:174 +#: ../../c-api/frame.rst:175 msgid "" "These APIs are :term:`soft deprecated`. As of Python 3.13, they do nothing. " "They exist solely for backwards compatibility." msgstr "" -#: ../../c-api/frame.rst:180 ../../c-api/frame.rst:194 -#: ../../c-api/frame.rst:207 +#: ../../c-api/frame.rst:181 ../../c-api/frame.rst:195 +#: ../../c-api/frame.rst:208 msgid "This function is :term:`soft deprecated` and does nothing." msgstr "" -#: ../../c-api/frame.rst:182 +#: ../../c-api/frame.rst:183 msgid "" "Prior to Python 3.13, this function would copy the :attr:`~frame.f_locals` " "attribute of *f* to the internal \"fast\" array of local variables, allowing " @@ -218,12 +220,12 @@ msgid "" "dictionary." msgstr "" -#: ../../c-api/frame.rst:188 ../../c-api/frame.rst:201 -#: ../../c-api/frame.rst:213 +#: ../../c-api/frame.rst:189 ../../c-api/frame.rst:202 +#: ../../c-api/frame.rst:214 msgid "This function now does nothing." msgstr "" -#: ../../c-api/frame.rst:196 +#: ../../c-api/frame.rst:197 msgid "" "Prior to Python 3.13, this function would copy the internal \"fast\" array " "of local variables (which is used by the interpreter) to the :attr:`~frame." @@ -231,38 +233,38 @@ msgid "" "visible to frame objects." msgstr "" -#: ../../c-api/frame.rst:209 +#: ../../c-api/frame.rst:210 msgid "" "Prior to Python 3.13, this function was similar to :c:func:" "`PyFrame_FastToLocals`, but would return ``0`` on success, and ``-1`` with " "an exception set on failure." msgstr "" -#: ../../c-api/frame.rst:218 +#: ../../c-api/frame.rst:219 msgid ":pep:`667`" msgstr ":pep:`667`" -#: ../../c-api/frame.rst:222 +#: ../../c-api/frame.rst:223 msgid "Internal Frames" msgstr "" -#: ../../c-api/frame.rst:224 +#: ../../c-api/frame.rst:225 msgid "Unless using :pep:`523`, you will not need this." msgstr "" -#: ../../c-api/frame.rst:228 +#: ../../c-api/frame.rst:229 msgid "The interpreter's internal frame representation." msgstr "" -#: ../../c-api/frame.rst:234 +#: ../../c-api/frame.rst:235 msgid "Return a :term:`strong reference` to the code object for the frame." msgstr "" -#: ../../c-api/frame.rst:241 +#: ../../c-api/frame.rst:242 msgid "Return the byte offset into the last executed instruction." msgstr "" -#: ../../c-api/frame.rst:248 +#: ../../c-api/frame.rst:249 msgid "" "Return the currently executing line number, or -1 if there is no line number." msgstr "" diff --git a/c-api/interp-lifecycle.po b/c-api/interp-lifecycle.po index 2c517d8bfbd..461fff3d79b 100644 --- a/c-api/interp-lifecycle.po +++ b/c-api/interp-lifecycle.po @@ -7,10 +7,11 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-24 00:20+0000\n" +"POT-Creation-Date: 2026-02-26 18:22+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" -"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-tw)\n" +"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" +"tw)\n" "Language: zh_TW\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -24,7 +25,9 @@ msgstr "直譯器的初始化與終結化" msgid "" "See :ref:`Python Initialization Configuration ` for details on " "how to configure the interpreter prior to initialization." -msgstr "關於如何在初始化之前設定直譯器的細節,請參見 :ref:`Python 初始化設定 `。" +msgstr "" +"關於如何在初始化之前設定直譯器的細節,請參見 :ref:`Python 初始化設定 `。" #: ../../c-api/interp-lifecycle.rst:14 msgid "Before Python initialization" @@ -273,7 +276,8 @@ msgstr "" msgid "" "Set by the :option:`-B` option and the :envvar:`PYTHONDONTWRITEBYTECODE` " "environment variable." -msgstr "由 :option:`-B` 選項與 :envvar:`PYTHONDONTWRITEBYTECODE` 環境變數設定。" +msgstr "" +"由 :option:`-B` 選項與 :envvar:`PYTHONDONTWRITEBYTECODE` 環境變數設定。" #: ../../c-api/interp-lifecycle.rst:142 msgid "" @@ -297,7 +301,8 @@ msgstr "" msgid "" "Set to ``1`` if the :envvar:`PYTHONHASHSEED` environment variable is set to " "a non-empty string." -msgstr "如果環境變數 :envvar:`PYTHONHASHSEED` 被設定為一個非空字串則設為 ``1``。" +msgstr "" +"如果環境變數 :envvar:`PYTHONHASHSEED` 被設定為一個非空字串則設為 ``1``。" #: ../../c-api/interp-lifecycle.rst:161 msgid "" @@ -317,8 +322,8 @@ msgid "" "Ignore all :envvar:`!PYTHON*` environment variables, e.g. :envvar:" "`PYTHONPATH` and :envvar:`PYTHONHOME`, that might be set." msgstr "" -"忽略所有可能被設定的 :envvar:`!PYTHON*` 環境變數,例如 :envvar:`PYTHONPATH` 與 " -":envvar:`PYTHONHOME`。" +"忽略所有可能被設定的 :envvar:`!PYTHON*` 環境變數,例如 :envvar:`PYTHONPATH` " +"與 :envvar:`PYTHONHOME`。" #: ../../c-api/interp-lifecycle.rst:176 msgid "Set by the :option:`-E` and :option:`-I` options." @@ -390,7 +395,9 @@ msgstr "" msgid "" "Set to ``1`` if the :envvar:`PYTHONLEGACYWINDOWSFSENCODING` environment " "variable is set to a non-empty string." -msgstr "如果環境變數 :envvar:`PYTHONLEGACYWINDOWSFSENCODING` 被設定為一個非空字串則設為 ``1``。" +msgstr "" +"如果環境變數 :envvar:`PYTHONLEGACYWINDOWSFSENCODING` 被設定為一個非空字串則設" +"為 ``1``。" #: ../../c-api/interp-lifecycle.rst:237 msgid "See :pep:`529` for more details." @@ -459,7 +466,9 @@ msgstr "" msgid "" "Set by the :option:`-s` and :option:`-I` options, and the :envvar:" "`PYTHONNOUSERSITE` environment variable." -msgstr "由 :option:`-s` 選項、:option:`-I` 選項與 :envvar:`PYTHONNOUSERSITE` 環境變數設定。" +msgstr "" +"由 :option:`-s` 選項、:option:`-I` 選項與 :envvar:`PYTHONNOUSERSITE` 環境變數" +"設定。" #: ../../c-api/interp-lifecycle.rst:296 msgid "" @@ -663,7 +672,9 @@ msgstr "" msgid "" "Raises an :ref:`auditing event ` ``cpython." "_PySys_ClearAuditHooks`` with no arguments." -msgstr "引發一個不附帶引數的\\ :ref:`稽核事件 ` ``cpython._PySys_ClearAuditHooks``。" +msgstr "" +"引發一個不附帶引數的\\ :ref:`稽核事件 ` ``cpython." +"_PySys_ClearAuditHooks``。" #: ../../c-api/interp-lifecycle.rst:476 msgid "" @@ -1143,6 +1154,52 @@ msgid "" "`Python Initialization Configuration `." msgstr "" +#: ../../c-api/interp-lifecycle.rst:906 +msgid "" +"This function works like :c:func:`PySys_SetArgvEx` with *updatepath* set to " +"``1`` unless the :program:`python` interpreter was started with the :option:" +"`-I`." +msgstr "" + +#: ../../c-api/interp-lifecycle.rst:916 +msgid "The *updatepath* value depends on :option:`-I`." +msgstr "" + +#: ../../c-api/interp-lifecycle.rst:923 +msgid "" +"This API is kept for backward compatibility: setting :c:member:`PyConfig." +"home` should be used instead, see :ref:`Python Initialization Configuration " +"`." +msgstr "" + +#: ../../c-api/interp-lifecycle.rst:927 +msgid "" +"Set the default \"home\" directory, that is, the location of the standard " +"Python libraries. See :envvar:`PYTHONHOME` for the meaning of the argument " +"string." +msgstr "" + +#: ../../c-api/interp-lifecycle.rst:931 +msgid "" +"The argument should point to a zero-terminated character string in static " +"storage whose contents will not change for the duration of the program's " +"execution. No code in the Python interpreter will change the contents of " +"this storage." +msgstr "" + +#: ../../c-api/interp-lifecycle.rst:944 +msgid "" +"Return the default \"home\", that is, the value set by :c:member:`PyConfig." +"home`, or the value of the :envvar:`PYTHONHOME` environment variable if it " +"is set." +msgstr "" + +#: ../../c-api/interp-lifecycle.rst:954 +msgid "" +"Use :c:func:`PyConfig_Get(\"home\") ` or the :envvar:" +"`PYTHONHOME` environment variable instead." +msgstr "" + #: ../../c-api/interp-lifecycle.rst:357 msgid "PyEval_InitThreads()" msgstr "PyEval_InitThreads()" diff --git a/c-api/threads.po b/c-api/threads.po index de6956663d2..2c0624f6b35 100644 --- a/c-api/threads.po +++ b/c-api/threads.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-24 00:20+0000\n" +"POT-Creation-Date: 2026-03-11 00:16+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -23,96 +23,120 @@ msgstr "執行緒狀態與全域直譯器鎖" #: ../../c-api/threads.rst:13 msgid "" -"Unless on a :term:`free-threaded ` build of :term:`CPython`, " -"the Python interpreter is not fully thread-safe. In order to support multi-" +"Unless on a :term:`free-threaded build` of :term:`CPython`, the Python " +"interpreter is generally not thread-safe. In order to support multi-" "threaded Python programs, there's a global lock, called the :term:`global " -"interpreter lock` or :term:`GIL`, that must be held by the current thread " -"before it can safely access Python objects. Without the lock, even the " -"simplest operations could cause problems in a multi-threaded program: for " -"example, when two threads simultaneously increment the reference count of " -"the same object, the reference count could end up being incremented only " -"once instead of twice." +"interpreter lock` or :term:`GIL`, that must be held by a thread before " +"accessing Python objects. Without the lock, even the simplest operations " +"could cause problems in a multi-threaded program: for example, when two " +"threads simultaneously increment the reference count of the same object, the " +"reference count could end up being incremented only once instead of twice." msgstr "" -#: ../../c-api/threads.rst:24 +#: ../../c-api/threads.rst:22 msgid "" -"Therefore, the rule exists that only the thread that has acquired the :term:" -"`GIL` may operate on Python objects or call Python/C API functions. In order " -"to emulate concurrency of execution, the interpreter regularly tries to " -"switch threads (see :func:`sys.setswitchinterval`). The lock is also " -"released around potentially blocking I/O operations like reading or writing " -"a file, so that other Python threads can run in the meantime." +"As such, only a thread that holds the GIL may operate on Python objects or " +"invoke Python's C API." msgstr "" -#: ../../c-api/threads.rst:34 +#: ../../c-api/threads.rst:27 msgid "" -"The Python interpreter keeps some thread-specific bookkeeping information " -"inside a data structure called :c:type:`PyThreadState`, known as a :term:" -"`thread state`. Each OS thread has a thread-local pointer to a :c:type:" -"`PyThreadState`; a thread state referenced by this pointer is considered to " -"be :term:`attached `." +"In order to emulate concurrency, the interpreter regularly tries to switch " +"threads between bytecode instructions (see :func:`sys.setswitchinterval`). " +"This is why locks are also necessary for thread-safety in pure-Python code." +msgstr "" + +#: ../../c-api/threads.rst:31 +msgid "" +"Additionally, the global interpreter lock is released around blocking I/O " +"operations, such as reading or writing to a file. From the C API, this is " +"done by :ref:`detaching the thread state `." msgstr "" #: ../../c-api/threads.rst:39 msgid "" +"The Python interpreter keeps some thread-local information inside a data " +"structure called :c:type:`PyThreadState`, known as a :term:`thread state`. " +"Each thread has a thread-local pointer to a :c:type:`PyThreadState`; a " +"thread state referenced by this pointer is considered to be :term:`attached " +"`." +msgstr "" + +#: ../../c-api/threads.rst:44 +msgid "" "A thread can only have one :term:`attached thread state` at a time. An " -"attached thread state is typically analogous with holding the :term:`GIL`, " -"except on :term:`free-threaded ` builds. On builds with " -"the :term:`GIL` enabled, :term:`attaching ` a thread " -"state will block until the :term:`GIL` can be acquired. However, even on " -"builds with the :term:`GIL` disabled, it is still required to have an " -"attached thread state to call most of the C API." +"attached thread state is typically analogous with holding the GIL, except on " +"free-threaded builds. On builds with the GIL enabled, attaching a thread " +"state will block until the GIL can be acquired. However, even on builds with " +"the GIL disabled, it is still required to have an attached thread state, as " +"the interpreter needs to keep track of which threads may access Python " +"objects." msgstr "" -#: ../../c-api/threads.rst:46 +#: ../../c-api/threads.rst:53 msgid "" -"In general, there will always be an :term:`attached thread state` when using " -"Python's C API. Only in some specific cases (such as in a :c:macro:" -"`Py_BEGIN_ALLOW_THREADS` block) will the thread not have an attached thread " -"state. If uncertain, check if :c:func:`PyThreadState_GetUnchecked` returns " -"``NULL``." +"Even on the free-threaded build, attaching a thread state may block, as the " +"GIL can be re-enabled or threads might be temporarily suspended (such as " +"during a garbage collection)." msgstr "" -#: ../../c-api/threads.rst:52 +#: ../../c-api/threads.rst:57 +msgid "" +"Generally, there will always be an attached thread state when using Python's " +"C API, including during embedding and when implementing methods, so it's " +"uncommon to need to set up a thread state on your own. Only in some specific " +"cases, such as in a :c:macro:`Py_BEGIN_ALLOW_THREADS` block or in a fresh " +"thread, will the thread not have an attached thread state. If uncertain, " +"check if :c:func:`PyThreadState_GetUnchecked` returns ``NULL``." +msgstr "" + +#: ../../c-api/threads.rst:64 +msgid "" +"If it turns out that you do need to create a thread state, call :c:func:" +"`PyThreadState_New` followed by :c:func:`PyThreadState_Swap`, or use the " +"dangerous :c:func:`PyGILState_Ensure` function." +msgstr "" + +#: ../../c-api/threads.rst:72 msgid "Detaching the thread state from extension code" msgstr "" -#: ../../c-api/threads.rst:54 +#: ../../c-api/threads.rst:74 msgid "" "Most extension code manipulating the :term:`thread state` has the following " "simple structure::" msgstr "" -#: ../../c-api/threads.rst:57 +#: ../../c-api/threads.rst:77 msgid "" "Save the thread state in a local variable.\n" "... Do some blocking I/O operation ...\n" "Restore the thread state from the local variable." msgstr "" -#: ../../c-api/threads.rst:61 +#: ../../c-api/threads.rst:81 msgid "This is so common that a pair of macros exists to simplify it::" msgstr "" -#: ../../c-api/threads.rst:63 +#: ../../c-api/threads.rst:83 msgid "" "Py_BEGIN_ALLOW_THREADS\n" "... Do some blocking I/O operation ...\n" "Py_END_ALLOW_THREADS" msgstr "" -#: ../../c-api/threads.rst:71 +#: ../../c-api/threads.rst:91 msgid "" "The :c:macro:`Py_BEGIN_ALLOW_THREADS` macro opens a new block and declares a " "hidden local variable; the :c:macro:`Py_END_ALLOW_THREADS` macro closes the " "block." msgstr "" -#: ../../c-api/threads.rst:75 +#: ../../c-api/threads.rst:95 msgid "The block above expands to the following code::" msgstr "" -#: ../../c-api/threads.rst:77 +#: ../../c-api/threads.rst:97 msgid "" "PyThreadState *_save;\n" "\n" @@ -121,63 +145,69 @@ msgid "" "PyEval_RestoreThread(_save);" msgstr "" -#: ../../c-api/threads.rst:87 +#: ../../c-api/threads.rst:107 msgid "Here is how these functions work:" msgstr "" -#: ../../c-api/threads.rst:89 +#: ../../c-api/threads.rst:109 msgid "" -"The :term:`attached thread state` holds the :term:`GIL` for the entire " -"interpreter. When detaching the :term:`attached thread state`, the :term:" -"`GIL` is released, allowing other threads to attach a thread state to their " -"own thread, thus getting the :term:`GIL` and can start executing. The " -"pointer to the prior :term:`attached thread state` is stored as a local " -"variable. Upon reaching :c:macro:`Py_END_ALLOW_THREADS`, the thread state " -"that was previously :term:`attached ` is passed to :c:" -"func:`PyEval_RestoreThread`. This function will block until another releases " -"its :term:`thread state `, thus allowing the old :" -"term:`thread state ` to get re-attached and the C API " -"can be called again." +"The attached thread state implies that the GIL is held for the interpreter. " +"To detach it, :c:func:`PyEval_SaveThread` is called and the result is stored " +"in a local variable." msgstr "" -#: ../../c-api/threads.rst:99 +#: ../../c-api/threads.rst:113 msgid "" -"For :term:`free-threaded ` builds, the :term:`GIL` is " -"normally out of the question, but detaching the :term:`thread state " -"` is still required for blocking I/O and long " -"operations. The difference is that threads don't have to wait for the :term:" -"`GIL` to be released to attach their thread state, allowing true multi-core " -"parallelism." +"By detaching the thread state, the GIL is released, which allows other " +"threads to attach to the interpreter and execute while the current thread " +"performs blocking I/O. When the I/O operation is complete, the old thread " +"state is reattached by calling :c:func:`PyEval_RestoreThread`, which will " +"wait until the GIL can be acquired." msgstr "" -#: ../../c-api/threads.rst:105 +#: ../../c-api/threads.rst:120 msgid "" -"Calling system I/O functions is the most common use case for detaching the :" -"term:`thread state `, but it can also be useful " -"before calling long-running computations which don't need access to Python " -"objects, such as compression or cryptographic functions operating over " -"memory buffers. For example, the standard :mod:`zlib` and :mod:`hashlib` " -"modules detach the :term:`thread state ` when " -"compressing or hashing data." +"Performing blocking I/O is the most common use case for detaching the thread " +"state, but it is also useful to call it over long-running native code that " +"doesn't need access to Python objects or Python's C API. For example, the " +"standard :mod:`zlib` and :mod:`hashlib` modules detach the :term:`thread " +"state ` when compressing or hashing data." msgstr "" -#: ../../c-api/threads.rst:113 +#: ../../c-api/threads.rst:127 +msgid "" +"On a :term:`free-threaded build`, the :term:`GIL` is usually out of the " +"question, but **detaching the thread state is still required**, because the " +"interpreter periodically needs to block all threads to get a consistent view " +"of Python objects without the risk of race conditions. For example, CPython " +"currently suspends all threads for a short period of time while running the " +"garbage collector." +msgstr "" + +#: ../../c-api/threads.rst:136 +msgid "" +"Detaching the thread state can lead to unexpected behavior during " +"interpreter finalization. See :ref:`cautions-regarding-runtime-finalization` " +"for more details." +msgstr "" + +#: ../../c-api/threads.rst:142 msgid "APIs" msgstr "" -#: ../../c-api/threads.rst:115 +#: ../../c-api/threads.rst:144 msgid "" "The following macros are normally used without a trailing semicolon; look " "for example usage in the Python source distribution." msgstr "" -#: ../../c-api/threads.rst:120 +#: ../../c-api/threads.rst:149 msgid "" "These macros are still necessary on the :term:`free-threaded build` to " "prevent deadlocks." msgstr "" -#: ../../c-api/threads.rst:125 +#: ../../c-api/threads.rst:154 msgid "" "This macro expands to ``{ PyThreadState *_save; _save = PyEval_SaveThread();" "``. Note that it contains an opening brace; it must be matched with a " @@ -185,7 +215,7 @@ msgid "" "discussion of this macro." msgstr "" -#: ../../c-api/threads.rst:133 +#: ../../c-api/threads.rst:162 msgid "" "This macro expands to ``PyEval_RestoreThread(_save); }``. Note that it " "contains a closing brace; it must be matched with an earlier :c:macro:" @@ -193,117 +223,134 @@ msgid "" "macro." msgstr "" -#: ../../c-api/threads.rst:141 +#: ../../c-api/threads.rst:170 msgid "" "This macro expands to ``PyEval_RestoreThread(_save);``: it is equivalent to :" "c:macro:`Py_END_ALLOW_THREADS` without the closing brace." msgstr "" -#: ../../c-api/threads.rst:147 +#: ../../c-api/threads.rst:176 msgid "" "This macro expands to ``_save = PyEval_SaveThread();``: it is equivalent to :" "c:macro:`Py_BEGIN_ALLOW_THREADS` without the opening brace and variable " "declaration." msgstr "" -#: ../../c-api/threads.rst:155 +#: ../../c-api/threads.rst:182 msgid "Non-Python created threads" msgstr "" -#: ../../c-api/threads.rst:157 +#: ../../c-api/threads.rst:184 msgid "" "When threads are created using the dedicated Python APIs (such as the :mod:" -"`threading` module), a thread state is automatically associated to them and " -"the code shown above is therefore correct. However, when threads are " -"created from C (for example by a third-party library with its own thread " -"management), they don't hold the :term:`GIL`, because they don't have an :" -"term:`attached thread state`." +"`threading` module), a thread state is automatically associated with them, " +"However, when a thread is created from native code (for example, by a third-" +"party library with its own thread management), it doesn't hold an attached " +"thread state." msgstr "" -#: ../../c-api/threads.rst:164 +#: ../../c-api/threads.rst:190 msgid "" "If you need to call Python code from these threads (often this will be part " "of a callback API provided by the aforementioned third-party library), you " -"must first register these threads with the interpreter by creating an :term:" -"`attached thread state` before you can start using the Python/C API. When " -"you are done, you should detach the :term:`thread state `, and finally free it." +"must first register these threads with the interpreter by creating a new " +"thread state and attaching it." msgstr "" -#: ../../c-api/threads.rst:171 +#: ../../c-api/threads.rst:195 msgid "" -"The :c:func:`PyGILState_Ensure` and :c:func:`PyGILState_Release` functions " -"do all of the above automatically. The typical idiom for calling into " -"Python from a C thread is::" +"The most robust way to do this is through :c:func:`PyThreadState_New` " +"followed by :c:func:`PyThreadState_Swap`." msgstr "" -#: ../../c-api/threads.rst:175 +#: ../../c-api/threads.rst:199 msgid "" -"PyGILState_STATE gstate;\n" -"gstate = PyGILState_Ensure();\n" +"``PyThreadState_New`` requires an argument pointing to the desired " +"interpreter; such a pointer can be acquired via a call to :c:func:" +"`PyInterpreterState_Get` from the code where the thread was created." +msgstr "" + +#: ../../c-api/threads.rst:204 +msgid "For example::" +msgstr "" + +#: ../../c-api/threads.rst:206 +msgid "" +"/* The return value of PyInterpreterState_Get() from the\n" +" function that created this thread. */\n" +"PyInterpreterState *interp = thread_data->interp;\n" +"\n" +"/* Create a new thread state for the interpreter. It does not start out\n" +" attached. */\n" +"PyThreadState *tstate = PyThreadState_New(interp);\n" +"\n" +"/* Attach the thread state, which will acquire the GIL. */\n" +"PyThreadState_Swap(tstate);\n" "\n" "/* Perform Python actions here. */\n" "result = CallSomeFunction();\n" "/* evaluate result or handle exception */\n" "\n" -"/* Release the thread. No Python API allowed beyond this point. */\n" -"PyGILState_Release(gstate);" +"/* Destroy the thread state. No Python API allowed beyond this point. */\n" +"PyThreadState_Clear(tstate);\n" +"PyThreadState_DeleteCurrent();" msgstr "" -#: ../../c-api/threads.rst:185 +#: ../../c-api/threads.rst:227 msgid "" -"Note that the ``PyGILState_*`` functions assume there is only one global " -"interpreter (created automatically by :c:func:`Py_Initialize`). Python " -"supports the creation of additional interpreters (using :c:func:" -"`Py_NewInterpreter`), but mixing multiple interpreters and the " -"``PyGILState_*`` API is unsupported. This is because :c:func:" -"`PyGILState_Ensure` and similar functions default to :term:`attaching " -"` a :term:`thread state` for the main interpreter, " -"meaning that the thread can't safely interact with the calling " -"subinterpreter." +"If the interpreter finalized before ``PyThreadState_Swap`` was called, then " +"``interp`` will be a dangling pointer!" msgstr "" -#: ../../c-api/threads.rst:195 -msgid "Supporting subinterpreters in non-Python threads" +#: ../../c-api/threads.rst:233 +msgid "Legacy API" msgstr "" -#: ../../c-api/threads.rst:197 +#: ../../c-api/threads.rst:235 msgid "" -"If you would like to support subinterpreters with non-Python created " -"threads, you must use the ``PyThreadState_*`` API instead of the traditional " -"``PyGILState_*`` API." +"Another common pattern to call Python code from a non-Python thread is to " +"use :c:func:`PyGILState_Ensure` followed by a call to :c:func:" +"`PyGILState_Release`." msgstr "" -#: ../../c-api/threads.rst:201 +#: ../../c-api/threads.rst:238 msgid "" -"In particular, you must store the interpreter state from the calling " -"function and pass it to :c:func:`PyThreadState_New`, which will ensure that " -"the :term:`thread state` is targeting the correct interpreter::" +"These functions do not work well when multiple interpreters exist in the " +"Python process. If no Python interpreter has ever been used in the current " +"thread (which is common for threads created outside Python), " +"``PyGILState_Ensure`` will create and attach a thread state for the \"main\" " +"interpreter (the first interpreter in the Python process)." msgstr "" -#: ../../c-api/threads.rst:205 +#: ../../c-api/threads.rst:244 msgid "" -"/* The return value of PyInterpreterState_Get() from the\n" -" function that created this thread. */\n" -"PyInterpreterState *interp = ThreadData->interp;\n" -"PyThreadState *tstate = PyThreadState_New(interp);\n" -"PyThreadState_Swap(tstate);\n" +"Additionally, these functions have thread-safety issues during interpreter " +"finalization. Using ``PyGILState_Ensure`` during finalization will likely " +"crash the process." +msgstr "" + +#: ../../c-api/threads.rst:248 +msgid "Usage of these functions look like such::" +msgstr "" + +#: ../../c-api/threads.rst:250 +msgid "" +"PyGILState_STATE gstate;\n" +"gstate = PyGILState_Ensure();\n" "\n" -"/* GIL of the subinterpreter is now held.\n" -" Perform Python actions here. */\n" +"/* Perform Python actions here. */\n" "result = CallSomeFunction();\n" "/* evaluate result or handle exception */\n" "\n" -"/* Destroy the thread state. No Python API allowed beyond this point. */\n" -"PyThreadState_Clear(tstate);\n" -"PyThreadState_DeleteCurrent();" +"/* Release the thread. No Python API allowed beyond this point. */\n" +"PyGILState_Release(gstate);" msgstr "" -#: ../../c-api/threads.rst:224 +#: ../../c-api/threads.rst:264 msgid "Cautions about fork()" msgstr "" -#: ../../c-api/threads.rst:226 +#: ../../c-api/threads.rst:266 msgid "" "Another important thing to note about threads is their behaviour in the face " "of the C :c:func:`fork` call. On most systems with :c:func:`fork`, after a " @@ -312,7 +359,7 @@ msgid "" "CPython's runtime." msgstr "" -#: ../../c-api/threads.rst:232 +#: ../../c-api/threads.rst:272 msgid "" "The fact that only the \"current\" thread remains means any locks held by " "other threads will never be released. Python solves this for :func:`os.fork` " @@ -329,7 +376,7 @@ msgid "" "locks, but is not always able to." msgstr "" -#: ../../c-api/threads.rst:247 +#: ../../c-api/threads.rst:287 msgid "" "The fact that all other threads go away also means that CPython's runtime " "state there must be cleaned up properly, which :func:`os.fork` does. This " @@ -342,64 +389,64 @@ msgid "" "called immediately after." msgstr "" -#: ../../c-api/threads.rst:260 +#: ../../c-api/threads.rst:300 msgid "High-level APIs" msgstr "" -#: ../../c-api/threads.rst:262 +#: ../../c-api/threads.rst:302 msgid "" "These are the most commonly used types and functions when writing multi-" "threaded C extensions." msgstr "" -#: ../../c-api/threads.rst:268 +#: ../../c-api/threads.rst:308 msgid "" "This data structure represents the state of a single thread. The only " "public data member is:" msgstr "" -#: ../../c-api/threads.rst:273 +#: ../../c-api/threads.rst:313 msgid "This thread's interpreter state." msgstr "這個執行緒的直譯器狀態。" -#: ../../c-api/threads.rst:284 +#: ../../c-api/threads.rst:324 msgid "Deprecated function which does nothing." msgstr "已棄用的函式,什麼也不做。" -#: ../../c-api/threads.rst:286 +#: ../../c-api/threads.rst:326 msgid "" "In Python 3.6 and older, this function created the GIL if it didn't exist." msgstr "" -#: ../../c-api/threads.rst:288 +#: ../../c-api/threads.rst:328 msgid "The function now does nothing." msgstr "此函式現在不會做任何事情。" -#: ../../c-api/threads.rst:291 +#: ../../c-api/threads.rst:331 msgid "" "This function is now called by :c:func:`Py_Initialize()`, so you don't have " "to call it yourself anymore." msgstr "" -#: ../../c-api/threads.rst:295 +#: ../../c-api/threads.rst:335 msgid "" "This function cannot be called before :c:func:`Py_Initialize()` anymore." msgstr "" -#: ../../c-api/threads.rst:305 +#: ../../c-api/threads.rst:345 msgid "" "Detach the :term:`attached thread state` and return it. The thread will have " "no :term:`thread state` upon returning." msgstr "" -#: ../../c-api/threads.rst:311 +#: ../../c-api/threads.rst:351 msgid "" "Set the :term:`attached thread state` to *tstate*. The passed :term:`thread " "state` **should not** be :term:`attached `, otherwise " "deadlock ensues. *tstate* will be attached upon returning." msgstr "" -#: ../../c-api/threads.rst:316 ../../c-api/threads.rst:600 +#: ../../c-api/threads.rst:356 ../../c-api/threads.rst:640 msgid "" "Calling this function from a thread when the runtime is finalizing will hang " "the thread until the program exits, even if the thread was not created by " @@ -407,14 +454,14 @@ msgid "" "details." msgstr "" -#: ../../c-api/threads.rst:321 ../../c-api/threads.rst:408 -#: ../../c-api/threads.rst:610 +#: ../../c-api/threads.rst:361 ../../c-api/threads.rst:448 +#: ../../c-api/threads.rst:650 msgid "" "Hangs the current thread, rather than terminating it, if called while the " "interpreter is finalizing." msgstr "" -#: ../../c-api/threads.rst:327 +#: ../../c-api/threads.rst:367 msgid "" "Return the :term:`attached thread state`. If the thread has no attached " "thread state, (such as when inside of :c:macro:`Py_BEGIN_ALLOW_THREADS` " @@ -422,70 +469,72 @@ msgid "" "``NULL``)." msgstr "" -#: ../../c-api/threads.rst:332 +#: ../../c-api/threads.rst:372 msgid "See also :c:func:`PyThreadState_GetUnchecked`." msgstr "也請見 :c:func:`PyThreadState_GetUnchecked`。" -#: ../../c-api/threads.rst:336 +#: ../../c-api/threads.rst:376 msgid "" "Similar to :c:func:`PyThreadState_Get`, but don't kill the process with a " "fatal error if it is NULL. The caller is responsible to check if the result " "is NULL." msgstr "" -#: ../../c-api/threads.rst:340 +#: ../../c-api/threads.rst:380 msgid "" "In Python 3.5 to 3.12, the function was private and known as " "``_PyThreadState_UncheckedGet()``." -msgstr "在 Python 3.5 到 3.12 中,此函式是私有的,被稱為 ``_PyThreadState_UncheckedGet()``。" +msgstr "" +"在 Python 3.5 到 3.12 中,此函式是私有的,被稱為 " +"``_PyThreadState_UncheckedGet()``。" -#: ../../c-api/threads.rst:347 +#: ../../c-api/threads.rst:387 msgid "" "Set the :term:`attached thread state` to *tstate*, and return the :term:" "`thread state` that was attached prior to calling." msgstr "" -#: ../../c-api/threads.rst:350 +#: ../../c-api/threads.rst:390 msgid "" "This function is safe to call without an :term:`attached thread state`; it " "will simply return ``NULL`` indicating that there was no prior thread state." msgstr "" -#: ../../c-api/threads.rst:354 +#: ../../c-api/threads.rst:394 msgid ":c:func:`PyEval_ReleaseThread`" msgstr ":c:func:`PyEval_ReleaseThread`" -#: ../../c-api/threads.rst:357 +#: ../../c-api/threads.rst:397 msgid "" "Similar to :c:func:`PyGILState_Ensure`, this function will hang the thread " "if the runtime is finalizing." msgstr "" -#: ../../c-api/threads.rst:362 +#: ../../c-api/threads.rst:402 msgid "GIL-state APIs" msgstr "GIL 狀態 API" -#: ../../c-api/threads.rst:364 +#: ../../c-api/threads.rst:404 msgid "" "The following functions use thread-local storage, and are not compatible " "with sub-interpreters:" msgstr "" -#: ../../c-api/threads.rst:369 +#: ../../c-api/threads.rst:409 msgid "" "The type of the value returned by :c:func:`PyGILState_Ensure` and passed to :" "c:func:`PyGILState_Release`." msgstr "" -#: ../../c-api/threads.rst:374 +#: ../../c-api/threads.rst:414 msgid "The GIL was already held when :c:func:`PyGILState_Ensure` was called." msgstr "" -#: ../../c-api/threads.rst:378 +#: ../../c-api/threads.rst:418 msgid "The GIL was not held when :c:func:`PyGILState_Ensure` was called." msgstr "" -#: ../../c-api/threads.rst:382 +#: ../../c-api/threads.rst:422 msgid "" "Ensure that the current thread is ready to call the Python C API regardless " "of the current state of Python, or of the :term:`attached thread state`. " @@ -498,7 +547,7 @@ msgid "" "is acceptable." msgstr "" -#: ../../c-api/threads.rst:392 +#: ../../c-api/threads.rst:432 msgid "" "The return value is an opaque \"handle\" to the :term:`attached thread " "state` when :c:func:`PyGILState_Ensure` was called, and must be passed to :c:" @@ -508,14 +557,14 @@ msgid "" "to :c:func:`PyGILState_Release`." msgstr "" -#: ../../c-api/threads.rst:399 +#: ../../c-api/threads.rst:439 msgid "" "When the function returns, there will be an :term:`attached thread state` " "and the thread will be able to call arbitrary Python code. Failure is a " "fatal error." msgstr "" -#: ../../c-api/threads.rst:403 +#: ../../c-api/threads.rst:443 msgid "" "Calling this function when the runtime is finalizing is unsafe. Doing so " "will either hang the thread until the program ends, or fully crash the " @@ -523,7 +572,7 @@ msgid "" "finalization` for more details." msgstr "" -#: ../../c-api/threads.rst:414 +#: ../../c-api/threads.rst:454 msgid "" "Release any resources previously acquired. After this call, Python's state " "will be the same as it was prior to the corresponding :c:func:" @@ -531,13 +580,13 @@ msgid "" "caller, hence the use of the GILState API)." msgstr "" -#: ../../c-api/threads.rst:419 +#: ../../c-api/threads.rst:459 msgid "" "Every call to :c:func:`PyGILState_Ensure` must be matched by a call to :c:" "func:`PyGILState_Release` on the same thread." msgstr "" -#: ../../c-api/threads.rst:424 +#: ../../c-api/threads.rst:464 msgid "" "Get the :term:`attached thread state` for this thread. May return ``NULL`` " "if no GILState API has been used on the current thread. Note that the main " @@ -545,18 +594,18 @@ msgid "" "been made on the main thread. This is mainly a helper/diagnostic function." msgstr "" -#: ../../c-api/threads.rst:430 +#: ../../c-api/threads.rst:470 msgid "" "This function may return non-``NULL`` even when the :term:`thread state` is " "detached. Prefer :c:func:`PyThreadState_Get` or :c:func:" "`PyThreadState_GetUnchecked` for most cases." msgstr "" -#: ../../c-api/threads.rst:435 +#: ../../c-api/threads.rst:475 msgid ":c:func:`PyThreadState_Get`" msgstr ":c:func:`PyThreadState_Get`" -#: ../../c-api/threads.rst:439 +#: ../../c-api/threads.rst:479 msgid "" "Return ``1`` if the current thread is holding the :term:`GIL` and ``0`` " "otherwise. This function can be called from any thread at any time. Only if " @@ -568,120 +617,120 @@ msgid "" "differently." msgstr "" -#: ../../c-api/threads.rst:449 +#: ../../c-api/threads.rst:489 msgid "" "If the current Python process has ever created a subinterpreter, this " "function will *always* return ``1``. Prefer :c:func:" "`PyThreadState_GetUnchecked` for most cases." msgstr "" -#: ../../c-api/threads.rst:457 +#: ../../c-api/threads.rst:497 msgid "Low-level APIs" msgstr "低階 API" -#: ../../c-api/threads.rst:461 +#: ../../c-api/threads.rst:501 msgid "" "Create a new thread state object belonging to the given interpreter object. " "An :term:`attached thread state` is not needed." msgstr "" -#: ../../c-api/threads.rst:466 +#: ../../c-api/threads.rst:506 msgid "" "Reset all information in a :term:`thread state` object. *tstate* must be :" "term:`attached `" msgstr "" -#: ../../c-api/threads.rst:469 +#: ../../c-api/threads.rst:509 msgid "" "This function now calls the :c:member:`!PyThreadState.on_delete` callback. " "Previously, that happened in :c:func:`PyThreadState_Delete`." msgstr "" -#: ../../c-api/threads.rst:473 +#: ../../c-api/threads.rst:513 msgid "The :c:member:`!PyThreadState.on_delete` callback was removed." msgstr ":c:member:`!PyThreadState.on_delete` 回呼已被移除。" -#: ../../c-api/threads.rst:479 +#: ../../c-api/threads.rst:519 msgid "" "Destroy a :term:`thread state` object. *tstate* should not be :term:" "`attached ` to any thread. *tstate* must have been " "reset with a previous call to :c:func:`PyThreadState_Clear`." msgstr "" -#: ../../c-api/threads.rst:487 +#: ../../c-api/threads.rst:527 msgid "" "Detach the :term:`attached thread state` (which must have been reset with a " "previous call to :c:func:`PyThreadState_Clear`) and then destroy it." msgstr "" -#: ../../c-api/threads.rst:490 +#: ../../c-api/threads.rst:530 msgid "" "No :term:`thread state` will be :term:`attached ` " "upon returning." msgstr "" -#: ../../c-api/threads.rst:495 +#: ../../c-api/threads.rst:535 msgid "Get the current frame of the Python thread state *tstate*." msgstr "" -#: ../../c-api/threads.rst:497 +#: ../../c-api/threads.rst:537 msgid "" "Return a :term:`strong reference`. Return ``NULL`` if no frame is currently " "executing." msgstr "" -#: ../../c-api/threads.rst:500 +#: ../../c-api/threads.rst:540 msgid "See also :c:func:`PyEval_GetFrame`." msgstr "也請見 :c:func:`PyEval_GetFrame`。" -#: ../../c-api/threads.rst:502 ../../c-api/threads.rst:511 -#: ../../c-api/threads.rst:520 +#: ../../c-api/threads.rst:542 ../../c-api/threads.rst:551 +#: ../../c-api/threads.rst:560 msgid "" "*tstate* must not be ``NULL``, and must be :term:`attached `." msgstr "" -#: ../../c-api/threads.rst:509 +#: ../../c-api/threads.rst:549 msgid "" "Get the unique :term:`thread state` identifier of the Python thread state " "*tstate*." msgstr "" -#: ../../c-api/threads.rst:518 +#: ../../c-api/threads.rst:558 msgid "Get the interpreter of the Python thread state *tstate*." msgstr "" -#: ../../c-api/threads.rst:527 +#: ../../c-api/threads.rst:567 msgid "Suspend tracing and profiling in the Python thread state *tstate*." msgstr "" -#: ../../c-api/threads.rst:529 +#: ../../c-api/threads.rst:569 msgid "Resume them using the :c:func:`PyThreadState_LeaveTracing` function." msgstr "" -#: ../../c-api/threads.rst:536 +#: ../../c-api/threads.rst:576 msgid "" "Resume tracing and profiling in the Python thread state *tstate* suspended " "by the :c:func:`PyThreadState_EnterTracing` function." msgstr "" -#: ../../c-api/threads.rst:539 +#: ../../c-api/threads.rst:579 msgid "" "See also :c:func:`PyEval_SetTrace` and :c:func:`PyEval_SetProfile` functions." msgstr "" -#: ../../c-api/threads.rst:547 +#: ../../c-api/threads.rst:587 msgid "" "Set the stack protection start address and stack protection size of a Python " "thread state." msgstr "" -#: ../../c-api/threads.rst:550 +#: ../../c-api/threads.rst:590 msgid "" "On success, return ``0``. On failure, set an exception and return ``-1``." msgstr "" -#: ../../c-api/threads.rst:553 +#: ../../c-api/threads.rst:593 msgid "" "CPython implements :ref:`recursion control ` for C code by " "raising :py:exc:`RecursionError` when it notices that the machine execution " @@ -694,31 +743,33 @@ msgid "" "change." msgstr "" -#: ../../c-api/threads.rst:562 +#: ../../c-api/threads.rst:602 msgid "" "Call :c:func:`~PyUnstable_ThreadState_SetStackProtection` either before or " "after changing the stack. Do not call any other Python C API between the " "call and the stack change." msgstr "" -#: ../../c-api/threads.rst:567 +#: ../../c-api/threads.rst:607 msgid "" "See :c:func:`PyUnstable_ThreadState_ResetStackProtection` for undoing this " "operation." -msgstr "若要撤銷此操作,請參見 :c:func:`PyUnstable_ThreadState_ResetStackProtection`。" +msgstr "" +"若要撤銷此操作,請參見 :c:func:" +"`PyUnstable_ThreadState_ResetStackProtection`。" -#: ../../c-api/threads.rst:574 +#: ../../c-api/threads.rst:614 msgid "" "Reset the stack protection start address and stack protection size of a " "Python thread state to the operating system defaults." msgstr "" -#: ../../c-api/threads.rst:577 +#: ../../c-api/threads.rst:617 msgid "" "See :c:func:`PyUnstable_ThreadState_SetStackProtection` for an explanation." msgstr "請參見 :c:func:`PyUnstable_ThreadState_SetStackProtection` 的說明。" -#: ../../c-api/threads.rst:584 +#: ../../c-api/threads.rst:624 msgid "" "Return a dictionary in which extensions can store thread-specific state " "information. Each extension should use a unique key to use to store state " @@ -728,62 +779,62 @@ msgid "" "thread state is attached." msgstr "" -#: ../../c-api/threads.rst:594 +#: ../../c-api/threads.rst:634 msgid "" ":term:`Attach ` *tstate* to the current thread, which " "must not be ``NULL`` or already :term:`attached `." msgstr "" -#: ../../c-api/threads.rst:597 +#: ../../c-api/threads.rst:637 msgid "" "The calling thread must not already have an :term:`attached thread state`." msgstr "" -#: ../../c-api/threads.rst:605 +#: ../../c-api/threads.rst:645 msgid "" "Updated to be consistent with :c:func:`PyEval_RestoreThread`, :c:func:" "`Py_END_ALLOW_THREADS`, and :c:func:`PyGILState_Ensure`, and terminate the " "current thread if called while the interpreter is finalizing." msgstr "" -#: ../../c-api/threads.rst:614 +#: ../../c-api/threads.rst:654 msgid "" ":c:func:`PyEval_RestoreThread` is a higher-level function which is always " "available (even when threads have not been initialized)." msgstr "" -#: ../../c-api/threads.rst:620 +#: ../../c-api/threads.rst:660 msgid "" "Detach the :term:`attached thread state`. The *tstate* argument, which must " "not be ``NULL``, is only used to check that it represents the :term:" "`attached thread state` --- if it isn't, a fatal error is reported." msgstr "" -#: ../../c-api/threads.rst:625 +#: ../../c-api/threads.rst:665 msgid "" ":c:func:`PyEval_SaveThread` is a higher-level function which is always " "available (even when threads have not been initialized)." msgstr "" -#: ../../c-api/threads.rst:630 +#: ../../c-api/threads.rst:670 msgid "Asynchronous notifications" msgstr "" -#: ../../c-api/threads.rst:632 +#: ../../c-api/threads.rst:672 msgid "" "A mechanism is provided to make asynchronous notifications to the main " "interpreter thread. These notifications take the form of a function pointer " "and a void pointer argument." msgstr "" -#: ../../c-api/threads.rst:639 +#: ../../c-api/threads.rst:679 msgid "" "Schedule a function to be called from the main interpreter thread. On " "success, ``0`` is returned and *func* is queued for being called in the main " "thread. On failure, ``-1`` is returned without setting any exception." msgstr "" -#: ../../c-api/threads.rst:643 +#: ../../c-api/threads.rst:683 msgid "" "When successfully queued, *func* will be *eventually* called from the main " "interpreter thread with the argument *arg*. It will be called " @@ -791,17 +842,17 @@ msgid "" "these conditions met:" msgstr "" -#: ../../c-api/threads.rst:648 +#: ../../c-api/threads.rst:688 msgid "on a :term:`bytecode` boundary;" msgstr "" -#: ../../c-api/threads.rst:649 +#: ../../c-api/threads.rst:689 msgid "" "with the main thread holding an :term:`attached thread state` (*func* can " "therefore use the full C API)." msgstr "" -#: ../../c-api/threads.rst:652 +#: ../../c-api/threads.rst:692 msgid "" "*func* must return ``0`` on success, or ``-1`` on failure with an exception " "set. *func* won't be interrupted to perform another asynchronous " @@ -809,7 +860,7 @@ msgid "" "if the :term:`thread state ` is detached." msgstr "" -#: ../../c-api/threads.rst:657 +#: ../../c-api/threads.rst:697 msgid "" "This function doesn't need an :term:`attached thread state`. However, to " "call this function in a subinterpreter, the caller must have an :term:" @@ -817,7 +868,7 @@ msgid "" "be called from the wrong interpreter." msgstr "" -#: ../../c-api/threads.rst:662 +#: ../../c-api/threads.rst:702 msgid "" "This is a low-level function, only useful for very special cases. There is " "no guarantee that *func* will be called as quick as possible. If the main " @@ -827,7 +878,7 @@ msgid "" "`PyGILState API`." msgstr "" -#: ../../c-api/threads.rst:671 +#: ../../c-api/threads.rst:711 msgid "" "If this function is called in a subinterpreter, the function *func* is now " "scheduled to be called from the subinterpreter, rather than being called " @@ -835,35 +886,35 @@ msgid "" "scheduled calls." msgstr "" -#: ../../c-api/threads.rst:677 +#: ../../c-api/threads.rst:717 msgid "" "This function now always schedules *func* to be run in the main interpreter." msgstr "" -#: ../../c-api/threads.rst:684 +#: ../../c-api/threads.rst:724 msgid "" "Execute all pending calls. This is usually executed automatically by the " "interpreter." msgstr "" -#: ../../c-api/threads.rst:687 +#: ../../c-api/threads.rst:727 msgid "" "This function returns ``0`` on success, and returns ``-1`` with an exception " "set on failure." msgstr "" -#: ../../c-api/threads.rst:690 +#: ../../c-api/threads.rst:730 msgid "" "If this is not called in the main thread of the main interpreter, this " "function does nothing and returns ``0``. The caller must hold an :term:" "`attached thread state`." msgstr "" -#: ../../c-api/threads.rst:696 +#: ../../c-api/threads.rst:736 msgid "This function only runs pending calls in the main interpreter." msgstr "" -#: ../../c-api/threads.rst:702 +#: ../../c-api/threads.rst:742 msgid "" "Asynchronously raise an exception in a thread. The *id* argument is the " "thread id of the target thread; *exc* is the exception object to be raised. " @@ -875,109 +926,109 @@ msgid "" "is cleared. This raises no exceptions." msgstr "" -#: ../../c-api/threads.rst:710 +#: ../../c-api/threads.rst:750 msgid "" "The type of the *id* parameter changed from :c:expr:`long` to :c:expr:" "`unsigned long`." msgstr "" -#: ../../c-api/threads.rst:716 +#: ../../c-api/threads.rst:756 msgid "Operating system thread APIs" msgstr "作業系統執行緒 API" -#: ../../c-api/threads.rst:720 +#: ../../c-api/threads.rst:760 msgid "Sentinel value for an invalid thread ID." msgstr "" -#: ../../c-api/threads.rst:722 +#: ../../c-api/threads.rst:762 msgid "This is currently equivalent to ``(unsigned long)-1``." msgstr "目前等同於 ``(unsigned long)-1``。" -#: ../../c-api/threads.rst:727 +#: ../../c-api/threads.rst:767 msgid "" "Start function *func* in a new thread with argument *arg*. The resulting " "thread is not intended to be joined." msgstr "" -#: ../../c-api/threads.rst:730 +#: ../../c-api/threads.rst:770 msgid "*func* must not be ``NULL``, but *arg* may be ``NULL``." msgstr "*func* 不能是 ``NULL``,但 *arg* 可以是 ``NULL``。" -#: ../../c-api/threads.rst:732 +#: ../../c-api/threads.rst:772 msgid "" "On success, this function returns the identifier of the new thread; on " "failure, this returns :c:macro:`PYTHREAD_INVALID_THREAD_ID`." msgstr "" -#: ../../c-api/threads.rst:735 ../../c-api/threads.rst:819 -#: ../../c-api/threads.rst:827 +#: ../../c-api/threads.rst:775 ../../c-api/threads.rst:859 +#: ../../c-api/threads.rst:867 msgid "The caller does not need to hold an :term:`attached thread state`." msgstr "呼叫者不需擁有一個 :term:`attached thread state`。" -#: ../../c-api/threads.rst:740 +#: ../../c-api/threads.rst:780 msgid "Return the identifier of the current thread, which will never be zero." msgstr "" -#: ../../c-api/threads.rst:742 ../../c-api/threads.rst:774 +#: ../../c-api/threads.rst:782 ../../c-api/threads.rst:814 msgid "" "This function cannot fail, and the caller does not need to hold an :term:" "`attached thread state`." msgstr "" -#: ../../c-api/threads.rst:746 +#: ../../c-api/threads.rst:786 msgid ":py:func:`threading.get_ident`" msgstr ":py:func:`threading.get_ident`" -#: ../../c-api/threads.rst:751 +#: ../../c-api/threads.rst:791 msgid "" "Get general information about the current thread in the form of a :ref:" "`struct sequence ` object. This information is " "accessible as :py:attr:`sys.thread_info` in Python." msgstr "" -#: ../../c-api/threads.rst:755 +#: ../../c-api/threads.rst:795 msgid "" "On success, this returns a new :term:`strong reference` to the thread " "information; on failure, this returns ``NULL`` with an exception set." msgstr "" -#: ../../c-api/threads.rst:758 +#: ../../c-api/threads.rst:798 msgid "The caller must hold an :term:`attached thread state`." msgstr "呼叫者必須擁有一個 :term:`attached thread state`。" -#: ../../c-api/threads.rst:763 +#: ../../c-api/threads.rst:803 msgid "This macro is defined when the system supports native thread IDs." msgstr "" -#: ../../c-api/threads.rst:768 +#: ../../c-api/threads.rst:808 msgid "" "Get the native identifier of the current thread as it was assigned by the " "operating system's kernel, which will never be less than zero." msgstr "" -#: ../../c-api/threads.rst:771 +#: ../../c-api/threads.rst:811 msgid "" "This function is only available when :c:macro:`PY_HAVE_THREAD_NATIVE_ID` is " "defined." msgstr "" -#: ../../c-api/threads.rst:778 +#: ../../c-api/threads.rst:818 msgid ":py:func:`threading.get_native_id`" msgstr ":py:func:`threading.get_native_id`" -#: ../../c-api/threads.rst:783 +#: ../../c-api/threads.rst:823 msgid "" "Terminate the current thread. This function is generally considered unsafe " "and should be avoided. It is kept solely for backwards compatibility." msgstr "" -#: ../../c-api/threads.rst:786 +#: ../../c-api/threads.rst:826 msgid "" "This function is only safe to call if all functions in the full call stack " "are written to safely allow it." msgstr "" -#: ../../c-api/threads.rst:791 +#: ../../c-api/threads.rst:831 msgid "" "If the current system uses POSIX threads (also known as \"pthreads\"), this " "calls :manpage:`pthread_exit(3)`, which attempts to unwind the stack and " @@ -986,34 +1037,34 @@ msgid "" "systems, such as macOS, do unwinding." msgstr "" -#: ../../c-api/threads.rst:797 +#: ../../c-api/threads.rst:837 msgid "" "On Windows, this function calls ``_endthreadex()``, which kills the thread " "without calling C++ destructors." msgstr "" -#: ../../c-api/threads.rst:800 +#: ../../c-api/threads.rst:840 msgid "In any case, there is a risk of corruption on the thread's stack." msgstr "" -#: ../../c-api/threads.rst:807 +#: ../../c-api/threads.rst:847 msgid "" "Initialize ``PyThread*`` APIs. Python executes this function automatically, " "so there's little need to call it from an extension module." msgstr "" -#: ../../c-api/threads.rst:813 +#: ../../c-api/threads.rst:853 msgid "Set the stack size of the current thread to *size* bytes." msgstr "" -#: ../../c-api/threads.rst:815 +#: ../../c-api/threads.rst:855 msgid "" "This function returns ``0`` on success, ``-1`` if *size* is invalid, or " "``-2`` if the system does not support changing the stack size. This function " "does not set exceptions." msgstr "" -#: ../../c-api/threads.rst:824 +#: ../../c-api/threads.rst:864 msgid "" "Return the stack size of the current thread in bytes, or ``0`` if the " "system's default stack size is in use." @@ -1031,50 +1082,50 @@ msgstr "interpreter lock(直譯器鎖)" msgid "lock, interpreter" msgstr "lock, interpreter(鎖、直譯器)" -#: ../../c-api/threads.rst:22 +#: ../../c-api/threads.rst:25 msgid "setswitchinterval (in module sys)" msgstr "setswitchinterval (sys 模組中)" -#: ../../c-api/threads.rst:31 +#: ../../c-api/threads.rst:36 msgid "PyThreadState (C type)" msgstr "PyThreadState(C 型別)" -#: ../../c-api/threads.rst:67 +#: ../../c-api/threads.rst:87 msgid "Py_BEGIN_ALLOW_THREADS (C macro)" msgstr "Py_BEGIN_ALLOW_THREADS(C 巨集)" -#: ../../c-api/threads.rst:67 +#: ../../c-api/threads.rst:87 msgid "Py_END_ALLOW_THREADS (C macro)" msgstr "Py_END_ALLOW_THREADS(C 巨集)" -#: ../../c-api/threads.rst:83 +#: ../../c-api/threads.rst:103 msgid "PyEval_RestoreThread (C function)" msgstr "PyEval_RestoreThread(C 函式)" -#: ../../c-api/threads.rst:83 +#: ../../c-api/threads.rst:103 msgid "PyEval_SaveThread (C function)" msgstr "PyEval_SaveThread(C 函式)" -#: ../../c-api/threads.rst:278 +#: ../../c-api/threads.rst:318 msgid "PyEval_AcquireThread()" msgstr "PyEval_AcquireThread()" -#: ../../c-api/threads.rst:278 +#: ../../c-api/threads.rst:318 msgid "PyEval_ReleaseThread()" msgstr "PyEval_ReleaseThread()" -#: ../../c-api/threads.rst:278 +#: ../../c-api/threads.rst:318 msgid "PyEval_SaveThread()" msgstr "PyEval_SaveThread()" -#: ../../c-api/threads.rst:278 +#: ../../c-api/threads.rst:318 msgid "PyEval_RestoreThread()" msgstr "PyEval_RestoreThread()" -#: ../../c-api/threads.rst:300 +#: ../../c-api/threads.rst:340 msgid "module" msgstr "模組" -#: ../../c-api/threads.rst:300 +#: ../../c-api/threads.rst:340 msgid "_thread" msgstr "_thread" diff --git a/c-api/type.po b/c-api/type.po index f5ecca59361..fbebee35e13 100644 --- a/c-api/type.po +++ b/c-api/type.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-11-22 00:14+0000\n" +"POT-Creation-Date: 2026-03-11 00:16+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-" @@ -302,13 +302,20 @@ msgid "" "created using :c:func:`PyType_FromModuleAndSpec`." msgstr "" -#: ../../c-api/type.rst:277 ../../c-api/type.rst:298 +#: ../../c-api/type.rst:277 ../../c-api/type.rst:324 +msgid "" +"The returned reference is :term:`borrowed ` from *type*, " +"and will be valid as long as you hold a reference to *type*. Do not release " +"it with :c:func:`Py_DECREF` or similar." +msgstr "" + +#: ../../c-api/type.rst:281 ../../c-api/type.rst:302 msgid "" "If no module is associated with the given type, sets :py:class:`TypeError` " "and returns ``NULL``." msgstr "" -#: ../../c-api/type.rst:280 +#: ../../c-api/type.rst:284 msgid "" "This function is usually used to get the module in which a method is " "defined. Note that in such a method, ``PyType_GetModule(Py_TYPE(self))`` may " @@ -319,31 +326,31 @@ msgid "" "type:`!PyCMethod` cannot be used." msgstr "" -#: ../../c-api/type.rst:294 +#: ../../c-api/type.rst:298 msgid "" "Return the state of the module object associated with the given type. This " "is a shortcut for calling :c:func:`PyModule_GetState()` on the result of :c:" "func:`PyType_GetModule`." msgstr "" -#: ../../c-api/type.rst:301 +#: ../../c-api/type.rst:305 msgid "" "If the *type* has an associated module but its state is ``NULL``, returns " "``NULL`` without setting an exception." msgstr "" -#: ../../c-api/type.rst:309 +#: ../../c-api/type.rst:313 msgid "" "Find the first superclass whose module was created from the given :c:type:" "`PyModuleDef` *def*, and return that module." msgstr "" -#: ../../c-api/type.rst:312 +#: ../../c-api/type.rst:316 msgid "" "If no module is found, raises a :py:class:`TypeError` and returns ``NULL``." msgstr "" -#: ../../c-api/type.rst:314 +#: ../../c-api/type.rst:318 msgid "" "This function is intended to be used together with :c:func:" "`PyModule_GetState()` to get module state from slot methods (such as :c:" @@ -352,37 +359,30 @@ msgid "" "type:`PyCMethod` calling convention." msgstr "" -#: ../../c-api/type.rst:320 -msgid "" -"The returned reference is :term:`borrowed ` from *type*, " -"and will be valid as long as you hold a reference to *type*. Do not release " -"it with :c:func:`Py_DECREF` or similar." -msgstr "" - -#: ../../c-api/type.rst:329 +#: ../../c-api/type.rst:333 msgid "" "Find the first superclass in *type*'s :term:`method resolution order` whose :" "c:macro:`Py_tp_token` token is equal to the given one." msgstr "" -#: ../../c-api/type.rst:332 +#: ../../c-api/type.rst:336 msgid "" "If found, set *\\*result* to a new :term:`strong reference` to it and return " "``1``." msgstr "" -#: ../../c-api/type.rst:334 +#: ../../c-api/type.rst:338 msgid "If not found, set *\\*result* to ``NULL`` and return ``0``." msgstr "如果沒找到,則將 *\\*result* 設為 ``NULL`` 並回傳 ``0``。" -#: ../../c-api/type.rst:335 +#: ../../c-api/type.rst:339 msgid "" "On error, set *\\*result* to ``NULL`` and return ``-1`` with an exception " "set." msgstr "" "在發生錯誤時,將 *\\*result* 設為 ``NULL`` 並回傳 ``-1``,同時設定例外。" -#: ../../c-api/type.rst:338 +#: ../../c-api/type.rst:342 msgid "" "The *result* argument may be ``NULL``, in which case *\\*result* is not set. " "Use this if you need only the return value." @@ -390,64 +390,64 @@ msgstr "" "如果 *result* 引數為 ``NULL``,則不會設定 *\\*result*。如果你只需要回傳值,請" "使用此選項。" -#: ../../c-api/type.rst:341 +#: ../../c-api/type.rst:345 msgid "The *token* argument may not be ``NULL``." msgstr "*token* 引數不可為 ``NULL``。" -#: ../../c-api/type.rst:348 +#: ../../c-api/type.rst:352 msgid "Attempt to assign a version tag to the given type." msgstr "" -#: ../../c-api/type.rst:350 +#: ../../c-api/type.rst:354 msgid "" "Returns 1 if the type already had a valid version tag or a new one was " "assigned, or 0 if a new tag could not be assigned." msgstr "" -#: ../../c-api/type.rst:358 +#: ../../c-api/type.rst:362 msgid "" "Return true if instances of *type* support creating weak references, false " "otherwise. This function always succeeds. *type* must not be ``NULL``." msgstr "" -#: ../../c-api/type.rst:362 +#: ../../c-api/type.rst:366 msgid ":ref:`weakrefobjects`" msgstr ":ref:`weakrefobjects`" -#: ../../c-api/type.rst:363 +#: ../../c-api/type.rst:367 msgid ":py:mod:`weakref`" msgstr ":py:mod:`weakref`" -#: ../../c-api/type.rst:367 +#: ../../c-api/type.rst:371 msgid "Creating Heap-Allocated Types" msgstr "" -#: ../../c-api/type.rst:369 +#: ../../c-api/type.rst:373 msgid "" "The following functions and structs are used to create :ref:`heap types " "`." msgstr "" -#: ../../c-api/type.rst:374 +#: ../../c-api/type.rst:378 msgid "" "Create and return a :ref:`heap type ` from the *spec* (see :c:" "macro:`Py_TPFLAGS_HEAPTYPE`)." msgstr "" -#: ../../c-api/type.rst:377 +#: ../../c-api/type.rst:381 msgid "" "The metaclass *metaclass* is used to construct the resulting type object. " "When *metaclass* is ``NULL``, the metaclass is derived from *bases* (or " "*Py_tp_base[s]* slots if *bases* is ``NULL``, see below)." msgstr "" -#: ../../c-api/type.rst:381 +#: ../../c-api/type.rst:385 msgid "" "Metaclasses that override :c:member:`~PyTypeObject.tp_new` are not " "supported, except if ``tp_new`` is ``NULL``." msgstr "" -#: ../../c-api/type.rst:384 +#: ../../c-api/type.rst:388 msgid "" "The *bases* argument can be used to specify base classes; it can either be " "only one class or a tuple of classes. If *bases* is ``NULL``, the :c:data:" @@ -456,7 +456,7 @@ msgid "" "derives from :class:`object`." msgstr "" -#: ../../c-api/type.rst:390 +#: ../../c-api/type.rst:394 msgid "" "The *module* argument can be used to record the module in which the new " "class is defined. It must be a module object or ``NULL``. If not ``NULL``, " @@ -465,11 +465,11 @@ msgid "" "subclasses; it must be specified for each class individually." msgstr "" -#: ../../c-api/type.rst:397 +#: ../../c-api/type.rst:401 msgid "This function calls :c:func:`PyType_Ready` on the new type." msgstr "" -#: ../../c-api/type.rst:399 +#: ../../c-api/type.rst:403 msgid "" "Note that this function does *not* fully match the behavior of calling :py:" "class:`type() ` or using the :keyword:`class` statement. With user-" @@ -478,7 +478,7 @@ msgid "" "Specifically:" msgstr "" -#: ../../c-api/type.rst:406 +#: ../../c-api/type.rst:410 msgid "" ":py:meth:`~object.__new__` is not called on the new class (and it must be " "set to ``type.__new__``)." @@ -486,102 +486,102 @@ msgstr "" ":py:meth:`~object.__new__` 不會在新類別上被呼叫(且它必須被設為 ``type." "__new__``)。" -#: ../../c-api/type.rst:408 +#: ../../c-api/type.rst:412 msgid ":py:meth:`~object.__init__` is not called on the new class." msgstr ":py:meth:`~object.__init__` 不會在新類別上被呼叫。" -#: ../../c-api/type.rst:409 +#: ../../c-api/type.rst:413 msgid ":py:meth:`~object.__init_subclass__` is not called on any bases." msgstr ":py:meth:`~object.__init_subclass__` 不會在任何基底上被呼叫。" -#: ../../c-api/type.rst:410 +#: ../../c-api/type.rst:414 msgid ":py:meth:`~object.__set_name__` is not called on new descriptors." msgstr ":py:meth:`~object.__set_name__` 不會在新的描述器上被呼叫。" -#: ../../c-api/type.rst:417 +#: ../../c-api/type.rst:421 msgid "Equivalent to ``PyType_FromMetaclass(NULL, module, spec, bases)``." msgstr "等價於 ``PyType_FromMetaclass(NULL, module, spec, bases)``。" -#: ../../c-api/type.rst:423 +#: ../../c-api/type.rst:427 msgid "" "The function now accepts a single class as the *bases* argument and ``NULL`` " "as the ``tp_doc`` slot." msgstr "" -#: ../../c-api/type.rst:428 ../../c-api/type.rst:450 +#: ../../c-api/type.rst:432 ../../c-api/type.rst:454 msgid "" "The function now finds and uses a metaclass corresponding to the provided " "base classes. Previously, only :class:`type` instances were returned." msgstr "" -#: ../../c-api/type.rst:431 ../../c-api/type.rst:453 ../../c-api/type.rst:474 +#: ../../c-api/type.rst:435 ../../c-api/type.rst:457 ../../c-api/type.rst:478 msgid "" "The :c:member:`~PyTypeObject.tp_new` of the metaclass is *ignored*. which " "may result in incomplete initialization. Creating classes whose metaclass " "overrides :c:member:`~PyTypeObject.tp_new` is deprecated." msgstr "" -#: ../../c-api/type.rst:438 ../../c-api/type.rst:460 ../../c-api/type.rst:481 +#: ../../c-api/type.rst:442 ../../c-api/type.rst:464 ../../c-api/type.rst:485 msgid "" "Creating classes whose metaclass overrides :c:member:`~PyTypeObject.tp_new` " "is no longer allowed." msgstr "" -#: ../../c-api/type.rst:444 +#: ../../c-api/type.rst:448 msgid "Equivalent to ``PyType_FromMetaclass(NULL, NULL, spec, bases)``." msgstr "等價於 ``PyType_FromMetaclass(NULL, NULL, spec, bases)``。" -#: ../../c-api/type.rst:466 +#: ../../c-api/type.rst:470 msgid "Equivalent to ``PyType_FromMetaclass(NULL, NULL, spec, NULL)``." msgstr "等價於 ``PyType_FromMetaclass(NULL, NULL, spec, NULL)``。" -#: ../../c-api/type.rst:470 +#: ../../c-api/type.rst:474 msgid "" "The function now finds and uses a metaclass corresponding to the base " "classes provided in *Py_tp_base[s]* slots. Previously, only :class:`type` " "instances were returned." msgstr "" -#: ../../c-api/type.rst:487 +#: ../../c-api/type.rst:491 msgid "" "Make a type immutable: set the :c:macro:`Py_TPFLAGS_IMMUTABLETYPE` flag." msgstr "" -#: ../../c-api/type.rst:489 +#: ../../c-api/type.rst:493 msgid "All base classes of *type* must be immutable." msgstr "所有 *type* 的基底類別都必須是不可變的。" -#: ../../c-api/type.rst:491 +#: ../../c-api/type.rst:495 msgid "On success, return ``0``. On error, set an exception and return ``-1``." msgstr "" -#: ../../c-api/type.rst:494 +#: ../../c-api/type.rst:498 msgid "" "The type must not be used before it's made immutable. For example, type " "instances must not be created before the type is made immutable." msgstr "" -#: ../../c-api/type.rst:510 +#: ../../c-api/type.rst:514 msgid "Structure defining a type's behavior." msgstr "" -#: ../../c-api/type.rst:514 +#: ../../c-api/type.rst:518 msgid "Name of the type, used to set :c:member:`PyTypeObject.tp_name`." msgstr "" -#: ../../c-api/type.rst:518 +#: ../../c-api/type.rst:522 msgid "" "If positive, specifies the size of the instance in bytes. It is used to set :" "c:member:`PyTypeObject.tp_basicsize`." msgstr "" -#: ../../c-api/type.rst:521 +#: ../../c-api/type.rst:525 msgid "" "If zero, specifies that :c:member:`~PyTypeObject.tp_basicsize` should be " "inherited." msgstr "" -#: ../../c-api/type.rst:524 +#: ../../c-api/type.rst:528 msgid "" "If negative, the absolute value specifies how much space instances of the " "class need *in addition* to the superclass. Use :c:func:" @@ -591,17 +591,17 @@ msgid "" "requirements." msgstr "" -#: ../../c-api/type.rst:534 +#: ../../c-api/type.rst:538 msgid "Previously, this field could not be negative." msgstr "在過去此欄位不可為負值。" -#: ../../c-api/type.rst:538 +#: ../../c-api/type.rst:542 msgid "" "Size of one element of a variable-size type, in bytes. Used to set :c:member:" "`PyTypeObject.tp_itemsize`. See ``tp_itemsize`` documentation for caveats." msgstr "" -#: ../../c-api/type.rst:542 +#: ../../c-api/type.rst:546 msgid "" "If zero, :c:member:`~PyTypeObject.tp_itemsize` is inherited. Extending " "arbitrary variable-sized classes is dangerous, since some types use a fixed " @@ -610,32 +610,32 @@ msgid "" "only possible in the following situations:" msgstr "" -#: ../../c-api/type.rst:549 +#: ../../c-api/type.rst:553 msgid "" "The base is not variable-sized (its :c:member:`~PyTypeObject.tp_itemsize`)." msgstr "" -#: ../../c-api/type.rst:551 +#: ../../c-api/type.rst:555 msgid "" "The requested :c:member:`PyType_Spec.basicsize` is positive, suggesting that " "the memory layout of the base class is known." msgstr "" -#: ../../c-api/type.rst:553 +#: ../../c-api/type.rst:557 msgid "" "The requested :c:member:`PyType_Spec.basicsize` is zero, suggesting that the " "subclass does not access the instance's memory directly." msgstr "" -#: ../../c-api/type.rst:556 +#: ../../c-api/type.rst:560 msgid "With the :c:macro:`Py_TPFLAGS_ITEMS_AT_END` flag." msgstr "" -#: ../../c-api/type.rst:560 +#: ../../c-api/type.rst:564 msgid "Type flags, used to set :c:member:`PyTypeObject.tp_flags`." msgstr "" -#: ../../c-api/type.rst:562 +#: ../../c-api/type.rst:566 msgid "" "If the ``Py_TPFLAGS_HEAPTYPE`` flag is not set, :c:func:" "`PyType_FromSpecWithBases` sets it automatically." @@ -643,27 +643,27 @@ msgstr "" "如果未設定 ``Py_TPFLAGS_HEAPTYPE`` 旗標,則 :c:func:" "`PyType_FromSpecWithBases` 會自動設定它。" -#: ../../c-api/type.rst:567 +#: ../../c-api/type.rst:571 msgid "" "Array of :c:type:`PyType_Slot` structures. Terminated by the special slot " "value ``{0, NULL}``." msgstr "" -#: ../../c-api/type.rst:570 +#: ../../c-api/type.rst:574 msgid "Each slot ID should be specified at most once." msgstr "" -#: ../../c-api/type.rst:580 +#: ../../c-api/type.rst:584 msgid "" "Structure defining optional functionality of a type, containing a slot ID " "and a value pointer." msgstr "" -#: ../../c-api/type.rst:585 +#: ../../c-api/type.rst:589 msgid "A slot ID." msgstr "" -#: ../../c-api/type.rst:587 +#: ../../c-api/type.rst:591 msgid "" "Slot IDs are named like the field names of the structures :c:type:" "`PyTypeObject`, :c:type:`PyNumberMethods`, :c:type:`PySequenceMethods`, :c:" @@ -671,34 +671,34 @@ msgid "" "prefix. For example, use:" msgstr "" -#: ../../c-api/type.rst:593 +#: ../../c-api/type.rst:597 msgid ":c:data:`Py_tp_dealloc` to set :c:member:`PyTypeObject.tp_dealloc`" msgstr ":c:data:`Py_tp_dealloc` 以設定 :c:member:`PyTypeObject.tp_dealloc`" -#: ../../c-api/type.rst:594 +#: ../../c-api/type.rst:598 msgid ":c:data:`Py_nb_add` to set :c:member:`PyNumberMethods.nb_add`" msgstr ":c:data:`Py_nb_add` 以設定 :c:member:`PyNumberMethods.nb_add`" -#: ../../c-api/type.rst:595 +#: ../../c-api/type.rst:599 msgid ":c:data:`Py_sq_length` to set :c:member:`PySequenceMethods.sq_length`" msgstr ":c:data:`Py_sq_length` 以設定 :c:member:`PySequenceMethods.sq_length`" -#: ../../c-api/type.rst:597 +#: ../../c-api/type.rst:601 msgid "" "An additional slot is supported that does not correspond to a :c:type:`!" "PyTypeObject` struct field:" msgstr "" -#: ../../c-api/type.rst:600 +#: ../../c-api/type.rst:604 msgid ":c:data:`Py_tp_token`" msgstr ":c:data:`Py_tp_token`" -#: ../../c-api/type.rst:602 +#: ../../c-api/type.rst:606 msgid "" "The following “offset” fields cannot be set using :c:type:`PyType_Slot`:" msgstr "" -#: ../../c-api/type.rst:604 +#: ../../c-api/type.rst:608 msgid "" ":c:member:`~PyTypeObject.tp_weaklistoffset` (use :c:macro:" "`Py_TPFLAGS_MANAGED_WEAKREF` instead if possible)" @@ -706,7 +706,7 @@ msgstr "" ":c:member:`~PyTypeObject.tp_weaklistoffset`\\ (如果可能,請改用 :c:macro:" "`Py_TPFLAGS_MANAGED_WEAKREF`)" -#: ../../c-api/type.rst:606 +#: ../../c-api/type.rst:610 msgid "" ":c:member:`~PyTypeObject.tp_dictoffset` (use :c:macro:" "`Py_TPFLAGS_MANAGED_DICT` instead if possible)" @@ -714,7 +714,7 @@ msgstr "" ":c:member:`~PyTypeObject.tp_dictoffset`\\ (如果可能,請改用 :c:macro:" "`Py_TPFLAGS_MANAGED_DICT`)" -#: ../../c-api/type.rst:608 +#: ../../c-api/type.rst:612 msgid "" ":c:member:`~PyTypeObject.tp_vectorcall_offset` (use " "``\"__vectorcalloffset__\"`` in :ref:`PyMemberDef `)" @@ -722,7 +722,7 @@ msgstr "" ":c:member:`~PyTypeObject.tp_vectorcall_offset`\\ (請用 :ref:`PyMemberDef " "` 中的 ``\"__vectorcalloffset__\"``)" -#: ../../c-api/type.rst:612 +#: ../../c-api/type.rst:616 msgid "" "If it is not possible to switch to a ``MANAGED`` flag (for example, for " "vectorcall or to support Python older than 3.12), specify the offset in :c:" @@ -730,75 +730,75 @@ msgid "" "offsets>` for details." msgstr "" -#: ../../c-api/type.rst:618 +#: ../../c-api/type.rst:622 msgid "" "The following internal fields cannot be set at all when creating a heap type:" msgstr "" -#: ../../c-api/type.rst:621 +#: ../../c-api/type.rst:625 msgid "" ":c:member:`~PyTypeObject.tp_dict`, :c:member:`~PyTypeObject.tp_mro`, :c:" "member:`~PyTypeObject.tp_cache`, :c:member:`~PyTypeObject.tp_subclasses`, " "and :c:member:`~PyTypeObject.tp_weaklist`." msgstr "" -#: ../../c-api/type.rst:627 +#: ../../c-api/type.rst:631 msgid "" "Setting :c:data:`Py_tp_bases` or :c:data:`Py_tp_base` may be problematic on " "some platforms. To avoid issues, use the *bases* argument of :c:func:" "`PyType_FromSpecWithBases` instead." msgstr "" -#: ../../c-api/type.rst:632 +#: ../../c-api/type.rst:636 msgid "Slots in :c:type:`PyBufferProcs` may be set in the unlimited API." msgstr "" -#: ../../c-api/type.rst:635 +#: ../../c-api/type.rst:639 msgid "" ":c:member:`~PyBufferProcs.bf_getbuffer` and :c:member:`~PyBufferProcs." "bf_releasebuffer` are now available under the :ref:`limited API `." msgstr "" -#: ../../c-api/type.rst:640 +#: ../../c-api/type.rst:644 msgid "" "The field :c:member:`~PyTypeObject.tp_vectorcall` can now be set using :c:" "data:`Py_tp_vectorcall`. See the field's documentation for details." msgstr "" -#: ../../c-api/type.rst:647 +#: ../../c-api/type.rst:651 msgid "" "The desired value of the slot. In most cases, this is a pointer to a " "function." msgstr "" -#: ../../c-api/type.rst:650 +#: ../../c-api/type.rst:654 msgid "*pfunc* values may not be ``NULL``, except for the following slots:" msgstr "" -#: ../../c-api/type.rst:652 +#: ../../c-api/type.rst:656 msgid ":c:data:`Py_tp_doc`" msgstr ":c:data:`Py_tp_doc`" -#: ../../c-api/type.rst:653 +#: ../../c-api/type.rst:657 msgid "" ":c:data:`Py_tp_token` (for clarity, prefer :c:data:`Py_TP_USE_SPEC` rather " "than ``NULL``)" msgstr "" -#: ../../c-api/type.rst:659 +#: ../../c-api/type.rst:663 msgid "" "A :c:member:`~PyType_Slot.slot` that records a static memory layout ID for a " "class." msgstr "" -#: ../../c-api/type.rst:662 +#: ../../c-api/type.rst:666 msgid "" "If the :c:type:`PyType_Spec` of the class is statically allocated, the token " "can be set to the spec using the special value :c:data:`Py_TP_USE_SPEC`:" msgstr "" -#: ../../c-api/type.rst:666 +#: ../../c-api/type.rst:670 msgid "" "static PyType_Slot foo_slots[] = {\n" " {Py_tp_token, Py_TP_USE_SPEC}," @@ -806,35 +806,35 @@ msgstr "" "static PyType_Slot foo_slots[] = {\n" " {Py_tp_token, Py_TP_USE_SPEC}," -#: ../../c-api/type.rst:671 +#: ../../c-api/type.rst:675 msgid "It can also be set to an arbitrary pointer, but you must ensure that:" msgstr "" -#: ../../c-api/type.rst:673 +#: ../../c-api/type.rst:677 msgid "" "The pointer outlives the class, so it's not reused for something else while " "the class exists." msgstr "" -#: ../../c-api/type.rst:675 +#: ../../c-api/type.rst:679 msgid "" "It \"belongs\" to the extension module where the class lives, so it will not " "clash with other extensions." msgstr "" -#: ../../c-api/type.rst:678 +#: ../../c-api/type.rst:682 msgid "" "Use :c:func:`PyType_GetBaseByToken` to check if a class's superclass has a " "given token -- that is, check whether the memory layout is compatible." msgstr "" -#: ../../c-api/type.rst:681 +#: ../../c-api/type.rst:685 msgid "" "To get the token for a given class (without considering superclasses), use :" "c:func:`PyType_GetSlot` with ``Py_tp_token``." msgstr "" -#: ../../c-api/type.rst:690 +#: ../../c-api/type.rst:694 msgid "" "Used as a value with :c:data:`Py_tp_token` to set the token to the class's :" "c:type:`PyType_Spec`. Expands to ``NULL``." diff --git a/c-api/typeobj.po b/c-api/typeobj.po index 69b4349bec6..fda01852018 100644 --- a/c-api/typeobj.po +++ b/c-api/typeobj.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-01-22 16:55+0000\n" +"POT-Creation-Date: 2026-02-28 00:16+0000\n" "PO-Revision-Date: 2018-05-23 14:33+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -1330,20 +1330,21 @@ msgstr "" #: ../../c-api/typeobj.rst:1323 ../../c-api/typeobj.rst:1370 #: ../../c-api/typeobj.rst:1396 ../../c-api/typeobj.rst:1415 #: ../../c-api/typeobj.rst:1445 ../../c-api/typeobj.rst:1467 -#: ../../c-api/typeobj.rst:1495 ../../c-api/typeobj.rst:1593 -#: ../../c-api/typeobj.rst:1739 ../../c-api/typeobj.rst:1806 -#: ../../c-api/typeobj.rst:1842 ../../c-api/typeobj.rst:1869 -#: ../../c-api/typeobj.rst:1894 ../../c-api/typeobj.rst:1909 -#: ../../c-api/typeobj.rst:1926 ../../c-api/typeobj.rst:1942 -#: ../../c-api/typeobj.rst:1974 ../../c-api/typeobj.rst:2006 -#: ../../c-api/typeobj.rst:2034 ../../c-api/typeobj.rst:2054 -#: ../../c-api/typeobj.rst:2083 ../../c-api/typeobj.rst:2129 -#: ../../c-api/typeobj.rst:2148 ../../c-api/typeobj.rst:2190 -#: ../../c-api/typeobj.rst:2215 ../../c-api/typeobj.rst:2255 -#: ../../c-api/typeobj.rst:2285 ../../c-api/typeobj.rst:2298 -#: ../../c-api/typeobj.rst:2308 ../../c-api/typeobj.rst:2325 -#: ../../c-api/typeobj.rst:2342 ../../c-api/typeobj.rst:2358 -#: ../../c-api/typeobj.rst:2502 ../../c-api/typeobj.rst:2562 +#: ../../c-api/typeobj.rst:1503 ../../c-api/typeobj.rst:1515 +#: ../../c-api/typeobj.rst:1541 ../../c-api/typeobj.rst:1639 +#: ../../c-api/typeobj.rst:1785 ../../c-api/typeobj.rst:1852 +#: ../../c-api/typeobj.rst:1888 ../../c-api/typeobj.rst:1915 +#: ../../c-api/typeobj.rst:1940 ../../c-api/typeobj.rst:1955 +#: ../../c-api/typeobj.rst:1972 ../../c-api/typeobj.rst:1988 +#: ../../c-api/typeobj.rst:2020 ../../c-api/typeobj.rst:2052 +#: ../../c-api/typeobj.rst:2080 ../../c-api/typeobj.rst:2100 +#: ../../c-api/typeobj.rst:2129 ../../c-api/typeobj.rst:2175 +#: ../../c-api/typeobj.rst:2194 ../../c-api/typeobj.rst:2236 +#: ../../c-api/typeobj.rst:2261 ../../c-api/typeobj.rst:2301 +#: ../../c-api/typeobj.rst:2331 ../../c-api/typeobj.rst:2344 +#: ../../c-api/typeobj.rst:2354 ../../c-api/typeobj.rst:2371 +#: ../../c-api/typeobj.rst:2388 ../../c-api/typeobj.rst:2404 +#: ../../c-api/typeobj.rst:2548 ../../c-api/typeobj.rst:2608 msgid "**Inheritance:**" msgstr "" @@ -1382,10 +1383,10 @@ msgstr "" #: ../../c-api/typeobj.rst:529 ../../c-api/typeobj.rst:811 #: ../../c-api/typeobj.rst:938 ../../c-api/typeobj.rst:1038 -#: ../../c-api/typeobj.rst:1060 ../../c-api/typeobj.rst:1871 -#: ../../c-api/typeobj.rst:1896 ../../c-api/typeobj.rst:2036 -#: ../../c-api/typeobj.rst:2056 ../../c-api/typeobj.rst:2131 -#: ../../c-api/typeobj.rst:2257 ../../c-api/typeobj.rst:2504 +#: ../../c-api/typeobj.rst:1060 ../../c-api/typeobj.rst:1917 +#: ../../c-api/typeobj.rst:1942 ../../c-api/typeobj.rst:2082 +#: ../../c-api/typeobj.rst:2102 ../../c-api/typeobj.rst:2177 +#: ../../c-api/typeobj.rst:2303 ../../c-api/typeobj.rst:2550 msgid "This field is inherited by subtypes." msgstr "" @@ -1772,8 +1773,8 @@ msgid "" "violate any assumptions of the library." msgstr "" -#: ../../c-api/typeobj.rst:815 ../../c-api/typeobj.rst:1750 -#: ../../c-api/typeobj.rst:2517 +#: ../../c-api/typeobj.rst:815 ../../c-api/typeobj.rst:1796 +#: ../../c-api/typeobj.rst:2563 msgid "" ":ref:`life-cycle` for details about how this slot relates to other slots." msgstr "" @@ -1937,11 +1938,11 @@ msgstr "" #: ../../c-api/typeobj.rst:940 ../../c-api/typeobj.rst:1021 #: ../../c-api/typeobj.rst:1062 ../../c-api/typeobj.rst:1089 #: ../../c-api/typeobj.rst:1117 ../../c-api/typeobj.rst:1159 -#: ../../c-api/typeobj.rst:1815 ../../c-api/typeobj.rst:1849 -#: ../../c-api/typeobj.rst:1978 ../../c-api/typeobj.rst:2011 -#: ../../c-api/typeobj.rst:2090 ../../c-api/typeobj.rst:2133 -#: ../../c-api/typeobj.rst:2155 ../../c-api/typeobj.rst:2196 -#: ../../c-api/typeobj.rst:2226 ../../c-api/typeobj.rst:2259 +#: ../../c-api/typeobj.rst:1861 ../../c-api/typeobj.rst:1895 +#: ../../c-api/typeobj.rst:2024 ../../c-api/typeobj.rst:2057 +#: ../../c-api/typeobj.rst:2136 ../../c-api/typeobj.rst:2179 +#: ../../c-api/typeobj.rst:2201 ../../c-api/typeobj.rst:2242 +#: ../../c-api/typeobj.rst:2272 ../../c-api/typeobj.rst:2305 msgid "**Default:**" msgstr "**預設:**" @@ -2031,7 +2032,7 @@ msgid "" "`PyObject_HashNotImplemented`." msgstr "" -#: ../../c-api/typeobj.rst:1014 ../../c-api/typeobj.rst:1808 +#: ../../c-api/typeobj.rst:1014 ../../c-api/typeobj.rst:1854 msgid "" "Group: :c:member:`~PyTypeObject.tp_hash`, :c:member:`~PyTypeObject." "tp_richcompare`" @@ -2264,8 +2265,8 @@ msgid "" "`supporting-cycle-detection`." msgstr "" -#: ../../c-api/typeobj.rst:1231 ../../c-api/typeobj.rst:1595 -#: ../../c-api/typeobj.rst:1741 +#: ../../c-api/typeobj.rst:1231 ../../c-api/typeobj.rst:1641 +#: ../../c-api/typeobj.rst:1787 msgid "" "Group: :c:macro:`Py_TPFLAGS_HAVE_GC`, :c:member:`~PyTypeObject." "tp_traverse`, :c:member:`~PyTypeObject.tp_clear`" @@ -2453,7 +2454,8 @@ msgid "" "`." msgstr "" -#: ../../c-api/typeobj.rst:1398 +#: ../../c-api/typeobj.rst:1398 ../../c-api/typeobj.rst:1505 +#: ../../c-api/typeobj.rst:1517 msgid "This flag is not inherited." msgstr "" @@ -2540,35 +2542,76 @@ msgid "" "in a future version of CPython" msgstr "" -#: ../../c-api/typeobj.rst:1491 +#: ../../c-api/typeobj.rst:1489 +msgid "" +"This is a :term:`soft deprecated` macro that does nothing. Historically, " +"this would indicate that the :c:member:`~PyTypeObject.tp_version_tag` field " +"was available and initialized." +msgstr "" + +#: ../../c-api/typeobj.rst:1497 +msgid "" +"This bit indicates that instances of this type will have an \"inline " +"values\" array (containing the object's attributes) placed directly after " +"the end of the object." +msgstr "" + +#: ../../c-api/typeobj.rst:1501 +#, fuzzy +msgid "This requires that :c:macro:`Py_TPFLAGS_HAVE_GC` is set." +msgstr "如果有設定此旗標,則也應該設定 :c:macro:`Py_TPFLAGS_HAVE_GC`。" + +#: ../../c-api/typeobj.rst:1512 +msgid "" +"This bit indicates that this is an abstract type and therefore cannot be " +"instantiated." +msgstr "" + +#: ../../c-api/typeobj.rst:1520 +msgid ":mod:`abc`" +msgstr "" + +#: ../../c-api/typeobj.rst:1525 +msgid "" +"Internal. Do not set or unset this flag. Historically, this was a reserved " +"flag for use in Stackless Python." +msgstr "" + +#: ../../c-api/typeobj.rst:1529 +msgid "" +"This flag is present in header files, but is not be used. This may be " +"removed in a future version of CPython." +msgstr "" + +#: ../../c-api/typeobj.rst:1537 msgid "" "An optional pointer to a NUL-terminated C string giving the docstring for " "this type object. This is exposed as the :attr:`~type.__doc__` attribute on " "the type and instances of the type." msgstr "" -#: ../../c-api/typeobj.rst:1497 +#: ../../c-api/typeobj.rst:1543 msgid "This field is *not* inherited by subtypes." msgstr "此欄位不會被子型別繼承。" -#: ../../c-api/typeobj.rst:1504 +#: ../../c-api/typeobj.rst:1550 msgid "" "An optional pointer to a traversal function for the garbage collector. This " "is only used if the :c:macro:`Py_TPFLAGS_HAVE_GC` flag bit is set. The " "signature is::" msgstr "" -#: ../../c-api/typeobj.rst:1507 +#: ../../c-api/typeobj.rst:1553 msgid "int tp_traverse(PyObject *self, visitproc visit, void *arg);" msgstr "int tp_traverse(PyObject *self, visitproc visit, void *arg);" -#: ../../c-api/typeobj.rst:1509 ../../c-api/typeobj.rst:1736 +#: ../../c-api/typeobj.rst:1555 ../../c-api/typeobj.rst:1782 msgid "" "More information about Python's garbage collection scheme can be found in " "section :ref:`supporting-cycle-detection`." msgstr "" -#: ../../c-api/typeobj.rst:1512 +#: ../../c-api/typeobj.rst:1558 msgid "" "The :c:member:`~PyTypeObject.tp_traverse` pointer is used by the garbage " "collector to detect reference cycles. A typical implementation of a :c:" @@ -2578,7 +2621,7 @@ msgid "" "`!_thread` extension module::" msgstr "" -#: ../../c-api/typeobj.rst:1518 +#: ../../c-api/typeobj.rst:1564 msgid "" "static int\n" "local_traverse(PyObject *op, visitproc visit, void *arg)\n" @@ -2600,7 +2643,7 @@ msgstr "" " return 0;\n" "}" -#: ../../c-api/typeobj.rst:1528 +#: ../../c-api/typeobj.rst:1574 msgid "" "Note that :c:func:`Py_VISIT` is called only on those members that can " "participate in reference cycles. Although there is also a ``self->key`` " @@ -2608,29 +2651,29 @@ msgid "" "part of a reference cycle." msgstr "" -#: ../../c-api/typeobj.rst:1532 +#: ../../c-api/typeobj.rst:1578 msgid "" "On the other hand, even if you know a member can never be part of a cycle, " "as a debugging aid you may want to visit it anyway just so the :mod:`gc` " "module's :func:`~gc.get_referents` function will include it." msgstr "" -#: ../../c-api/typeobj.rst:1536 +#: ../../c-api/typeobj.rst:1582 msgid "" "Heap types (:c:macro:`Py_TPFLAGS_HEAPTYPE`) must visit their type with::" msgstr "" -#: ../../c-api/typeobj.rst:1538 +#: ../../c-api/typeobj.rst:1584 msgid "Py_VISIT(Py_TYPE(self));" msgstr "Py_VISIT(Py_TYPE(self));" -#: ../../c-api/typeobj.rst:1540 +#: ../../c-api/typeobj.rst:1586 msgid "" "It is only needed since Python 3.9. To support Python 3.8 and older, this " "line must be conditional::" msgstr "" -#: ../../c-api/typeobj.rst:1543 +#: ../../c-api/typeobj.rst:1589 msgid "" "#if PY_VERSION_HEX >= 0x03090000\n" " Py_VISIT(Py_TYPE(self));\n" @@ -2640,18 +2683,18 @@ msgstr "" " Py_VISIT(Py_TYPE(self));\n" "#endif" -#: ../../c-api/typeobj.rst:1547 +#: ../../c-api/typeobj.rst:1593 msgid "" "If the :c:macro:`Py_TPFLAGS_MANAGED_DICT` bit is set in the :c:member:" "`~PyTypeObject.tp_flags` field, the traverse function must call :c:func:" "`PyObject_VisitManagedDict` like this::" msgstr "" -#: ../../c-api/typeobj.rst:1551 +#: ../../c-api/typeobj.rst:1597 msgid "PyObject_VisitManagedDict((PyObject*)self, visit, arg);" msgstr "PyObject_VisitManagedDict((PyObject*)self, visit, arg);" -#: ../../c-api/typeobj.rst:1554 +#: ../../c-api/typeobj.rst:1600 msgid "" "When implementing :c:member:`~PyTypeObject.tp_traverse`, only the members " "that the instance *owns* (by having :term:`strong references ` hold a reference to " "their type. Their traversal function must therefore either visit :c:func:" @@ -2687,20 +2730,20 @@ msgid "" "superclass). If they do not, the type object may not be garbage-collected." msgstr "" -#: ../../c-api/typeobj.rst:1583 +#: ../../c-api/typeobj.rst:1629 msgid "" "The :c:member:`~PyTypeObject.tp_traverse` function can be called from any " "thread." msgstr ":c:member:`~PyTypeObject.tp_traverse` 函式可以從任何執行緒呼叫。" -#: ../../c-api/typeobj.rst:1588 +#: ../../c-api/typeobj.rst:1634 msgid "" "Heap-allocated types are expected to visit ``Py_TYPE(self)`` in " "``tp_traverse``. In earlier versions of Python, due to `bug 40217 `_, doing this may lead to crashes in subclasses." msgstr "" -#: ../../c-api/typeobj.rst:1597 +#: ../../c-api/typeobj.rst:1643 msgid "" "This field is inherited by subtypes together with :c:member:`~PyTypeObject." "tp_clear` and the :c:macro:`Py_TPFLAGS_HAVE_GC` flag bit: the flag bit, :c:" @@ -2708,15 +2751,15 @@ msgid "" "are all inherited from the base type if they are all zero in the subtype." msgstr "" -#: ../../c-api/typeobj.rst:1607 +#: ../../c-api/typeobj.rst:1653 msgid "An optional pointer to a clear function. The signature is::" msgstr "" -#: ../../c-api/typeobj.rst:1609 +#: ../../c-api/typeobj.rst:1655 msgid "int tp_clear(PyObject *);" msgstr "int tp_clear(PyObject *);" -#: ../../c-api/typeobj.rst:1611 +#: ../../c-api/typeobj.rst:1657 msgid "" "The purpose of this function is to break reference cycles that are causing " "a :term:`cyclic isolate` so that the objects can be safely destroyed. A " @@ -2724,7 +2767,7 @@ msgid "" "to satisfy design invariants held during normal use." msgstr "" -#: ../../c-api/typeobj.rst:1616 +#: ../../c-api/typeobj.rst:1662 msgid "" ":c:member:`!tp_clear` does not need to delete references to objects that " "can't participate in reference cycles, such as Python strings or Python " @@ -2735,44 +2778,44 @@ msgid "" "func:`Py_CLEAR`.)" msgstr "" -#: ../../c-api/typeobj.rst:1624 +#: ../../c-api/typeobj.rst:1670 msgid "" "Any non-trivial cleanup should be performed in :c:member:`~PyTypeObject." "tp_finalize` instead of :c:member:`!tp_clear`." msgstr "" -#: ../../c-api/typeobj.rst:1629 +#: ../../c-api/typeobj.rst:1675 msgid "" "If :c:member:`!tp_clear` fails to break a reference cycle then the objects " "in the :term:`cyclic isolate` may remain indefinitely uncollectable " "(\"leak\"). See :data:`gc.garbage`." msgstr "" -#: ../../c-api/typeobj.rst:1635 +#: ../../c-api/typeobj.rst:1681 msgid "" "Referents (direct and indirect) might have already been cleared; they are " "not guaranteed to be in a consistent state." msgstr "" -#: ../../c-api/typeobj.rst:1640 +#: ../../c-api/typeobj.rst:1686 msgid "" "The :c:member:`~PyTypeObject.tp_clear` function can be called from any " "thread." msgstr ":c:member:`~PyTypeObject.tp_clear` 函式可以從任何執行緒呼叫。" -#: ../../c-api/typeobj.rst:1645 +#: ../../c-api/typeobj.rst:1691 msgid "" "An object is not guaranteed to be automatically cleared before its " "destructor (:c:member:`~PyTypeObject.tp_dealloc`) is called." msgstr "" -#: ../../c-api/typeobj.rst:1648 +#: ../../c-api/typeobj.rst:1694 msgid "" "This function differs from the destructor (:c:member:`~PyTypeObject." "tp_dealloc`) in the following ways:" msgstr "" -#: ../../c-api/typeobj.rst:1651 +#: ../../c-api/typeobj.rst:1697 msgid "" "The purpose of clearing an object is to remove references to other objects " "that might participate in a reference cycle. The purpose of the destructor, " @@ -2782,7 +2825,7 @@ msgid "" "`~PyTypeObject.tp_free`)." msgstr "" -#: ../../c-api/typeobj.rst:1657 +#: ../../c-api/typeobj.rst:1703 msgid "" "When :c:member:`!tp_clear` is called, other objects might still hold " "references to the object being cleared. Because of this, :c:member:`!" @@ -2792,7 +2835,7 @@ msgid "" "object itself by deallocating it." msgstr "" -#: ../../c-api/typeobj.rst:1663 +#: ../../c-api/typeobj.rst:1709 msgid "" ":c:member:`!tp_clear` might never be automatically called. An object's " "destructor, on the other hand, will be automatically called some time after " @@ -2800,20 +2843,20 @@ msgid "" "object or the object is a member of a :term:`cyclic isolate`)." msgstr "" -#: ../../c-api/typeobj.rst:1668 +#: ../../c-api/typeobj.rst:1714 msgid "" "No guarantees are made about when, if, or how often Python automatically " "clears an object, except:" msgstr "" -#: ../../c-api/typeobj.rst:1671 +#: ../../c-api/typeobj.rst:1717 msgid "" "Python will not automatically clear an object if it is reachable, i.e., " "there is a reference to it and it is not a member of a :term:`cyclic " "isolate`." msgstr "" -#: ../../c-api/typeobj.rst:1674 +#: ../../c-api/typeobj.rst:1720 msgid "" "Python will not automatically clear an object if it has not been " "automatically finalized (see :c:member:`~PyTypeObject.tp_finalize`). (If " @@ -2821,14 +2864,14 @@ msgid "" "automatically finalized again before it is cleared.)" msgstr "" -#: ../../c-api/typeobj.rst:1678 +#: ../../c-api/typeobj.rst:1724 msgid "" "If an object is a member of a :term:`cyclic isolate`, Python will not " "automatically clear it if any member of the cyclic isolate has not yet been " "automatically finalized (:c:member:`~PyTypeObject.tp_finalize`)." msgstr "" -#: ../../c-api/typeobj.rst:1681 +#: ../../c-api/typeobj.rst:1727 msgid "" "Python will not destroy an object until after any automatic calls to its :c:" "member:`!tp_clear` function have returned. This ensures that the act of " @@ -2836,20 +2879,20 @@ msgid "" "member:`!tp_clear` is still executing." msgstr "" -#: ../../c-api/typeobj.rst:1685 +#: ../../c-api/typeobj.rst:1731 msgid "" "Python will not automatically call :c:member:`!tp_clear` multiple times " "concurrently." msgstr "" -#: ../../c-api/typeobj.rst:1688 +#: ../../c-api/typeobj.rst:1734 msgid "" "CPython currently only automatically clears objects as needed to break " "reference cycles in a :term:`cyclic isolate`, but future versions might " "clear objects regularly before their destruction." msgstr "" -#: ../../c-api/typeobj.rst:1692 +#: ../../c-api/typeobj.rst:1738 msgid "" "Taken together, all :c:member:`~PyTypeObject.tp_clear` functions in the " "system must combine to break all reference cycles. This is subtle, and if " @@ -2862,7 +2905,7 @@ msgid "" "good reason to avoid implementing :c:member:`~PyTypeObject.tp_clear`." msgstr "" -#: ../../c-api/typeobj.rst:1703 +#: ../../c-api/typeobj.rst:1749 msgid "" "Implementations of :c:member:`~PyTypeObject.tp_clear` should drop the " "instance's references to those of its members that may be Python objects, " @@ -2870,7 +2913,7 @@ msgid "" "example::" msgstr "" -#: ../../c-api/typeobj.rst:1707 +#: ../../c-api/typeobj.rst:1753 msgid "" "static int\n" "local_clear(PyObject *op)\n" @@ -2894,7 +2937,7 @@ msgstr "" " return 0;\n" "}" -#: ../../c-api/typeobj.rst:1718 +#: ../../c-api/typeobj.rst:1764 msgid "" "The :c:func:`Py_CLEAR` macro should be used, because clearing references is " "delicate: the reference to the contained object must not be released (via :" @@ -2909,18 +2952,18 @@ msgid "" "performs the operations in a safe order." msgstr "" -#: ../../c-api/typeobj.rst:1730 +#: ../../c-api/typeobj.rst:1776 msgid "" "If the :c:macro:`Py_TPFLAGS_MANAGED_DICT` bit is set in the :c:member:" "`~PyTypeObject.tp_flags` field, the clear function must call :c:func:" "`PyObject_ClearManagedDict` like this::" msgstr "" -#: ../../c-api/typeobj.rst:1734 +#: ../../c-api/typeobj.rst:1780 msgid "PyObject_ClearManagedDict((PyObject*)self);" msgstr "PyObject_ClearManagedDict((PyObject*)self);" -#: ../../c-api/typeobj.rst:1743 +#: ../../c-api/typeobj.rst:1789 msgid "" "This field is inherited by subtypes together with :c:member:`~PyTypeObject." "tp_traverse` and the :c:macro:`Py_TPFLAGS_HAVE_GC` flag bit: the flag bit, :" @@ -2928,22 +2971,22 @@ msgid "" "are all inherited from the base type if they are all zero in the subtype." msgstr "" -#: ../../c-api/typeobj.rst:1757 +#: ../../c-api/typeobj.rst:1803 msgid "" "An optional pointer to the rich comparison function, whose signature is::" msgstr "" -#: ../../c-api/typeobj.rst:1759 +#: ../../c-api/typeobj.rst:1805 msgid "PyObject *tp_richcompare(PyObject *self, PyObject *other, int op);" msgstr "PyObject *tp_richcompare(PyObject *self, PyObject *other, int op);" -#: ../../c-api/typeobj.rst:1761 +#: ../../c-api/typeobj.rst:1807 msgid "" "The first parameter is guaranteed to be an instance of the type that is " "defined by :c:type:`PyTypeObject`." msgstr "" -#: ../../c-api/typeobj.rst:1764 +#: ../../c-api/typeobj.rst:1810 msgid "" "The function should return the result of the comparison (usually ``Py_True`` " "or ``Py_False``). If the comparison is undefined, it must return " @@ -2951,50 +2994,50 @@ msgid "" "set an exception condition." msgstr "" -#: ../../c-api/typeobj.rst:1769 +#: ../../c-api/typeobj.rst:1815 msgid "" "The following constants are defined to be used as the third argument for :c:" "member:`~PyTypeObject.tp_richcompare` and for :c:func:`PyObject_RichCompare`:" msgstr "" -#: ../../c-api/typeobj.rst:1775 +#: ../../c-api/typeobj.rst:1821 msgid "Constant" msgstr "常數" -#: ../../c-api/typeobj.rst:1775 +#: ../../c-api/typeobj.rst:1821 msgid "Comparison" msgstr "" -#: ../../c-api/typeobj.rst:1777 +#: ../../c-api/typeobj.rst:1823 msgid "``<``" msgstr "``<``" -#: ../../c-api/typeobj.rst:1779 +#: ../../c-api/typeobj.rst:1825 msgid "``<=``" msgstr "``<=``" -#: ../../c-api/typeobj.rst:1781 +#: ../../c-api/typeobj.rst:1827 msgid "``==``" msgstr "``==``" -#: ../../c-api/typeobj.rst:1783 +#: ../../c-api/typeobj.rst:1829 msgid "``!=``" msgstr "``!=``" -#: ../../c-api/typeobj.rst:1785 +#: ../../c-api/typeobj.rst:1831 msgid "``>``" msgstr "``>``" -#: ../../c-api/typeobj.rst:1787 +#: ../../c-api/typeobj.rst:1833 msgid "``>=``" msgstr "``>=``" -#: ../../c-api/typeobj.rst:1790 +#: ../../c-api/typeobj.rst:1836 msgid "" "The following macro is defined to ease writing rich comparison functions:" msgstr "" -#: ../../c-api/typeobj.rst:1794 +#: ../../c-api/typeobj.rst:1840 msgid "" "Return ``Py_True`` or ``Py_False`` from the function, depending on the " "result of a comparison. VAL_A and VAL_B must be orderable by C comparison " @@ -3002,15 +3045,15 @@ msgid "" "specifies the requested operation, as for :c:func:`PyObject_RichCompare`." msgstr "" -#: ../../c-api/typeobj.rst:1800 +#: ../../c-api/typeobj.rst:1846 msgid "The returned value is a new :term:`strong reference`." msgstr "" -#: ../../c-api/typeobj.rst:1802 +#: ../../c-api/typeobj.rst:1848 msgid "On error, sets an exception and returns ``NULL`` from the function." msgstr "" -#: ../../c-api/typeobj.rst:1810 +#: ../../c-api/typeobj.rst:1856 msgid "" "This field is inherited by subtypes together with :c:member:`~PyTypeObject." "tp_hash`: a subtype inherits :c:member:`~PyTypeObject.tp_richcompare` and :c:" @@ -3018,7 +3061,7 @@ msgid "" "tp_richcompare` and :c:member:`~PyTypeObject.tp_hash` are both ``NULL``." msgstr "" -#: ../../c-api/typeobj.rst:1817 +#: ../../c-api/typeobj.rst:1863 msgid "" ":c:data:`PyBaseObject_Type` provides a :c:member:`~PyTypeObject." "tp_richcompare` implementation, which may be inherited. However, if only :c:" @@ -3027,13 +3070,13 @@ msgid "" "comparisons." msgstr "" -#: ../../c-api/typeobj.rst:1826 +#: ../../c-api/typeobj.rst:1872 msgid "" "While this field is still supported, :c:macro:`Py_TPFLAGS_MANAGED_WEAKREF` " "should be used instead, if at all possible." msgstr "" -#: ../../c-api/typeobj.rst:1829 +#: ../../c-api/typeobj.rst:1875 msgid "" "If the instances of this type are weakly referenceable, this field is " "greater than zero and contains the offset in the instance structure of the " @@ -3043,19 +3086,19 @@ msgid "" "`PyObject*` which is initialized to ``NULL``." msgstr "" -#: ../../c-api/typeobj.rst:1836 +#: ../../c-api/typeobj.rst:1882 msgid "" "Do not confuse this field with :c:member:`~PyTypeObject.tp_weaklist`; that " "is the list head for weak references to the type object itself." msgstr "" -#: ../../c-api/typeobj.rst:1839 +#: ../../c-api/typeobj.rst:1885 msgid "" "It is an error to set both the :c:macro:`Py_TPFLAGS_MANAGED_WEAKREF` bit " "and :c:member:`~PyTypeObject.tp_weaklistoffset`." msgstr "" -#: ../../c-api/typeobj.rst:1844 +#: ../../c-api/typeobj.rst:1890 msgid "" "This field is inherited by subtypes, but see the rules listed below. A " "subtype may override this offset; this means that the subtype uses a " @@ -3064,7 +3107,7 @@ msgid "" "not be a problem." msgstr "" -#: ../../c-api/typeobj.rst:1851 +#: ../../c-api/typeobj.rst:1897 msgid "" "If the :c:macro:`Py_TPFLAGS_MANAGED_WEAKREF` bit is set in the :c:member:" "`~PyTypeObject.tp_flags` field, then :c:member:`~PyTypeObject." @@ -3072,32 +3115,32 @@ msgid "" "unsafe to use this field." msgstr "" -#: ../../c-api/typeobj.rst:1861 +#: ../../c-api/typeobj.rst:1907 msgid "" "An optional pointer to a function that returns an :term:`iterator` for the " "object. Its presence normally signals that the instances of this type are :" "term:`iterable` (although sequences may be iterable without this function)." msgstr "" -#: ../../c-api/typeobj.rst:1865 +#: ../../c-api/typeobj.rst:1911 msgid "This function has the same signature as :c:func:`PyObject_GetIter`::" msgstr "" -#: ../../c-api/typeobj.rst:1867 +#: ../../c-api/typeobj.rst:1913 msgid "PyObject *tp_iter(PyObject *self);" msgstr "PyObject *tp_iter(PyObject *self);" -#: ../../c-api/typeobj.rst:1878 +#: ../../c-api/typeobj.rst:1924 msgid "" "An optional pointer to a function that returns the next item in an :term:" "`iterator`. The signature is::" msgstr "" -#: ../../c-api/typeobj.rst:1881 +#: ../../c-api/typeobj.rst:1927 msgid "PyObject *tp_iternext(PyObject *self);" msgstr "PyObject *tp_iternext(PyObject *self);" -#: ../../c-api/typeobj.rst:1883 +#: ../../c-api/typeobj.rst:1929 msgid "" "When the iterator is exhausted, it must return ``NULL``; a :exc:" "`StopIteration` exception may or may not be set. When another error occurs, " @@ -3105,74 +3148,74 @@ msgid "" "this type are iterators." msgstr "" -#: ../../c-api/typeobj.rst:1888 +#: ../../c-api/typeobj.rst:1934 msgid "" "Iterator types should also define the :c:member:`~PyTypeObject.tp_iter` " "function, and that function should return the iterator instance itself (not " "a new iterator instance)." msgstr "" -#: ../../c-api/typeobj.rst:1892 +#: ../../c-api/typeobj.rst:1938 msgid "This function has the same signature as :c:func:`PyIter_Next`." msgstr "" -#: ../../c-api/typeobj.rst:1903 +#: ../../c-api/typeobj.rst:1949 msgid "" "An optional pointer to a static ``NULL``-terminated array of :c:type:" "`PyMethodDef` structures, declaring regular methods of this type." msgstr "" -#: ../../c-api/typeobj.rst:1906 +#: ../../c-api/typeobj.rst:1952 msgid "" "For each entry in the array, an entry is added to the type's dictionary " "(see :c:member:`~PyTypeObject.tp_dict` below) containing a method descriptor." msgstr "" -#: ../../c-api/typeobj.rst:1911 +#: ../../c-api/typeobj.rst:1957 msgid "" "This field is not inherited by subtypes (methods are inherited through a " "different mechanism)." msgstr "" -#: ../../c-api/typeobj.rst:1919 +#: ../../c-api/typeobj.rst:1965 msgid "" "An optional pointer to a static ``NULL``-terminated array of :c:type:" "`PyMemberDef` structures, declaring regular data members (fields or slots) " "of instances of this type." msgstr "" -#: ../../c-api/typeobj.rst:1923 +#: ../../c-api/typeobj.rst:1969 msgid "" "For each entry in the array, an entry is added to the type's dictionary " "(see :c:member:`~PyTypeObject.tp_dict` below) containing a member descriptor." msgstr "" -#: ../../c-api/typeobj.rst:1928 +#: ../../c-api/typeobj.rst:1974 msgid "" "This field is not inherited by subtypes (members are inherited through a " "different mechanism)." msgstr "" -#: ../../c-api/typeobj.rst:1936 +#: ../../c-api/typeobj.rst:1982 msgid "" "An optional pointer to a static ``NULL``-terminated array of :c:type:" "`PyGetSetDef` structures, declaring computed attributes of instances of this " "type." msgstr "" -#: ../../c-api/typeobj.rst:1939 +#: ../../c-api/typeobj.rst:1985 msgid "" "For each entry in the array, an entry is added to the type's dictionary " "(see :c:member:`~PyTypeObject.tp_dict` below) containing a getset descriptor." msgstr "" -#: ../../c-api/typeobj.rst:1944 +#: ../../c-api/typeobj.rst:1990 msgid "" "This field is not inherited by subtypes (computed attributes are inherited " "through a different mechanism)." msgstr "" -#: ../../c-api/typeobj.rst:1952 +#: ../../c-api/typeobj.rst:1998 msgid "" "An optional pointer to a base type from which type properties are " "inherited. At this level, only single inheritance is supported; multiple " @@ -3180,7 +3223,7 @@ msgid "" "metatype." msgstr "" -#: ../../c-api/typeobj.rst:1960 +#: ../../c-api/typeobj.rst:2006 msgid "" "Slot initialization is subject to the rules of initializing globals. C99 " "requires the initializers to be \"address constants\". Function designators " @@ -3188,7 +3231,7 @@ msgid "" "valid C99 address constants." msgstr "" -#: ../../c-api/typeobj.rst:1965 +#: ../../c-api/typeobj.rst:2011 msgid "" "However, the unary '&' operator applied to a non-static variable like :c:" "data:`PyBaseObject_Type` is not required to produce an address constant. " @@ -3196,27 +3239,27 @@ msgid "" "strictly standard conforming in this particular behavior." msgstr "" -#: ../../c-api/typeobj.rst:1971 +#: ../../c-api/typeobj.rst:2017 msgid "" "Consequently, :c:member:`~PyTypeObject.tp_base` should be set in the " "extension module's init function." msgstr "" -#: ../../c-api/typeobj.rst:1976 +#: ../../c-api/typeobj.rst:2022 msgid "This field is not inherited by subtypes (obviously)." msgstr "" -#: ../../c-api/typeobj.rst:1980 +#: ../../c-api/typeobj.rst:2026 msgid "" "This field defaults to ``&PyBaseObject_Type`` (which to Python programmers " "is known as the type :class:`object`)." msgstr "" -#: ../../c-api/typeobj.rst:1986 +#: ../../c-api/typeobj.rst:2032 msgid "The type's dictionary is stored here by :c:func:`PyType_Ready`." msgstr "" -#: ../../c-api/typeobj.rst:1988 +#: ../../c-api/typeobj.rst:2034 msgid "" "This field should normally be initialized to ``NULL`` before PyType_Ready is " "called; it may also be initialized to a dictionary containing initial " @@ -3227,73 +3270,73 @@ msgid "" "be treated as read-only." msgstr "" -#: ../../c-api/typeobj.rst:1996 +#: ../../c-api/typeobj.rst:2042 msgid "" "Some types may not store their dictionary in this slot. Use :c:func:" "`PyType_GetDict` to retrieve the dictionary for an arbitrary type." msgstr "" -#: ../../c-api/typeobj.rst:2002 +#: ../../c-api/typeobj.rst:2048 msgid "" "Internals detail: For static builtin types, this is always ``NULL``. " "Instead, the dict for such types is stored on ``PyInterpreterState``. Use :c:" "func:`PyType_GetDict` to get the dict for an arbitrary type." msgstr "" -#: ../../c-api/typeobj.rst:2008 +#: ../../c-api/typeobj.rst:2054 msgid "" "This field is not inherited by subtypes (though the attributes defined in " "here are inherited through a different mechanism)." msgstr "" -#: ../../c-api/typeobj.rst:2013 +#: ../../c-api/typeobj.rst:2059 msgid "" "If this field is ``NULL``, :c:func:`PyType_Ready` will assign a new " "dictionary to it." msgstr "" -#: ../../c-api/typeobj.rst:2018 +#: ../../c-api/typeobj.rst:2064 msgid "" "It is not safe to use :c:func:`PyDict_SetItem` on or otherwise modify :c:" "member:`~PyTypeObject.tp_dict` with the dictionary C-API." msgstr "" -#: ../../c-api/typeobj.rst:2026 +#: ../../c-api/typeobj.rst:2072 msgid "An optional pointer to a \"descriptor get\" function." msgstr "" -#: ../../c-api/typeobj.rst:2028 ../../c-api/typeobj.rst:2046 -#: ../../c-api/typeobj.rst:2112 ../../c-api/typeobj.rst:2144 -#: ../../c-api/typeobj.rst:2169 +#: ../../c-api/typeobj.rst:2074 ../../c-api/typeobj.rst:2092 +#: ../../c-api/typeobj.rst:2158 ../../c-api/typeobj.rst:2190 +#: ../../c-api/typeobj.rst:2215 msgid "The function signature is::" msgstr "" -#: ../../c-api/typeobj.rst:2030 +#: ../../c-api/typeobj.rst:2076 msgid "PyObject * tp_descr_get(PyObject *self, PyObject *obj, PyObject *type);" msgstr "" "PyObject * tp_descr_get(PyObject *self, PyObject *obj, PyObject *type);" -#: ../../c-api/typeobj.rst:2043 +#: ../../c-api/typeobj.rst:2089 msgid "" "An optional pointer to a function for setting and deleting a descriptor's " "value." msgstr "" -#: ../../c-api/typeobj.rst:2048 +#: ../../c-api/typeobj.rst:2094 msgid "int tp_descr_set(PyObject *self, PyObject *obj, PyObject *value);" msgstr "int tp_descr_set(PyObject *self, PyObject *obj, PyObject *value);" -#: ../../c-api/typeobj.rst:2050 +#: ../../c-api/typeobj.rst:2096 msgid "The *value* argument is set to ``NULL`` to delete the value." msgstr "" -#: ../../c-api/typeobj.rst:2061 +#: ../../c-api/typeobj.rst:2107 msgid "" "While this field is still supported, :c:macro:`Py_TPFLAGS_MANAGED_DICT` " "should be used instead, if at all possible." msgstr "" -#: ../../c-api/typeobj.rst:2064 +#: ../../c-api/typeobj.rst:2110 msgid "" "If the instances of this type have a dictionary containing instance " "variables, this field is non-zero and contains the offset in the instances " @@ -3301,19 +3344,19 @@ msgid "" "func:`PyObject_GenericGetAttr`." msgstr "" -#: ../../c-api/typeobj.rst:2069 +#: ../../c-api/typeobj.rst:2115 msgid "" "Do not confuse this field with :c:member:`~PyTypeObject.tp_dict`; that is " "the dictionary for attributes of the type object itself." msgstr "" -#: ../../c-api/typeobj.rst:2072 +#: ../../c-api/typeobj.rst:2118 msgid "" "The value specifies the offset of the dictionary from the start of the " "instance structure." msgstr "" -#: ../../c-api/typeobj.rst:2074 +#: ../../c-api/typeobj.rst:2120 msgid "" "The :c:member:`~PyTypeObject.tp_dictoffset` should be regarded as write-" "only. To get the pointer to the dictionary call :c:func:" @@ -3322,13 +3365,13 @@ msgid "" "to call :c:func:`PyObject_GetAttr` when accessing an attribute on the object." msgstr "" -#: ../../c-api/typeobj.rst:2080 +#: ../../c-api/typeobj.rst:2126 msgid "" "It is an error to set both the :c:macro:`Py_TPFLAGS_MANAGED_DICT` bit and :c:" "member:`~PyTypeObject.tp_dictoffset`." msgstr "" -#: ../../c-api/typeobj.rst:2085 +#: ../../c-api/typeobj.rst:2131 msgid "" "This field is inherited by subtypes. A subtype should not override this " "offset; doing so could be unsafe, if C code tries to access the dictionary " @@ -3336,25 +3379,25 @@ msgid "" "`Py_TPFLAGS_MANAGED_DICT`." msgstr "" -#: ../../c-api/typeobj.rst:2092 +#: ../../c-api/typeobj.rst:2138 msgid "" "This slot has no default. For :ref:`static types `, if the " "field is ``NULL`` then no :attr:`~object.__dict__` gets created for " "instances." msgstr "" -#: ../../c-api/typeobj.rst:2095 +#: ../../c-api/typeobj.rst:2141 msgid "" "If the :c:macro:`Py_TPFLAGS_MANAGED_DICT` bit is set in the :c:member:" "`~PyTypeObject.tp_flags` field, then :c:member:`~PyTypeObject.tp_dictoffset` " "will be set to ``-1``, to indicate that it is unsafe to use this field." msgstr "" -#: ../../c-api/typeobj.rst:2105 +#: ../../c-api/typeobj.rst:2151 msgid "An optional pointer to an instance initialization function." msgstr "" -#: ../../c-api/typeobj.rst:2107 +#: ../../c-api/typeobj.rst:2153 msgid "" "This function corresponds to the :meth:`~object.__init__` method of " "classes. Like :meth:`!__init__`, it is possible to create an instance " @@ -3362,18 +3405,18 @@ msgid "" "instance by calling its :meth:`!__init__` method again." msgstr "" -#: ../../c-api/typeobj.rst:2114 +#: ../../c-api/typeobj.rst:2160 msgid "int tp_init(PyObject *self, PyObject *args, PyObject *kwds);" msgstr "int tp_init(PyObject *self, PyObject *args, PyObject *kwds);" -#: ../../c-api/typeobj.rst:2116 +#: ../../c-api/typeobj.rst:2162 msgid "" "The self argument is the instance to be initialized; the *args* and *kwds* " "arguments represent positional and keyword arguments of the call to :meth:" "`~object.__init__`." msgstr "" -#: ../../c-api/typeobj.rst:2120 +#: ../../c-api/typeobj.rst:2166 msgid "" "The :c:member:`~PyTypeObject.tp_init` function, if not ``NULL``, is called " "when an instance is created normally by calling its type, after the type's :" @@ -3385,53 +3428,53 @@ msgid "" "subtype's :c:member:`~PyTypeObject.tp_init` is called." msgstr "" -#: ../../c-api/typeobj.rst:2127 +#: ../../c-api/typeobj.rst:2173 msgid "Returns ``0`` on success, ``-1`` and sets an exception on error." msgstr "" -#: ../../c-api/typeobj.rst:2135 +#: ../../c-api/typeobj.rst:2181 msgid "" "For :ref:`static types ` this field does not have a default." msgstr "" -#: ../../c-api/typeobj.rst:2142 +#: ../../c-api/typeobj.rst:2188 msgid "An optional pointer to an instance allocation function." msgstr "" -#: ../../c-api/typeobj.rst:2146 +#: ../../c-api/typeobj.rst:2192 msgid "PyObject *tp_alloc(PyTypeObject *self, Py_ssize_t nitems);" msgstr "PyObject *tp_alloc(PyTypeObject *self, Py_ssize_t nitems);" -#: ../../c-api/typeobj.rst:2150 +#: ../../c-api/typeobj.rst:2196 msgid "" "Static subtypes inherit this slot, which will be :c:func:" "`PyType_GenericAlloc` if inherited from :class:`object`." msgstr "" -#: ../../c-api/typeobj.rst:2153 ../../c-api/typeobj.rst:2224 +#: ../../c-api/typeobj.rst:2199 ../../c-api/typeobj.rst:2270 msgid ":ref:`Heap subtypes ` do not inherit this slot." msgstr "" -#: ../../c-api/typeobj.rst:2157 +#: ../../c-api/typeobj.rst:2203 msgid "" "For heap subtypes, this field is always set to :c:func:`PyType_GenericAlloc`." msgstr "" -#: ../../c-api/typeobj.rst:2160 ../../c-api/typeobj.rst:2232 +#: ../../c-api/typeobj.rst:2206 ../../c-api/typeobj.rst:2278 msgid "For static subtypes, this slot is inherited (see above)." msgstr "" -#: ../../c-api/typeobj.rst:2167 +#: ../../c-api/typeobj.rst:2213 msgid "An optional pointer to an instance creation function." msgstr "" -#: ../../c-api/typeobj.rst:2171 +#: ../../c-api/typeobj.rst:2217 msgid "" "PyObject *tp_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds);" msgstr "" "PyObject *tp_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds);" -#: ../../c-api/typeobj.rst:2173 +#: ../../c-api/typeobj.rst:2219 msgid "" "The *subtype* argument is the type of the object being created; the *args* " "and *kwds* arguments represent positional and keyword arguments of the call " @@ -3440,7 +3483,7 @@ msgid "" "that type (but not an unrelated type)." msgstr "" -#: ../../c-api/typeobj.rst:2179 +#: ../../c-api/typeobj.rst:2225 msgid "" "The :c:member:`~PyTypeObject.tp_new` function should call ``subtype-" ">tp_alloc(subtype, nitems)`` to allocate space for the object, and then do " @@ -3452,20 +3495,20 @@ msgid "" "be deferred to :c:member:`~PyTypeObject.tp_init`." msgstr "" -#: ../../c-api/typeobj.rst:2187 +#: ../../c-api/typeobj.rst:2233 msgid "" "Set the :c:macro:`Py_TPFLAGS_DISALLOW_INSTANTIATION` flag to disallow " "creating instances of the type in Python." msgstr "" -#: ../../c-api/typeobj.rst:2192 +#: ../../c-api/typeobj.rst:2238 msgid "" "This field is inherited by subtypes, except it is not inherited by :ref:" "`static types ` whose :c:member:`~PyTypeObject.tp_base` is " "``NULL`` or ``&PyBaseObject_Type``." msgstr "" -#: ../../c-api/typeobj.rst:2198 +#: ../../c-api/typeobj.rst:2244 msgid "" "For :ref:`static types ` this field has no default. This means " "if the slot is defined as ``NULL``, the type cannot be called to create new " @@ -3473,22 +3516,22 @@ msgid "" "factory function." msgstr "" -#: ../../c-api/typeobj.rst:2208 +#: ../../c-api/typeobj.rst:2254 msgid "" "An optional pointer to an instance deallocation function. Its signature is::" msgstr "" -#: ../../c-api/typeobj.rst:2210 +#: ../../c-api/typeobj.rst:2256 msgid "void tp_free(void *self);" msgstr "void tp_free(void *self);" -#: ../../c-api/typeobj.rst:2212 +#: ../../c-api/typeobj.rst:2258 msgid "" "This function must free the memory allocated by :c:member:`~PyTypeObject." "tp_alloc`." msgstr "" -#: ../../c-api/typeobj.rst:2217 +#: ../../c-api/typeobj.rst:2263 msgid "" "Static subtypes inherit this slot, which will be :c:func:`PyObject_Free` if " "inherited from :class:`object`. Exception: If the type supports garbage " @@ -3497,18 +3540,18 @@ msgid "" "this slot is not inherited but instead defaults to :c:func:`PyObject_GC_Del`." msgstr "" -#: ../../c-api/typeobj.rst:2228 +#: ../../c-api/typeobj.rst:2274 msgid "" "For :ref:`heap subtypes `, this slot defaults to a deallocator " "suitable to match :c:func:`PyType_GenericAlloc` and the value of the :c:" "macro:`Py_TPFLAGS_HAVE_GC` flag." msgstr "" -#: ../../c-api/typeobj.rst:2239 +#: ../../c-api/typeobj.rst:2285 msgid "An optional pointer to a function called by the garbage collector." msgstr "" -#: ../../c-api/typeobj.rst:2241 +#: ../../c-api/typeobj.rst:2287 msgid "" "The garbage collector needs to know whether a particular object is " "collectible or not. Normally, it is sufficient to look at the object's " @@ -3520,93 +3563,93 @@ msgid "" "instance. The signature is::" msgstr "" -#: ../../c-api/typeobj.rst:2249 +#: ../../c-api/typeobj.rst:2295 msgid "int tp_is_gc(PyObject *self);" msgstr "int tp_is_gc(PyObject *self);" -#: ../../c-api/typeobj.rst:2251 +#: ../../c-api/typeobj.rst:2297 msgid "" "(The only example of this are types themselves. The metatype, :c:data:" "`PyType_Type`, defines this function to distinguish between statically and :" "ref:`dynamically allocated types `.)" msgstr "" -#: ../../c-api/typeobj.rst:2261 +#: ../../c-api/typeobj.rst:2307 msgid "" "This slot has no default. If this field is ``NULL``, :c:macro:" "`Py_TPFLAGS_HAVE_GC` is used as the functional equivalent." msgstr "" -#: ../../c-api/typeobj.rst:2269 +#: ../../c-api/typeobj.rst:2315 msgid "Tuple of base types." msgstr "" -#: ../../c-api/typeobj.rst:2271 ../../c-api/typeobj.rst:2295 +#: ../../c-api/typeobj.rst:2317 ../../c-api/typeobj.rst:2341 msgid "" "This field should be set to ``NULL`` and treated as read-only. Python will " "fill it in when the type is :c:func:`initialized `." msgstr "" -#: ../../c-api/typeobj.rst:2274 +#: ../../c-api/typeobj.rst:2320 msgid "" "For dynamically created classes, the :c:data:`Py_tp_bases` :c:type:`slot " "` can be used instead of the *bases* argument of :c:func:" "`PyType_FromSpecWithBases`. The argument form is preferred." msgstr "" -#: ../../c-api/typeobj.rst:2281 +#: ../../c-api/typeobj.rst:2327 msgid "" "Multiple inheritance does not work well for statically defined types. If you " "set ``tp_bases`` to a tuple, Python will not raise an error, but some slots " "will only be inherited from the first base." msgstr "" -#: ../../c-api/typeobj.rst:2287 ../../c-api/typeobj.rst:2310 -#: ../../c-api/typeobj.rst:2327 ../../c-api/typeobj.rst:2344 -#: ../../c-api/typeobj.rst:2360 +#: ../../c-api/typeobj.rst:2333 ../../c-api/typeobj.rst:2356 +#: ../../c-api/typeobj.rst:2373 ../../c-api/typeobj.rst:2390 +#: ../../c-api/typeobj.rst:2406 msgid "This field is not inherited." msgstr "" -#: ../../c-api/typeobj.rst:2292 +#: ../../c-api/typeobj.rst:2338 msgid "" "Tuple containing the expanded set of base types, starting with the type " "itself and ending with :class:`object`, in Method Resolution Order." msgstr "" -#: ../../c-api/typeobj.rst:2300 +#: ../../c-api/typeobj.rst:2346 msgid "" "This field is not inherited; it is calculated fresh by :c:func:" "`PyType_Ready`." msgstr "" -#: ../../c-api/typeobj.rst:2306 +#: ../../c-api/typeobj.rst:2352 msgid "Unused. Internal use only." msgstr "" -#: ../../c-api/typeobj.rst:2315 +#: ../../c-api/typeobj.rst:2361 msgid "" "A collection of subclasses. Internal use only. May be an invalid pointer." msgstr "" -#: ../../c-api/typeobj.rst:2317 +#: ../../c-api/typeobj.rst:2363 msgid "" "To get a list of subclasses, call the Python method :py:meth:`~type." "__subclasses__`." msgstr "" -#: ../../c-api/typeobj.rst:2322 +#: ../../c-api/typeobj.rst:2368 msgid "" "For some types, this field does not hold a valid :c:expr:`PyObject*`. The " "type was changed to :c:expr:`void*` to indicate this." msgstr "" -#: ../../c-api/typeobj.rst:2332 +#: ../../c-api/typeobj.rst:2378 msgid "" "Weak reference list head, for weak references to this type object. Not " "inherited. Internal use only." msgstr "" -#: ../../c-api/typeobj.rst:2337 +#: ../../c-api/typeobj.rst:2383 msgid "" "Internals detail: For the static builtin types this is always ``NULL``, even " "if weakrefs are added. Instead, the weakrefs for each are stored on " @@ -3614,27 +3657,27 @@ msgid "" "``_PyObject_GET_WEAKREFS_LISTPTR()`` macro to avoid the distinction." msgstr "" -#: ../../c-api/typeobj.rst:2351 +#: ../../c-api/typeobj.rst:2397 msgid "" "This field is deprecated. Use :c:member:`~PyTypeObject.tp_finalize` instead." msgstr "此欄位已被棄用。請改用 :c:member:`~PyTypeObject.tp_finalize`。" -#: ../../c-api/typeobj.rst:2356 +#: ../../c-api/typeobj.rst:2402 msgid "Used to index into the method cache. Internal use only." msgstr "" -#: ../../c-api/typeobj.rst:2367 +#: ../../c-api/typeobj.rst:2413 msgid "" "An optional pointer to an instance finalization function. This is the C " "implementation of the :meth:`~object.__del__` special method. Its signature " "is::" msgstr "" -#: ../../c-api/typeobj.rst:2371 +#: ../../c-api/typeobj.rst:2417 msgid "void tp_finalize(PyObject *self);" msgstr "void tp_finalize(PyObject *self);" -#: ../../c-api/typeobj.rst:2373 +#: ../../c-api/typeobj.rst:2419 msgid "" "The primary purpose of finalization is to perform any non-trivial cleanup " "that must be performed before the object is destroyed, while the object and " @@ -3642,7 +3685,7 @@ msgid "" "consistent state. The finalizer is allowed to execute arbitrary Python code." msgstr "" -#: ../../c-api/typeobj.rst:2379 +#: ../../c-api/typeobj.rst:2425 msgid "" "Before Python automatically finalizes an object, some of the object's direct " "or indirect referents might have themselves been automatically finalized. " @@ -3650,14 +3693,14 @@ msgid "" "member:`~PyTypeObject.tp_clear`) yet." msgstr "" -#: ../../c-api/typeobj.rst:2384 +#: ../../c-api/typeobj.rst:2430 msgid "" "Other non-finalized objects might still be using a finalized object, so the " "finalizer must leave the object in a sane state (e.g., invariants are still " "met)." msgstr "" -#: ../../c-api/typeobj.rst:2390 +#: ../../c-api/typeobj.rst:2436 msgid "" "After Python automatically finalizes an object, Python might start " "automatically clearing (:c:member:`~PyTypeObject.tp_clear`) the object and " @@ -3666,7 +3709,7 @@ msgid "" "cleared referents." msgstr "" -#: ../../c-api/typeobj.rst:2398 +#: ../../c-api/typeobj.rst:2444 msgid "" "An object is not guaranteed to be automatically finalized before its " "destructor (:c:member:`~PyTypeObject.tp_dealloc`) is called. It is " @@ -3675,25 +3718,25 @@ msgid "" "finalized before destruction." msgstr "" -#: ../../c-api/typeobj.rst:2406 +#: ../../c-api/typeobj.rst:2452 msgid "" "The :c:member:`~PyTypeObject.tp_finalize` function can be called from any " "thread, although the :term:`GIL` will be held." msgstr "" -#: ../../c-api/typeobj.rst:2411 +#: ../../c-api/typeobj.rst:2457 msgid "" "The :c:member:`!tp_finalize` function can be called during shutdown, after " "some global variables have been deleted. See the documentation of the :meth:" "`~object.__del__` method for details." msgstr "" -#: ../../c-api/typeobj.rst:2415 +#: ../../c-api/typeobj.rst:2461 msgid "" "When Python finalizes an object, it behaves like the following algorithm:" msgstr "" -#: ../../c-api/typeobj.rst:2417 +#: ../../c-api/typeobj.rst:2463 msgid "" "Python might mark the object as *finalized*. Currently, Python always marks " "objects whose type supports garbage collection (i.e., the :c:macro:" @@ -3701,13 +3744,13 @@ msgid "" "never marks other types of objects; this might change in a future version." msgstr "" -#: ../../c-api/typeobj.rst:2422 +#: ../../c-api/typeobj.rst:2468 msgid "" "If the object is not marked as *finalized* and its :c:member:`!tp_finalize` " "finalizer function is non-``NULL``, the finalizer function is called." msgstr "" -#: ../../c-api/typeobj.rst:2425 +#: ../../c-api/typeobj.rst:2471 msgid "" "If the finalizer function was called and the finalizer made the object " "reachable (i.e., there is a reference to the object and it is not a member " @@ -3717,7 +3760,7 @@ msgid "" "make it reachable, i.e., the object is (still) a member of a cyclic isolate." msgstr "" -#: ../../c-api/typeobj.rst:2432 +#: ../../c-api/typeobj.rst:2478 msgid "" "If the finalizer resurrected the object, the object's pending destruction is " "canceled and the object's *finalized* mark might be removed if present. " @@ -3725,7 +3768,7 @@ msgid "" "future version." msgstr "" -#: ../../c-api/typeobj.rst:2437 +#: ../../c-api/typeobj.rst:2483 msgid "" "*Automatic finalization* refers to any finalization performed by Python " "except via calls to :c:func:`PyObject_CallFinalizer` or :c:func:" @@ -3733,14 +3776,14 @@ msgid "" "or how often an object is automatically finalized, except:" msgstr "" -#: ../../c-api/typeobj.rst:2442 +#: ../../c-api/typeobj.rst:2488 msgid "" "Python will not automatically finalize an object if it is reachable, i.e., " "there is a reference to it and it is not a member of a :term:`cyclic " "isolate`." msgstr "" -#: ../../c-api/typeobj.rst:2445 +#: ../../c-api/typeobj.rst:2491 msgid "" "Python will not automatically finalize an object if finalizing it would not " "mark the object as *finalized*. Currently, this applies to objects whose " @@ -3750,53 +3793,53 @@ msgid "" "`PyObject_CallFinalizerFromDealloc`." msgstr "" -#: ../../c-api/typeobj.rst:2451 +#: ../../c-api/typeobj.rst:2497 msgid "" "Python will not automatically finalize any two members of a :term:`cyclic " "isolate` concurrently." msgstr "" -#: ../../c-api/typeobj.rst:2453 +#: ../../c-api/typeobj.rst:2499 msgid "" "Python will not automatically finalize an object after it has automatically " "cleared (:c:member:`~PyTypeObject.tp_clear`) the object." msgstr "" -#: ../../c-api/typeobj.rst:2455 +#: ../../c-api/typeobj.rst:2501 msgid "" "If an object is a member of a :term:`cyclic isolate`, Python will not " "automatically finalize it after automatically clearing (see :c:member:" "`~PyTypeObject.tp_clear`) any other member." msgstr "" -#: ../../c-api/typeobj.rst:2458 +#: ../../c-api/typeobj.rst:2504 msgid "" "Python will automatically finalize every member of a :term:`cyclic isolate` " "before it automatically clears (see :c:member:`~PyTypeObject.tp_clear`) any " "of them." msgstr "" -#: ../../c-api/typeobj.rst:2461 +#: ../../c-api/typeobj.rst:2507 msgid "" "If Python is going to automatically clear an object (:c:member:" "`~PyTypeObject.tp_clear`), it will automatically finalize the object first." msgstr "" -#: ../../c-api/typeobj.rst:2465 +#: ../../c-api/typeobj.rst:2511 msgid "" "Python currently only automatically finalizes objects that are members of a :" "term:`cyclic isolate`, but future versions might finalize objects regularly " "before their destruction." msgstr "" -#: ../../c-api/typeobj.rst:2469 +#: ../../c-api/typeobj.rst:2515 msgid "" "To manually finalize an object, do not call this function directly; call :c:" "func:`PyObject_CallFinalizer` or :c:func:`PyObject_CallFinalizerFromDealloc` " "instead." msgstr "" -#: ../../c-api/typeobj.rst:2473 +#: ../../c-api/typeobj.rst:2519 msgid "" ":c:member:`~PyTypeObject.tp_finalize` should leave the current exception " "status unchanged. The recommended way to write a non-trivial finalizer is " @@ -3807,7 +3850,7 @@ msgid "" "`PyErr_WriteUnraisable` or :c:func:`PyErr_FormatUnraisable`. For example::" msgstr "" -#: ../../c-api/typeobj.rst:2482 +#: ../../c-api/typeobj.rst:2528 msgid "" "static void\n" "foo_finalize(PyObject *self)\n" @@ -3830,26 +3873,26 @@ msgid "" "}" msgstr "" -#: ../../c-api/typeobj.rst:2510 +#: ../../c-api/typeobj.rst:2556 msgid "" "Before version 3.8 it was necessary to set the :c:macro:" "`Py_TPFLAGS_HAVE_FINALIZE` flags bit in order for this field to be used. " "This is no longer required." msgstr "" -#: ../../c-api/typeobj.rst:2516 +#: ../../c-api/typeobj.rst:2562 msgid ":pep:`442`: \"Safe object finalization\"" msgstr "" -#: ../../c-api/typeobj.rst:2519 +#: ../../c-api/typeobj.rst:2565 msgid ":c:func:`PyObject_CallFinalizer`" msgstr ":c:func:`PyObject_CallFinalizer`" -#: ../../c-api/typeobj.rst:2520 +#: ../../c-api/typeobj.rst:2566 msgid ":c:func:`PyObject_CallFinalizerFromDealloc`" msgstr ":c:func:`PyObject_CallFinalizerFromDealloc`" -#: ../../c-api/typeobj.rst:2527 +#: ../../c-api/typeobj.rst:2573 msgid "" "A :ref:`vectorcall function ` to use for calls of this type " "object (rather than instances). In other words, ``tp_vectorcall`` can be " @@ -3857,13 +3900,13 @@ msgid "" "of *type*." msgstr "" -#: ../../c-api/typeobj.rst:2532 +#: ../../c-api/typeobj.rst:2578 msgid "" "As with any vectorcall function, if ``tp_vectorcall`` is ``NULL``, the " "*tp_call* protocol (``Py_TYPE(type)->tp_call``) is used instead." msgstr "" -#: ../../c-api/typeobj.rst:2537 +#: ../../c-api/typeobj.rst:2583 msgid "" "The :ref:`vectorcall protocol ` requires that the vectorcall " "function has the same behavior as the corresponding ``tp_call``. This means " @@ -3871,27 +3914,27 @@ msgid "" ">tp_call``." msgstr "" -#: ../../c-api/typeobj.rst:2542 +#: ../../c-api/typeobj.rst:2588 msgid "" "Specifically, if *type* uses the default metaclass, ``type->tp_vectorcall`` " "must behave the same as :c:expr:`PyType_Type->tp_call`, which:" msgstr "" -#: ../../c-api/typeobj.rst:2546 +#: ../../c-api/typeobj.rst:2592 msgid "calls ``type->tp_new``," msgstr "呼叫 ``type->tp_new``," -#: ../../c-api/typeobj.rst:2548 +#: ../../c-api/typeobj.rst:2594 msgid "" "if the result is a subclass of *type*, calls ``type->tp_init`` on the result " "of ``tp_new``, and" msgstr "" -#: ../../c-api/typeobj.rst:2551 +#: ../../c-api/typeobj.rst:2597 msgid "returns the result of ``tp_new``." msgstr "回傳 ``tp_new`` 的結果。" -#: ../../c-api/typeobj.rst:2553 +#: ../../c-api/typeobj.rst:2599 msgid "" "Typically, ``tp_vectorcall`` is overridden to optimize this process for " "specific :c:member:`~PyTypeObject.tp_new` and :c:member:`~PyTypeObject." @@ -3900,65 +3943,65 @@ msgid "" "__init__`, respectively)." msgstr "" -#: ../../c-api/typeobj.rst:2564 +#: ../../c-api/typeobj.rst:2610 msgid "This field is never inherited." msgstr "" -#: ../../c-api/typeobj.rst:2566 +#: ../../c-api/typeobj.rst:2612 msgid "(the field exists since 3.8 but it's only used since 3.9)" msgstr "" -#: ../../c-api/typeobj.rst:2571 +#: ../../c-api/typeobj.rst:2617 msgid "Internal. Do not use." msgstr "" -#: ../../c-api/typeobj.rst:2579 +#: ../../c-api/typeobj.rst:2625 msgid "Static Types" msgstr "靜態型別" -#: ../../c-api/typeobj.rst:2581 +#: ../../c-api/typeobj.rst:2627 msgid "" "Traditionally, types defined in C code are *static*, that is, a static :c:" "type:`PyTypeObject` structure is defined directly in code and initialized " "using :c:func:`PyType_Ready`." msgstr "" -#: ../../c-api/typeobj.rst:2585 +#: ../../c-api/typeobj.rst:2631 msgid "" "This results in types that are limited relative to types defined in Python:" msgstr "" -#: ../../c-api/typeobj.rst:2587 +#: ../../c-api/typeobj.rst:2633 msgid "" "Static types are limited to one base, i.e. they cannot use multiple " "inheritance." msgstr "" -#: ../../c-api/typeobj.rst:2589 +#: ../../c-api/typeobj.rst:2635 msgid "" "Static type objects (but not necessarily their instances) are immutable. It " "is not possible to add or modify the type object's attributes from Python." msgstr "" -#: ../../c-api/typeobj.rst:2591 +#: ../../c-api/typeobj.rst:2637 msgid "" "Static type objects are shared across :ref:`sub-interpreters `, so they should not include any subinterpreter-" "specific state." msgstr "" -#: ../../c-api/typeobj.rst:2595 +#: ../../c-api/typeobj.rst:2641 msgid "" "Also, since :c:type:`PyTypeObject` is only part of the :ref:`Limited API " "` as an opaque struct, any extension modules using static " "types must be compiled for a specific Python minor version." msgstr "" -#: ../../c-api/typeobj.rst:2603 +#: ../../c-api/typeobj.rst:2649 msgid "Heap Types" msgstr "堆積型別" -#: ../../c-api/typeobj.rst:2605 +#: ../../c-api/typeobj.rst:2651 msgid "" "An alternative to :ref:`static types ` is *heap-allocated " "types*, or *heap types* for short, which correspond closely to classes " @@ -3966,29 +4009,29 @@ msgid "" "`Py_TPFLAGS_HEAPTYPE` flag set." msgstr "" -#: ../../c-api/typeobj.rst:2610 +#: ../../c-api/typeobj.rst:2656 msgid "" "This is done by filling a :c:type:`PyType_Spec` structure and calling :c:" "func:`PyType_FromSpec`, :c:func:`PyType_FromSpecWithBases`, :c:func:" "`PyType_FromModuleAndSpec`, or :c:func:`PyType_FromMetaclass`." msgstr "" -#: ../../c-api/typeobj.rst:2618 +#: ../../c-api/typeobj.rst:2664 msgid "Number Object Structures" msgstr "" -#: ../../c-api/typeobj.rst:2625 +#: ../../c-api/typeobj.rst:2671 msgid "" "This structure holds pointers to the functions which an object uses to " "implement the number protocol. Each function is used by the function of " "similar name documented in the :ref:`number` section." msgstr "" -#: ../../c-api/typeobj.rst:2631 ../../c-api/typeobj.rst:3087 +#: ../../c-api/typeobj.rst:2677 ../../c-api/typeobj.rst:3133 msgid "Here is the structure definition::" msgstr "" -#: ../../c-api/typeobj.rst:2633 +#: ../../c-api/typeobj.rst:2679 msgid "" "typedef struct {\n" " binaryfunc nb_add;\n" @@ -4076,7 +4119,7 @@ msgstr "" " binaryfunc nb_inplace_matrix_multiply;\n" "} PyNumberMethods;" -#: ../../c-api/typeobj.rst:2678 +#: ../../c-api/typeobj.rst:2724 msgid "" "Binary and ternary functions must check the type of all their operands, and " "implement the necessary conversions (at least one of the operands is an " @@ -4086,31 +4129,31 @@ msgid "" "and set an exception." msgstr "" -#: ../../c-api/typeobj.rst:2687 +#: ../../c-api/typeobj.rst:2733 msgid "" "The :c:member:`~PyNumberMethods.nb_reserved` field should always be " "``NULL``. It was previously called :c:member:`!nb_long`, and was renamed in " "Python 3.0.1." msgstr "" -#: ../../c-api/typeobj.rst:2838 +#: ../../c-api/typeobj.rst:2884 msgid "Mapping Object Structures" msgstr "對映物件結構" -#: ../../c-api/typeobj.rst:2845 +#: ../../c-api/typeobj.rst:2891 msgid "" "This structure holds pointers to the functions which an object uses to " "implement the mapping protocol. It has three members:" msgstr "" -#: ../../c-api/typeobj.rst:2852 +#: ../../c-api/typeobj.rst:2898 msgid "" "This function is used by :c:func:`PyMapping_Size` and :c:func:" "`PyObject_Size`, and has the same signature. This slot may be set to " "``NULL`` if the object has no defined length." msgstr "" -#: ../../c-api/typeobj.rst:2860 +#: ../../c-api/typeobj.rst:2906 msgid "" "This function is used by :c:func:`PyObject_GetItem` and :c:func:" "`PySequence_GetSlice`, and has the same signature as :c:func:`!" @@ -4118,7 +4161,7 @@ msgid "" "`PyMapping_Check` function to return ``1``, it can be ``NULL`` otherwise." msgstr "" -#: ../../c-api/typeobj.rst:2870 +#: ../../c-api/typeobj.rst:2916 msgid "" "This function is used by :c:func:`PyObject_SetItem`, :c:func:" "`PyObject_DelItem`, :c:func:`PySequence_SetSlice` and :c:func:" @@ -4128,17 +4171,17 @@ msgid "" "deletion." msgstr "" -#: ../../c-api/typeobj.rst:2881 +#: ../../c-api/typeobj.rst:2927 msgid "Sequence Object Structures" msgstr "序列物件結構" -#: ../../c-api/typeobj.rst:2888 +#: ../../c-api/typeobj.rst:2934 msgid "" "This structure holds pointers to the functions which an object uses to " "implement the sequence protocol." msgstr "" -#: ../../c-api/typeobj.rst:2895 +#: ../../c-api/typeobj.rst:2941 msgid "" "This function is used by :c:func:`PySequence_Size` and :c:func:" "`PyObject_Size`, and has the same signature. It is also used for handling " @@ -4146,21 +4189,21 @@ msgid "" "member:`~PySequenceMethods.sq_ass_item` slots." msgstr "" -#: ../../c-api/typeobj.rst:2904 +#: ../../c-api/typeobj.rst:2950 msgid "" "This function is used by :c:func:`PySequence_Concat` and has the same " "signature. It is also used by the ``+`` operator, after trying the numeric " "addition via the :c:member:`~PyNumberMethods.nb_add` slot." msgstr "" -#: ../../c-api/typeobj.rst:2912 +#: ../../c-api/typeobj.rst:2958 msgid "" "This function is used by :c:func:`PySequence_Repeat` and has the same " "signature. It is also used by the ``*`` operator, after trying numeric " "multiplication via the :c:member:`~PyNumberMethods.nb_multiply` slot." msgstr "" -#: ../../c-api/typeobj.rst:2920 +#: ../../c-api/typeobj.rst:2966 msgid "" "This function is used by :c:func:`PySequence_GetItem` and has the same " "signature. It is also used by :c:func:`PyObject_GetItem`, after trying the " @@ -4169,7 +4212,7 @@ msgid "" "``1``, it can be ``NULL`` otherwise." msgstr "" -#: ../../c-api/typeobj.rst:2926 +#: ../../c-api/typeobj.rst:2972 msgid "" "Negative indexes are handled as follows: if the :c:member:" "`~PySequenceMethods.sq_length` slot is filled, it is called and the sequence " @@ -4178,7 +4221,7 @@ msgid "" "index is passed as is to the function." msgstr "" -#: ../../c-api/typeobj.rst:2935 +#: ../../c-api/typeobj.rst:2981 msgid "" "This function is used by :c:func:`PySequence_SetItem` and has the same " "signature. It is also used by :c:func:`PyObject_SetItem` and :c:func:" @@ -4187,14 +4230,14 @@ msgid "" "``NULL`` if the object does not support item assignment and deletion." msgstr "" -#: ../../c-api/typeobj.rst:2946 +#: ../../c-api/typeobj.rst:2992 msgid "" "This function may be used by :c:func:`PySequence_Contains` and has the same " "signature. This slot may be left to ``NULL``, in this case :c:func:`!" "PySequence_Contains` simply traverses the sequence until it finds a match." msgstr "" -#: ../../c-api/typeobj.rst:2955 +#: ../../c-api/typeobj.rst:3001 msgid "" "This function is used by :c:func:`PySequence_InPlaceConcat` and has the same " "signature. It should modify its first operand, and return it. This slot " @@ -4204,7 +4247,7 @@ msgid "" "c:member:`~PyNumberMethods.nb_inplace_add` slot." msgstr "" -#: ../../c-api/typeobj.rst:2966 +#: ../../c-api/typeobj.rst:3012 msgid "" "This function is used by :c:func:`PySequence_InPlaceRepeat` and has the same " "signature. It should modify its first operand, and return it. This slot " @@ -4214,76 +4257,76 @@ msgid "" "via the :c:member:`~PyNumberMethods.nb_inplace_multiply` slot." msgstr "" -#: ../../c-api/typeobj.rst:2977 +#: ../../c-api/typeobj.rst:3023 msgid "Buffer Object Structures" msgstr "緩衝區物件結構" -#: ../../c-api/typeobj.rst:2985 +#: ../../c-api/typeobj.rst:3031 msgid "" "This structure holds pointers to the functions required by the :ref:`Buffer " "protocol `. The protocol defines how an exporter object can " "expose its internal data to consumer objects." msgstr "" -#: ../../c-api/typeobj.rst:2993 ../../c-api/typeobj.rst:3044 -#: ../../c-api/typeobj.rst:3100 ../../c-api/typeobj.rst:3113 -#: ../../c-api/typeobj.rst:3127 ../../c-api/typeobj.rst:3139 +#: ../../c-api/typeobj.rst:3039 ../../c-api/typeobj.rst:3090 +#: ../../c-api/typeobj.rst:3146 ../../c-api/typeobj.rst:3159 +#: ../../c-api/typeobj.rst:3173 ../../c-api/typeobj.rst:3185 msgid "The signature of this function is::" msgstr "函式的簽名為: ::" -#: ../../c-api/typeobj.rst:2995 +#: ../../c-api/typeobj.rst:3041 msgid "int (PyObject *exporter, Py_buffer *view, int flags);" msgstr "int (PyObject *exporter, Py_buffer *view, int flags);" -#: ../../c-api/typeobj.rst:2997 +#: ../../c-api/typeobj.rst:3043 msgid "" "Handle a request to *exporter* to fill in *view* as specified by *flags*. " "Except for point (3), an implementation of this function MUST take these " "steps:" msgstr "" -#: ../../c-api/typeobj.rst:3001 +#: ../../c-api/typeobj.rst:3047 msgid "" "Check if the request can be met. If not, raise :exc:`BufferError`, set :c:" "expr:`view->obj` to ``NULL`` and return ``-1``." msgstr "" -#: ../../c-api/typeobj.rst:3004 +#: ../../c-api/typeobj.rst:3050 msgid "Fill in the requested fields." msgstr "" -#: ../../c-api/typeobj.rst:3006 +#: ../../c-api/typeobj.rst:3052 msgid "Increment an internal counter for the number of exports." msgstr "" -#: ../../c-api/typeobj.rst:3008 +#: ../../c-api/typeobj.rst:3054 msgid "" "Set :c:expr:`view->obj` to *exporter* and increment :c:expr:`view->obj`." msgstr "" -#: ../../c-api/typeobj.rst:3010 +#: ../../c-api/typeobj.rst:3056 msgid "Return ``0``." msgstr "回傳 ``0``。" -#: ../../c-api/typeobj.rst:3012 +#: ../../c-api/typeobj.rst:3058 msgid "" "If *exporter* is part of a chain or tree of buffer providers, two main " "schemes can be used:" msgstr "" -#: ../../c-api/typeobj.rst:3015 +#: ../../c-api/typeobj.rst:3061 msgid "" "Re-export: Each member of the tree acts as the exporting object and sets :c:" "expr:`view->obj` to a new reference to itself." msgstr "" -#: ../../c-api/typeobj.rst:3018 +#: ../../c-api/typeobj.rst:3064 msgid "" "Redirect: The buffer request is redirected to the root object of the tree. " "Here, :c:expr:`view->obj` will be a new reference to the root object." msgstr "" -#: ../../c-api/typeobj.rst:3022 +#: ../../c-api/typeobj.rst:3068 msgid "" "The individual fields of *view* are described in section :ref:`Buffer " "structure `, the rules how an exporter must react to " @@ -4291,7 +4334,7 @@ msgid "" "types>`." msgstr "" -#: ../../c-api/typeobj.rst:3027 +#: ../../c-api/typeobj.rst:3073 msgid "" "All memory pointed to in the :c:type:`Py_buffer` structure belongs to the " "exporter and must remain valid until there are no consumers left. :c:member:" @@ -4300,23 +4343,23 @@ msgid "" "internal` are read-only for the consumer." msgstr "" -#: ../../c-api/typeobj.rst:3034 +#: ../../c-api/typeobj.rst:3080 msgid "" ":c:func:`PyBuffer_FillInfo` provides an easy way of exposing a simple bytes " "buffer while dealing correctly with all request types." msgstr "" -#: ../../c-api/typeobj.rst:3037 +#: ../../c-api/typeobj.rst:3083 msgid "" ":c:func:`PyObject_GetBuffer` is the interface for the consumer that wraps " "this function." msgstr "" -#: ../../c-api/typeobj.rst:3046 +#: ../../c-api/typeobj.rst:3092 msgid "void (PyObject *exporter, Py_buffer *view);" msgstr "void (PyObject *exporter, Py_buffer *view);" -#: ../../c-api/typeobj.rst:3048 +#: ../../c-api/typeobj.rst:3094 msgid "" "Handle a request to release the resources of the buffer. If no resources " "need to be released, :c:member:`PyBufferProcs.bf_releasebuffer` may be " @@ -4324,15 +4367,15 @@ msgid "" "these optional steps:" msgstr "" -#: ../../c-api/typeobj.rst:3053 +#: ../../c-api/typeobj.rst:3099 msgid "Decrement an internal counter for the number of exports." msgstr "" -#: ../../c-api/typeobj.rst:3055 +#: ../../c-api/typeobj.rst:3101 msgid "If the counter is ``0``, free all memory associated with *view*." msgstr "" -#: ../../c-api/typeobj.rst:3057 +#: ../../c-api/typeobj.rst:3103 msgid "" "The exporter MUST use the :c:member:`~Py_buffer.internal` field to keep " "track of buffer-specific resources. This field is guaranteed to remain " @@ -4340,30 +4383,30 @@ msgid "" "*view* argument." msgstr "" -#: ../../c-api/typeobj.rst:3063 +#: ../../c-api/typeobj.rst:3109 msgid "" "This function MUST NOT decrement :c:expr:`view->obj`, since that is done " "automatically in :c:func:`PyBuffer_Release` (this scheme is useful for " "breaking reference cycles)." msgstr "" -#: ../../c-api/typeobj.rst:3068 +#: ../../c-api/typeobj.rst:3114 msgid "" ":c:func:`PyBuffer_Release` is the interface for the consumer that wraps this " "function." msgstr "" -#: ../../c-api/typeobj.rst:3076 +#: ../../c-api/typeobj.rst:3122 msgid "Async Object Structures" msgstr "非同步物件結構" -#: ../../c-api/typeobj.rst:3084 +#: ../../c-api/typeobj.rst:3130 msgid "" "This structure holds pointers to the functions required to implement :term:" "`awaitable` and :term:`asynchronous iterator` objects." msgstr "" -#: ../../c-api/typeobj.rst:3089 +#: ../../c-api/typeobj.rst:3135 msgid "" "typedef struct {\n" " unaryfunc am_await;\n" @@ -4379,62 +4422,62 @@ msgstr "" " sendfunc am_send;\n" "} PyAsyncMethods;" -#: ../../c-api/typeobj.rst:3102 +#: ../../c-api/typeobj.rst:3148 msgid "PyObject *am_await(PyObject *self);" msgstr "PyObject *am_await(PyObject *self);" -#: ../../c-api/typeobj.rst:3104 +#: ../../c-api/typeobj.rst:3150 msgid "" "The returned object must be an :term:`iterator`, i.e. :c:func:`PyIter_Check` " "must return ``1`` for it." msgstr "" -#: ../../c-api/typeobj.rst:3107 +#: ../../c-api/typeobj.rst:3153 msgid "" "This slot may be set to ``NULL`` if an object is not an :term:`awaitable`." msgstr "" -#: ../../c-api/typeobj.rst:3115 +#: ../../c-api/typeobj.rst:3161 msgid "PyObject *am_aiter(PyObject *self);" msgstr "PyObject *am_aiter(PyObject *self);" -#: ../../c-api/typeobj.rst:3117 +#: ../../c-api/typeobj.rst:3163 msgid "" "Must return an :term:`asynchronous iterator` object. See :meth:`~object." "__anext__` for details." msgstr "" -#: ../../c-api/typeobj.rst:3120 +#: ../../c-api/typeobj.rst:3166 msgid "" "This slot may be set to ``NULL`` if an object does not implement " "asynchronous iteration protocol." msgstr "" -#: ../../c-api/typeobj.rst:3129 +#: ../../c-api/typeobj.rst:3175 msgid "PyObject *am_anext(PyObject *self);" msgstr "PyObject *am_anext(PyObject *self);" -#: ../../c-api/typeobj.rst:3131 +#: ../../c-api/typeobj.rst:3177 msgid "" "Must return an :term:`awaitable` object. See :meth:`~object.__anext__` for " "details. This slot may be set to ``NULL``." msgstr "" -#: ../../c-api/typeobj.rst:3141 +#: ../../c-api/typeobj.rst:3187 msgid "PySendResult am_send(PyObject *self, PyObject *arg, PyObject **result);" msgstr "" "PySendResult am_send(PyObject *self, PyObject *arg, PyObject **result);" -#: ../../c-api/typeobj.rst:3143 +#: ../../c-api/typeobj.rst:3189 msgid "" "See :c:func:`PyIter_Send` for details. This slot may be set to ``NULL``." msgstr "" -#: ../../c-api/typeobj.rst:3152 +#: ../../c-api/typeobj.rst:3198 msgid "Slot Type typedefs" msgstr "" -#: ../../c-api/typeobj.rst:3156 +#: ../../c-api/typeobj.rst:3202 msgid "" "The purpose of this function is to separate memory allocation from memory " "initialization. It should return a pointer to a block of memory of adequate " @@ -4448,80 +4491,80 @@ msgid "" "length of the block should be :c:member:`~PyTypeObject.tp_basicsize`." msgstr "" -#: ../../c-api/typeobj.rst:3166 +#: ../../c-api/typeobj.rst:3212 msgid "" "This function should not do any other instance initialization, not even to " "allocate additional memory; that should be done by :c:member:`~PyTypeObject." "tp_new`." msgstr "" -#: ../../c-api/typeobj.rst:3173 +#: ../../c-api/typeobj.rst:3219 msgid "See :c:member:`~PyTypeObject.tp_free`." msgstr "請見 :c:member:`~PyTypeObject.tp_free`。" -#: ../../c-api/typeobj.rst:3177 +#: ../../c-api/typeobj.rst:3223 msgid "See :c:member:`~PyTypeObject.tp_new`." msgstr "請見 :c:member:`~PyTypeObject.tp_new`。" -#: ../../c-api/typeobj.rst:3181 +#: ../../c-api/typeobj.rst:3227 msgid "See :c:member:`~PyTypeObject.tp_init`." msgstr "請見 :c:member:`~PyTypeObject.tp_init`。" -#: ../../c-api/typeobj.rst:3185 +#: ../../c-api/typeobj.rst:3231 msgid "See :c:member:`~PyTypeObject.tp_repr`." msgstr "請見 :c:member:`~PyTypeObject.tp_repr`。" -#: ../../c-api/typeobj.rst:3189 ../../c-api/typeobj.rst:3198 +#: ../../c-api/typeobj.rst:3235 ../../c-api/typeobj.rst:3244 msgid "Return the value of the named attribute for the object." msgstr "" -#: ../../c-api/typeobj.rst:3193 ../../c-api/typeobj.rst:3204 +#: ../../c-api/typeobj.rst:3239 ../../c-api/typeobj.rst:3250 msgid "" "Set the value of the named attribute for the object. The value argument is " "set to ``NULL`` to delete the attribute." msgstr "" -#: ../../c-api/typeobj.rst:3200 +#: ../../c-api/typeobj.rst:3246 msgid "See :c:member:`~PyTypeObject.tp_getattro`." msgstr "請見 :c:member:`~PyTypeObject.tp_getattro`。" -#: ../../c-api/typeobj.rst:3207 +#: ../../c-api/typeobj.rst:3253 msgid "See :c:member:`~PyTypeObject.tp_setattro`." msgstr "請見 :c:member:`~PyTypeObject.tp_setattro`。" -#: ../../c-api/typeobj.rst:3211 +#: ../../c-api/typeobj.rst:3257 msgid "See :c:member:`~PyTypeObject.tp_descr_get`." msgstr "請見 :c:member:`~PyTypeObject.tp_descr_get`。" -#: ../../c-api/typeobj.rst:3215 +#: ../../c-api/typeobj.rst:3261 msgid "See :c:member:`~PyTypeObject.tp_descr_set`." msgstr "請見 :c:member:`~PyTypeObject.tp_descr_set`。" -#: ../../c-api/typeobj.rst:3219 +#: ../../c-api/typeobj.rst:3265 msgid "See :c:member:`~PyTypeObject.tp_hash`." msgstr "請見 :c:member:`~PyTypeObject.tp_hash`。" -#: ../../c-api/typeobj.rst:3223 +#: ../../c-api/typeobj.rst:3269 msgid "See :c:member:`~PyTypeObject.tp_richcompare`." msgstr "請見 :c:member:`~PyTypeObject.tp_richcompare`。" -#: ../../c-api/typeobj.rst:3227 +#: ../../c-api/typeobj.rst:3273 msgid "See :c:member:`~PyTypeObject.tp_iter`." msgstr "請見 :c:member:`~PyTypeObject.tp_iter`。" -#: ../../c-api/typeobj.rst:3231 +#: ../../c-api/typeobj.rst:3277 msgid "See :c:member:`~PyTypeObject.tp_iternext`." msgstr "請見 :c:member:`~PyTypeObject.tp_iternext`。" -#: ../../c-api/typeobj.rst:3245 +#: ../../c-api/typeobj.rst:3291 msgid "See :c:member:`~PyAsyncMethods.am_send`." msgstr "請見 :c:member:`~PyAsyncMethods.am_send`。" -#: ../../c-api/typeobj.rst:3261 +#: ../../c-api/typeobj.rst:3307 msgid "Examples" msgstr "範例" -#: ../../c-api/typeobj.rst:3263 +#: ../../c-api/typeobj.rst:3309 msgid "" "The following are simple examples of Python type definitions. They include " "common usage you may encounter. Some demonstrate tricky corner cases. For " @@ -4529,11 +4572,11 @@ msgid "" "and :ref:`new-types-topics`." msgstr "" -#: ../../c-api/typeobj.rst:3268 +#: ../../c-api/typeobj.rst:3314 msgid "A basic :ref:`static type `::" msgstr "" -#: ../../c-api/typeobj.rst:3270 +#: ../../c-api/typeobj.rst:3316 msgid "" "typedef struct {\n" " PyObject_HEAD\n" @@ -4565,13 +4608,13 @@ msgstr "" " .tp_repr = (reprfunc)myobj_repr,\n" "};" -#: ../../c-api/typeobj.rst:3285 +#: ../../c-api/typeobj.rst:3331 msgid "" "You may also find older code (especially in the CPython code base) with a " "more verbose initializer::" msgstr "" -#: ../../c-api/typeobj.rst:3288 +#: ../../c-api/typeobj.rst:3334 msgid "" "static PyTypeObject MyObject_Type = {\n" " PyVarObject_HEAD_INIT(NULL, 0)\n" @@ -4655,11 +4698,11 @@ msgstr "" " myobj_new, /* tp_new */\n" "};" -#: ../../c-api/typeobj.rst:3329 +#: ../../c-api/typeobj.rst:3375 msgid "A type that supports weakrefs, instance dicts, and hashing::" msgstr "" -#: ../../c-api/typeobj.rst:3331 +#: ../../c-api/typeobj.rst:3377 msgid "" "typedef struct {\n" " PyObject_HEAD\n" @@ -4685,14 +4728,14 @@ msgid "" "};" msgstr "" -#: ../../c-api/typeobj.rst:3354 +#: ../../c-api/typeobj.rst:3400 msgid "" "A str subclass that cannot be subclassed and cannot be called to create " "instances (e.g. uses a separate factory func) using :c:macro:" "`Py_TPFLAGS_DISALLOW_INSTANTIATION` flag::" msgstr "" -#: ../../c-api/typeobj.rst:3358 +#: ../../c-api/typeobj.rst:3404 msgid "" "typedef struct {\n" " PyUnicodeObject raw;\n" @@ -4710,12 +4753,12 @@ msgid "" "};" msgstr "" -#: ../../c-api/typeobj.rst:3373 +#: ../../c-api/typeobj.rst:3419 msgid "" "The simplest :ref:`static type ` with fixed-length instances::" msgstr "" -#: ../../c-api/typeobj.rst:3375 +#: ../../c-api/typeobj.rst:3421 msgid "" "typedef struct {\n" " PyObject_HEAD\n" @@ -4735,13 +4778,13 @@ msgstr "" " .tp_name = \"mymod.MyObject\",\n" "};" -#: ../../c-api/typeobj.rst:3384 +#: ../../c-api/typeobj.rst:3430 msgid "" "The simplest :ref:`static type ` with variable-length " "instances::" msgstr "" -#: ../../c-api/typeobj.rst:3386 +#: ../../c-api/typeobj.rst:3432 msgid "" "typedef struct {\n" " PyObject_VAR_HEAD\n" diff --git a/faq/programming.po b/faq/programming.po index 393263fa6e6..906687c43fc 100644 --- a/faq/programming.po +++ b/faq/programming.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-19 00:20+0000\n" +"POT-Creation-Date: 2026-03-11 00:16+0000\n" "PO-Revision-Date: 2024-04-25 14:17+0800\n" "Last-Translator: KNChiu \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -30,16 +30,17 @@ msgid "Contents" msgstr "目錄" #: ../../faq/programming.rst:12 -msgid "General Questions" +#, fuzzy +msgid "General questions" msgstr "常見問題" #: ../../faq/programming.rst:15 +#, fuzzy msgid "" -"Is there a source code level debugger with breakpoints, single-stepping, " -"etc.?" +"Is there a source code-level debugger with breakpoints and single-stepping?" msgstr "是否有可以使用在程式碼階段,具有中斷點,步驟執行等功能的除錯器?" -#: ../../faq/programming.rst:17 ../../faq/programming.rst:58 +#: ../../faq/programming.rst:17 ../../faq/programming.rst:56 msgid "Yes." msgstr "有的。" @@ -63,17 +64,17 @@ msgstr "" "碼作為範例來編寫自己的除錯器。" #: ../../faq/programming.rst:27 +#, fuzzy msgid "" "The IDLE interactive development environment, which is part of the standard " -"Python distribution (normally available as `Tools/scripts/idle3 `_), includes a " +"Python distribution (normally available as :mod:`idlelib`), includes a " "graphical debugger." msgstr "" "IDLE 交互式開發環境,它是標準 Python 發行版的一部分(通常作為 `Tools/scripts/" "idle3 `_ 提" "供),包括一個圖形除錯器。" -#: ../../faq/programming.rst:32 +#: ../../faq/programming.rst:31 msgid "" "PythonWin is a Python IDE that includes a GUI debugger based on pdb. The " "PythonWin debugger colors breakpoints and has quite a few cool features such " @@ -87,7 +88,7 @@ msgstr "" "為 `pywin32 `_ 專案的一部分和作為 " "`ActivePython `_ 的一部分發佈。" -#: ../../faq/programming.rst:39 +#: ../../faq/programming.rst:38 msgid "" "`Eric `_ is an IDE built on PyQt and " "the Scintilla editing component." @@ -95,7 +96,7 @@ msgstr "" "`Eric `_ 是一個基於 PyQt 和 Scintilla " "編輯元件所建構的 IDE。" -#: ../../faq/programming.rst:42 +#: ../../faq/programming.rst:41 msgid "" "`trepan3k `_ is a gdb-like " "debugger." @@ -103,7 +104,7 @@ msgstr "" "`trepan3k `_ 是一個類似 gdb 的除錯" "器。" -#: ../../faq/programming.rst:44 +#: ../../faq/programming.rst:43 msgid "" "`Visual Studio Code `_ is an IDE with " "debugging tools that integrates with version-control software." @@ -111,42 +112,41 @@ msgstr "" "`Visual Studio Code `_ 是一個整合了版本控制軟" "體與除錯工具的 IDE。" -#: ../../faq/programming.rst:47 +#: ../../faq/programming.rst:46 msgid "" "There are a number of commercial Python IDEs that include graphical " "debuggers. They include:" msgstr "有數個商業化Python整合化開發工具包含圖形除錯功能。這些包含:" -#: ../../faq/programming.rst:50 +#: ../../faq/programming.rst:49 msgid "`Wing IDE `_" msgstr "`Wing IDE `_" -#: ../../faq/programming.rst:51 -msgid "`Komodo IDE `_" -msgstr "`Komodo IDE `_" - -#: ../../faq/programming.rst:52 +#: ../../faq/programming.rst:50 msgid "`PyCharm `_" msgstr "`PyCharm `_" -#: ../../faq/programming.rst:56 +#: ../../faq/programming.rst:54 msgid "Are there tools to help find bugs or perform static analysis?" msgstr "有沒有工具能夠幫忙找 bug 或執行靜態分析?" -#: ../../faq/programming.rst:60 +#: ../../faq/programming.rst:58 +#, fuzzy msgid "" -"`Pylint `_ and `Pyflakes " -"`_ do basic checking that will help you " -"catch bugs sooner." +"`Ruff `__, `Pylint `__ and `Pyflakes `__ do basic " +"checking that will help you catch bugs sooner." msgstr "" "`Pylint `_ 和 `Pyflakes " "`_ 進行基本檢查以幫助你儘早抓出錯誤。" -#: ../../faq/programming.rst:64 +#: ../../faq/programming.rst:63 +#, fuzzy msgid "" -"Static type checkers such as `Mypy `_, `Pyre " -"`_, and `Pytype `_ can check type hints in Python source code." +"Static type checkers such as `mypy `__, `ty `__, `Pyrefly `__, and `pytype " +"`__ can check type hints in Python source " +"code." msgstr "" "靜態型別檢查器,例如 `Mypy `_、`Pyre `_ 和 `Pytype `_ 可以檢查 " @@ -169,12 +169,12 @@ msgstr "" "集,並將這些模組與 Python 二進位檔案綁定在一起以產生單個可執行檔。" #: ../../faq/programming.rst:81 +#, fuzzy msgid "" "One is to use the freeze tool, which is included in the Python source tree " -"as `Tools/freeze `_. It converts Python byte code to C arrays; with a C compiler you " -"can embed all your modules into a new program, which is then linked with the " -"standard Python modules." +"as :source:`Tools/freeze`. It converts Python byte code to C arrays; with a " +"C compiler you can embed all your modules into a new program, which is then " +"linked with the standard Python modules." msgstr "" "一種是使用 freeze 工具,它位於 Python 原始碼樹中的 `Tools/freeze `_。它將 Python 位元組碼轉換" @@ -235,25 +235,26 @@ msgstr "`py2app `_\\ (僅限 macOS msgid "`py2exe `_ (Windows only)" msgstr "`py2exe `_\\ (僅限 Windows)" -#: ../../faq/programming.rst:107 +#: ../../faq/programming.rst:108 msgid "Are there coding standards or a style guide for Python programs?" msgstr "Python 程式碼是否有編碼標準或風格指南?" -#: ../../faq/programming.rst:109 +#: ../../faq/programming.rst:110 msgid "" "Yes. The coding style required for standard library modules is documented " "as :pep:`8`." msgstr "是的。標準函式庫模組所需的編碼風格稱為 :pep:`8`。" -#: ../../faq/programming.rst:114 -msgid "Core Language" +#: ../../faq/programming.rst:115 +#, fuzzy +msgid "Core language" msgstr "核心語言" -#: ../../faq/programming.rst:119 +#: ../../faq/programming.rst:120 msgid "Why am I getting an UnboundLocalError when the variable has a value?" msgstr "為什麼當變數有值時,我仍得到錯誤訊息 UnboundLocalError?" -#: ../../faq/programming.rst:121 +#: ../../faq/programming.rst:122 #, fuzzy msgid "" "It can be a surprise to get the :exc:`UnboundLocalError` in previously " @@ -263,19 +264,19 @@ msgstr "" "當透過在函式主體的某處新增賦值陳述式修改以前的工作程式碼時,在以前的工作程式" "碼中得到 :exc:`UnboundLocalError` 可能會令人驚訝。" -#: ../../faq/programming.rst:125 +#: ../../faq/programming.rst:126 msgid "This code:" msgstr "這段程式碼:" -#: ../../faq/programming.rst:134 +#: ../../faq/programming.rst:135 msgid "works, but this code:" msgstr "可以執行,但是這段程式:" -#: ../../faq/programming.rst:141 +#: ../../faq/programming.rst:142 msgid "results in an :exc:`!UnboundLocalError`:" msgstr "導致 :exc:`!UnboundLocalError`:" -#: ../../faq/programming.rst:148 +#: ../../faq/programming.rst:149 #, fuzzy msgid "" "This is because when you make an assignment to a variable in a scope, that " @@ -290,13 +291,13 @@ msgstr "" "一個新值,因此編譯器將其識別為局部變數。因此,當較早的 ``print(x)`` 嘗試印出" "未初始化的局部變數並產生錯誤時。" -#: ../../faq/programming.rst:155 +#: ../../faq/programming.rst:156 msgid "" "In the example above you can access the outer scope variable by declaring it " "global:" msgstr "在上面的範例中,你可以透過將其聲明為全域變數來存取外部範圍變數:" -#: ../../faq/programming.rst:167 +#: ../../faq/programming.rst:168 #, fuzzy msgid "" "This explicit declaration is required in order to remind you that (unlike " @@ -306,17 +307,17 @@ msgstr "" "需要此顯式聲明是為了提醒你(與類別和實例變數表面上類似的情況不同)你實際上是" "在外部範圍內修改變數的值:" -#: ../../faq/programming.rst:174 +#: ../../faq/programming.rst:175 msgid "" "You can do a similar thing in a nested scope using the :keyword:`nonlocal` " "keyword:" msgstr "你可以使用 :keyword:`nonlocal` 關鍵字在巢狀作用域內做類似的事情:" -#: ../../faq/programming.rst:192 +#: ../../faq/programming.rst:193 msgid "What are the rules for local and global variables in Python?" msgstr "Python 的區域變數和全域變數有什麼規則?" -#: ../../faq/programming.rst:194 +#: ../../faq/programming.rst:195 #, fuzzy msgid "" "In Python, variables that are only referenced inside a function are " @@ -327,7 +328,7 @@ msgstr "" "在 Python 中,僅在函式內部參照的變數是隱式全域變數。如果一個變數在函式體內的" "任何地方被賦值,除非明確聲明為全域變數,否則它被假定為局部變數。" -#: ../../faq/programming.rst:198 +#: ../../faq/programming.rst:199 #, fuzzy msgid "" "Though a bit surprising at first, a moment's consideration explains this. " @@ -343,20 +344,21 @@ msgstr "" "``global``,那麼你將一直使用 ``global``。你必須將對內建函式或引入模組的組件的" "每個參照聲明為全域。這種混亂會破壞用於識別副作用的 ``global`` 聲明的有用性。" -#: ../../faq/programming.rst:208 +#: ../../faq/programming.rst:209 msgid "" "Why do lambdas defined in a loop with different values all return the same " "result?" msgstr "為什麼以不同的值在迴圈中定義的 lambda 都回傳相同的結果?" -#: ../../faq/programming.rst:210 +#: ../../faq/programming.rst:211 +#, fuzzy msgid "" "Assume you use a for loop to define a few different lambdas (or even plain " -"functions), e.g.::" +"functions), for example::" msgstr "" "假設你使用 for 迴圈來定義幾個不同的 lambda(甚至是普通函式),例如: ::" -#: ../../faq/programming.rst:213 +#: ../../faq/programming.rst:214 msgid "" ">>> squares = []\n" ">>> for x in range(5):\n" @@ -366,7 +368,7 @@ msgstr "" ">>> for x in range(5):\n" "... squares.append(lambda: x**2)" -#: ../../faq/programming.rst:217 +#: ../../faq/programming.rst:218 msgid "" "This gives you a list that contains 5 lambdas that calculate ``x**2``. You " "might expect that, when called, they would return, respectively, ``0``, " @@ -377,7 +379,7 @@ msgstr "" "們會分別回傳 ``0``、``1``、``4``、``9`` 和 ``16``,然而當你實際嘗試你會發現它" "們都回傳 ``16``: ::" -#: ../../faq/programming.rst:222 +#: ../../faq/programming.rst:223 msgid "" ">>> squares[2]()\n" "16\n" @@ -389,20 +391,22 @@ msgstr "" ">>> squares[4]()\n" "16" -#: ../../faq/programming.rst:227 +#: ../../faq/programming.rst:228 +#, fuzzy msgid "" "This happens because ``x`` is not local to the lambdas, but is defined in " "the outer scope, and it is accessed when the lambda is called --- not when " "it is defined. At the end of the loop, the value of ``x`` is ``4``, so all " -"the functions now return ``4**2``, i.e. ``16``. You can also verify this by " -"changing the value of ``x`` and see how the results of the lambdas change::" +"the functions now return ``4**2``, that is ``16``. You can also verify this " +"by changing the value of ``x`` and see how the results of the lambdas " +"change::" msgstr "" "發生這種情況是因為 ``x`` 不是 lambda 的局部變數,而是在外部作用域中定義的,且" "是在呼叫 lambda 時才會存取它,並非於定義時就會存取。在迴圈結束時,``x`` 的值" "為 ``4``,因此所有函式都回傳 ``4**2``,即為 ``16``。你還可以透過更改 ``x`` 的" "值來驗證這一點,並查看 lambda 運算式的結果如何變化: ::" -#: ../../faq/programming.rst:233 +#: ../../faq/programming.rst:234 msgid "" ">>> x = 8\n" ">>> squares[2]()\n" @@ -412,7 +416,7 @@ msgstr "" ">>> squares[2]()\n" "64" -#: ../../faq/programming.rst:237 +#: ../../faq/programming.rst:238 msgid "" "In order to avoid this, you need to save the values in variables local to " "the lambdas, so that they don't rely on the value of the global ``x``::" @@ -420,7 +424,7 @@ msgstr "" "為了避免這種情況,你需要將值保存在 lambda 的局部變數中,這樣它們就不會依賴於" "全域 ``x`` 的值: ::" -#: ../../faq/programming.rst:240 +#: ../../faq/programming.rst:241 msgid "" ">>> squares = []\n" ">>> for x in range(5):\n" @@ -430,7 +434,7 @@ msgstr "" ">>> for x in range(5):\n" "... squares.append(lambda n=x: n**2)" -#: ../../faq/programming.rst:244 +#: ../../faq/programming.rst:245 #, fuzzy msgid "" "Here, ``n=x`` creates a new variable ``n`` local to the lambda and computed " @@ -444,7 +448,7 @@ msgstr "" "lambda 中為 ``0`` ,在第二個中為 ``1`` ,在第三個中為 ``2`` ,依此類推。因此" "每個 lambda 現在將回傳正確的結果: ::" -#: ../../faq/programming.rst:250 +#: ../../faq/programming.rst:251 msgid "" ">>> squares[2]()\n" "4\n" @@ -456,17 +460,17 @@ msgstr "" ">>> squares[4]()\n" "16" -#: ../../faq/programming.rst:255 +#: ../../faq/programming.rst:256 msgid "" "Note that this behaviour is not peculiar to lambdas, but applies to regular " "functions too." msgstr "請注意,此行為並非 lambda 所特有,也適用於常規函式。" -#: ../../faq/programming.rst:260 +#: ../../faq/programming.rst:261 msgid "How do I share global variables across modules?" msgstr "如何跨模組共享全域變數?" -#: ../../faq/programming.rst:262 +#: ../../faq/programming.rst:263 #, fuzzy msgid "" "The canonical way to share information across modules within a single " @@ -481,19 +485,19 @@ msgstr "" "因為每個模組只有一個實例,所以對模組物件所做的任何更改都會在各處反映出來。例" "如:" -#: ../../faq/programming.rst:268 +#: ../../faq/programming.rst:269 msgid "config.py::" msgstr "config.py: ::" -#: ../../faq/programming.rst:270 +#: ../../faq/programming.rst:271 msgid "x = 0 # Default value of the 'x' configuration setting" msgstr "x = 0 # 'x' 配置設定的預設值" -#: ../../faq/programming.rst:272 +#: ../../faq/programming.rst:273 msgid "mod.py::" msgstr "mod.py: ::" -#: ../../faq/programming.rst:274 +#: ../../faq/programming.rst:275 msgid "" "import config\n" "config.x = 1" @@ -501,11 +505,11 @@ msgstr "" "import config\n" "config.x = 1" -#: ../../faq/programming.rst:277 +#: ../../faq/programming.rst:278 msgid "main.py::" msgstr "main.py: ::" -#: ../../faq/programming.rst:279 +#: ../../faq/programming.rst:280 msgid "" "import config\n" "import mod\n" @@ -515,17 +519,17 @@ msgstr "" "import mod\n" "print(config.x)" -#: ../../faq/programming.rst:283 +#: ../../faq/programming.rst:284 msgid "" "Note that using a module is also the basis for implementing the singleton " "design pattern, for the same reason." msgstr "請注意,出於同樣的原因,使用模組也是實作單例設計模式的基礎。" -#: ../../faq/programming.rst:288 +#: ../../faq/programming.rst:289 msgid "What are the \"best practices\" for using import in a module?" msgstr "在模組中使用 import 的「最佳實踐」有哪些?" -#: ../../faq/programming.rst:290 +#: ../../faq/programming.rst:291 #, fuzzy msgid "" "In general, don't use ``from modulename import *``. Doing so clutters the " @@ -535,7 +539,7 @@ msgstr "" "一般來說,不要使用``from modulename import *``。這樣做會使引入器的命名空間混" "亂,並使 linters 更難檢測未定義的名稱。" -#: ../../faq/programming.rst:294 +#: ../../faq/programming.rst:295 #, fuzzy msgid "" "Import modules at the top of a file. Doing so makes it clear what other " @@ -547,39 +551,40 @@ msgstr "" "是否在範圍內的問題。每行使用一個引入可以輕鬆新增和刪除模組引入,但每行使用多" "個引入會佔用更少的屏幕空間。" -#: ../../faq/programming.rst:299 +#: ../../faq/programming.rst:300 #, fuzzy msgid "It's good practice if you import modules in the following order:" msgstr "如果你按以下順序引入模組,這是一個很好的做法:" -#: ../../faq/programming.rst:301 +#: ../../faq/programming.rst:302 +#, fuzzy msgid "" -"standard library modules -- e.g. :mod:`sys`, :mod:`os`, :mod:`argparse`, :" +"standard library modules -- such as :mod:`sys`, :mod:`os`, :mod:`argparse`, :" "mod:`re`" msgstr "" "標準函式庫模組 —— 例如 :mod:`sys`、:mod:`os`、:mod:`argparse`、:mod:`re`" -#: ../../faq/programming.rst:302 +#: ../../faq/programming.rst:303 #, fuzzy msgid "" "third-party library modules (anything installed in Python's site-packages " -"directory) -- e.g. :mod:`!dateutil`, :mod:`!requests`, :mod:`!PIL.Image`" +"directory) -- such as :pypi:`dateutil`, :pypi:`requests`, :pypi:`tzdata`" msgstr "" "第三方函式庫模組(任何安裝在 Python 的站點包目錄中的模組)——例如:mod:`!" "dateutil`, :mod:`!requests`, :mod:`!PIL.Image`" -#: ../../faq/programming.rst:304 +#: ../../faq/programming.rst:305 msgid "locally developed modules" msgstr "本地開發的模組" -#: ../../faq/programming.rst:306 +#: ../../faq/programming.rst:307 #, fuzzy msgid "" "It is sometimes necessary to move imports to a function or class to avoid " "problems with circular imports. Gordon McMillan says:" msgstr "有時需要將引入移動到函式或類別以避免循環引入的問題。戈登麥克米蘭 說:" -#: ../../faq/programming.rst:309 +#: ../../faq/programming.rst:310 #, fuzzy msgid "" "Circular imports are fine where both modules use the \"import \" " @@ -593,7 +598,7 @@ msgstr "" "於頂層時,它們會失敗。那是因為 1st 中的名稱尚不可用,因為第一個模組正忙於導" "入 2nd。" -#: ../../faq/programming.rst:315 +#: ../../faq/programming.rst:316 #, fuzzy msgid "" "In this case, if the second module is only used in one function, then the " @@ -604,7 +609,7 @@ msgstr "" "在這種情況下,如果第二個模組只在一個函式中使用,那麼引入可以很容易地移到那個" "函式中。在呼叫引入時,第一個模組將完成初始化,第二個模組可以進行引入。" -#: ../../faq/programming.rst:320 +#: ../../faq/programming.rst:321 #, fuzzy msgid "" "It may also be necessary to move imports out of the top level of code if " @@ -617,7 +622,7 @@ msgstr "" "下,甚至可能無法引入檔案頂部的所有模組。在這種情況下,在相應的特定於平台的程" "式碼中引入正確的模組是一個不錯的選擇。" -#: ../../faq/programming.rst:325 +#: ../../faq/programming.rst:326 #, fuzzy msgid "" "Only move imports into a local scope, such as inside a function definition, " @@ -638,17 +643,17 @@ msgstr "" "組實際上是免費的,只需幾次字典查詢。即使模組名稱超出範圍,該模組也可能在 :" "data:`sys.modules` 中可用。" -#: ../../faq/programming.rst:338 +#: ../../faq/programming.rst:339 msgid "Why are default values shared between objects?" msgstr "為什麼物件之間共享預設值?" -#: ../../faq/programming.rst:340 +#: ../../faq/programming.rst:341 msgid "" "This type of bug commonly bites neophyte programmers. Consider this " "function::" msgstr "這種類型的錯誤通常會困擾新手程式員。像是這個函式: ::" -#: ../../faq/programming.rst:342 +#: ../../faq/programming.rst:343 msgid "" "def foo(mydict={}): # Danger: shared reference to one dict for all calls\n" " ... compute something ...\n" @@ -660,7 +665,7 @@ msgstr "" " mydict[key] = value\n" " return mydict" -#: ../../faq/programming.rst:347 +#: ../../faq/programming.rst:348 msgid "" "The first time you call this function, ``mydict`` contains a single item. " "The second time, ``mydict`` contains two items because when ``foo()`` begins " @@ -669,7 +674,7 @@ msgstr "" "第一次呼叫此函式時, ``mydict`` 包含一個項目。第二次後 ``mydict`` 包含兩個項" "目,因為當 ``foo()`` 開始執行時,``mydict`` 以其中已有的項目開始。" -#: ../../faq/programming.rst:351 +#: ../../faq/programming.rst:352 #, fuzzy msgid "" "It is often expected that a function call creates new objects for default " @@ -682,7 +687,7 @@ msgstr "" "建立一次。如果該物件發生更改,如本例中的字典,則對該函式的後續呼叫將參照該已" "更改的物件。" -#: ../../faq/programming.rst:356 +#: ../../faq/programming.rst:357 #, fuzzy msgid "" "By definition, immutable objects such as numbers, strings, tuples, and " @@ -692,7 +697,7 @@ msgstr "" "根據定義,數字、字串、元組和 ``None`` 等不可變物件是安全的,不會發生變化。對" "字典、串列和類別實例等可變物件的更改可能會導致混淆。" -#: ../../faq/programming.rst:360 +#: ../../faq/programming.rst:361 msgid "" "Because of this feature, it is good programming practice to not use mutable " "objects as default values. Instead, use ``None`` as the default value and " @@ -703,7 +708,7 @@ msgstr "" "``None`` 作為預設值,並在函式內部檢查參數是否為 ``None``,再建立一個新的串列/" "字典/或其他東西。例如,不要這樣寫: ::" -#: ../../faq/programming.rst:365 +#: ../../faq/programming.rst:366 msgid "" "def foo(mydict={}):\n" " ..." @@ -711,11 +716,11 @@ msgstr "" "def foo(mydict={}):\n" " ..." -#: ../../faq/programming.rst:368 +#: ../../faq/programming.rst:369 msgid "but::" msgstr "而是寫成: ::" -#: ../../faq/programming.rst:370 +#: ../../faq/programming.rst:371 msgid "" "def foo(mydict=None):\n" " if mydict is None:\n" @@ -725,7 +730,7 @@ msgstr "" " if mydict is None:\n" " mydict = {} # 為區域命名空間建立一個新字典" -#: ../../faq/programming.rst:374 +#: ../../faq/programming.rst:375 #, fuzzy msgid "" "This feature can be useful. When you have a function that's time-consuming " @@ -738,7 +743,7 @@ msgstr "" "和每次呼叫該函式的結果值,並在再次請求相同的值時回傳快取的值。這稱為「記憶" "化」,可以像這樣實作: ::" -#: ../../faq/programming.rst:379 +#: ../../faq/programming.rst:380 msgid "" "# Callers can only provide two parameters and optionally pass _cache by " "keyword\n" @@ -761,18 +766,18 @@ msgstr "" " _cache[(arg1, arg2)] = result # 將結果儲存在快取中\n" " return result" -#: ../../faq/programming.rst:389 +#: ../../faq/programming.rst:390 msgid "" "You could use a global variable containing a dictionary instead of the " "default value; it's a matter of taste." msgstr "你可以使用包含字典的全域變數而不是預設值;這取決於喜好。" -#: ../../faq/programming.rst:394 +#: ../../faq/programming.rst:395 msgid "" "How can I pass optional or keyword parameters from one function to another?" msgstr "如何將可選參數或關鍵字參數從一個函式傳遞到另一個函式?" -#: ../../faq/programming.rst:396 +#: ../../faq/programming.rst:397 #, fuzzy msgid "" "Collect the arguments using the ``*`` and ``**`` specifiers in the " @@ -784,7 +789,7 @@ msgstr "" "置引數和作為字典的關鍵字引數。然後,你可以在使用 ``*`` 和 ``**`` 呼叫另一個函" "式時傳遞這些引數: ::" -#: ../../faq/programming.rst:401 +#: ../../faq/programming.rst:402 msgid "" "def f(x, *args, **kwargs):\n" " ...\n" @@ -798,11 +803,11 @@ msgstr "" " ...\n" " g(x, *args, **kwargs)" -#: ../../faq/programming.rst:415 +#: ../../faq/programming.rst:416 msgid "What is the difference between arguments and parameters?" msgstr "引數 (arguments) 和參數 (parameters) 有什麼區別?" -#: ../../faq/programming.rst:417 +#: ../../faq/programming.rst:418 msgid "" ":term:`Parameters ` are defined by the names that appear in a " "function definition, whereas :term:`arguments ` are the values " @@ -814,7 +819,7 @@ msgstr "" "`\\ 是呼叫函式時實際傳遞給函式的值。參數定義函式可以接受的\\ :term:" "`引數種類 `。例如,給定以下函式定義: ::" -#: ../../faq/programming.rst:423 +#: ../../faq/programming.rst:424 msgid "" "def func(foo, bar=None, **kwargs):\n" " pass" @@ -822,7 +827,7 @@ msgstr "" "def func(foo, bar=None, **kwargs):\n" " pass" -#: ../../faq/programming.rst:426 +#: ../../faq/programming.rst:427 msgid "" "*foo*, *bar* and *kwargs* are parameters of ``func``. However, when calling " "``func``, for example::" @@ -830,23 +835,23 @@ msgstr "" "*foo*、*bar* 和 *kwargs* 是 ``func`` 的參數。然而當呼叫 ``func`` 時,例" "如: ::" -#: ../../faq/programming.rst:429 +#: ../../faq/programming.rst:430 msgid "func(42, bar=314, extra=somevar)" msgstr "func(42, bar=314, extra=somevar)" -#: ../../faq/programming.rst:431 +#: ../../faq/programming.rst:432 msgid "the values ``42``, ``314``, and ``somevar`` are arguments." msgstr "``42``、``314`` 和 ``somevar`` 是引數。" -#: ../../faq/programming.rst:435 +#: ../../faq/programming.rst:436 msgid "Why did changing list 'y' also change list 'x'?" msgstr "為什麼更改串列 'y' 也會更改串列 'x'?" -#: ../../faq/programming.rst:437 +#: ../../faq/programming.rst:438 msgid "If you wrote code like::" msgstr "如果你寫了像這樣的程式碼: ::" -#: ../../faq/programming.rst:439 +#: ../../faq/programming.rst:440 msgid "" ">>> x = []\n" ">>> y = x\n" @@ -864,16 +869,16 @@ msgstr "" ">>> x\n" "[10]" -#: ../../faq/programming.rst:447 +#: ../../faq/programming.rst:448 msgid "" "you might be wondering why appending an element to ``y`` changed ``x`` too." msgstr "你可能想知道為什麼將一個元素附加到 ``y`` 時也會改變 ``x``。" -#: ../../faq/programming.rst:449 +#: ../../faq/programming.rst:450 msgid "There are two factors that produce this result:" msgstr "產生這個結果的原因有兩個:" -#: ../../faq/programming.rst:451 +#: ../../faq/programming.rst:452 #, fuzzy msgid "" "Variables are simply names that refer to objects. Doing ``y = x`` doesn't " @@ -885,12 +890,12 @@ msgstr "" "數 ``y``,它指向 ``x`` 指向的同一物件。這意味著只有一個物件(list),並且 " "``x`` 和 ``y`` 都參照它。" -#: ../../faq/programming.rst:455 +#: ../../faq/programming.rst:456 msgid "" "Lists are :term:`mutable`, which means that you can change their content." msgstr "list 是 :term:`mutable`,這意味著你可以變更它們的內容。" -#: ../../faq/programming.rst:457 +#: ../../faq/programming.rst:458 msgid "" "After the call to :meth:`~sequence.append`, the content of the mutable " "object has changed from ``[]`` to ``[10]``. Since both the variables refer " @@ -900,11 +905,11 @@ msgstr "" "``[10]``。由於這兩個變數都參照同一個物件,因此使用任一名稱都可以存取修改後的" "值 ``[10]``。" -#: ../../faq/programming.rst:461 +#: ../../faq/programming.rst:462 msgid "If we instead assign an immutable object to ``x``::" msgstr "如果我們改為賦予一個不可變物件給 ``x``: ::" -#: ../../faq/programming.rst:463 +#: ../../faq/programming.rst:464 msgid "" ">>> x = 5 # ints are immutable\n" ">>> y = x\n" @@ -922,7 +927,7 @@ msgstr "" ">>> y\n" "5" -#: ../../faq/programming.rst:471 +#: ../../faq/programming.rst:472 #, fuzzy msgid "" "we can see that in this case ``x`` and ``y`` are not equal anymore. This is " @@ -939,7 +944,7 @@ msgstr "" "件)。在這個賦值之後,我們有兩個物件(整數 ``6`` 和 ``5``)和兩個參照它們的變" "數(``x`` 現在指的是 ``6`` 但 ``y`` 仍然指的是``5``)。" -#: ../../faq/programming.rst:479 +#: ../../faq/programming.rst:480 #, fuzzy msgid "" "Some operations (for example ``y.append(10)`` and ``y.sort()``) mutate the " @@ -958,7 +963,7 @@ msgstr "" "sort()``,認為它會為你提供 ``y`` 的排序副本,那麼你最終會得到 ``None``,這可" "能會導致你的程式生成一個容易診斷的錯誤。" -#: ../../faq/programming.rst:488 +#: ../../faq/programming.rst:489 #, fuzzy msgid "" "However, there is one class of operations where the same operation sometimes " @@ -973,25 +978,25 @@ msgstr "" "``a_list.extend([1, 2, 3])``並改變 ``a_list``,而 ``some_tuple += (1, 2, " "3)`` 和 ``some_int += 1`` 建立新物件)。" -#: ../../faq/programming.rst:495 +#: ../../faq/programming.rst:496 msgid "In other words:" msgstr "換句話說:" -#: ../../faq/programming.rst:497 +#: ../../faq/programming.rst:498 #, fuzzy msgid "" -"If we have a mutable object (:class:`list`, :class:`dict`, :class:`set`, " -"etc.), we can use some specific operations to mutate it and all the " +"If we have a mutable object (such as :class:`list`, :class:`dict`, :class:" +"`set`), we can use some specific operations to mutate it and all the " "variables that refer to it will see the change." msgstr "" "如果我們有一個可變物件(:class:`list`、:class:`dict`、:class:`set` 等),我們" "可以使用一些特定的操作來改變它,所有參照它的變數都會看到變化。" -#: ../../faq/programming.rst:500 +#: ../../faq/programming.rst:501 #, fuzzy msgid "" -"If we have an immutable object (:class:`str`, :class:`int`, :class:`tuple`, " -"etc.), all the variables that refer to it will always see the same value, " +"If we have an immutable object (such as :class:`str`, :class:`int`, :class:" +"`tuple`), all the variables that refer to it will always see the same value, " "but operations that transform that value into a new value always return a " "new object." msgstr "" @@ -999,7 +1004,7 @@ msgstr "" "有參照它的變數將始終看到相同的值,但是轉換的操作將該值轉化為新值總是回傳一個" "新物件。" -#: ../../faq/programming.rst:505 +#: ../../faq/programming.rst:506 msgid "" "If you want to know if two variables refer to the same object or not, you " "can use the :keyword:`is` operator, or the built-in function :func:`id`." @@ -1007,26 +1012,27 @@ msgstr "" "如果你想知道兩個變數是否參照同一個物件,你可以使用 :keyword:`is` 運算子或內建" "函式 :func:`id`。" -#: ../../faq/programming.rst:510 +#: ../../faq/programming.rst:511 msgid "How do I write a function with output parameters (call by reference)?" msgstr "如何編寫帶有輸出參數的函式(透過傳參照呼叫 (call by reference))?" -#: ../../faq/programming.rst:512 +#: ../../faq/programming.rst:513 +#, fuzzy msgid "" "Remember that arguments are passed by assignment in Python. Since " "assignment just creates references to objects, there's no alias between an " -"argument name in the caller and callee, and so no call-by-reference per se. " -"You can achieve the desired effect in a number of ways." +"argument name in the caller and callee, and consequently no call-by-" +"reference. You can achieve the desired effect in a number of ways." msgstr "" "請記住,在 Python 中引數是透過賦值傳遞的。由於賦值只是建立對物件的參照,因此" "呼叫者和被呼叫者的引數名稱之間沒有別名,因此本身沒有傳參照呼叫。你可以透過多" "種方式實作所需的效果。" -#: ../../faq/programming.rst:517 +#: ../../faq/programming.rst:518 msgid "By returning a tuple of the results::" msgstr "透過回傳結果的元組: ::" -#: ../../faq/programming.rst:519 +#: ../../faq/programming.rst:520 msgid "" ">>> def func1(a, b):\n" "... a = 'new-value' # a and b are local names\n" @@ -1046,20 +1052,20 @@ msgstr "" ">>> func1(x, y)\n" "('new-value', 100)" -#: ../../faq/programming.rst:528 +#: ../../faq/programming.rst:529 msgid "This is almost always the clearest solution." msgstr "這幾乎都會是最清楚的方案。" -#: ../../faq/programming.rst:530 +#: ../../faq/programming.rst:531 msgid "" "By using global variables. This isn't thread-safe, and is not recommended." msgstr "透過使用全域變數。這不是執行緒安全的,所以不推薦。" -#: ../../faq/programming.rst:532 +#: ../../faq/programming.rst:533 msgid "By passing a mutable (changeable in-place) object::" msgstr "透過傳遞一個可變的(可於原地 (in-place) 改變的)物件: ::" -#: ../../faq/programming.rst:534 +#: ../../faq/programming.rst:535 msgid "" ">>> def func2(a):\n" "... a[0] = 'new-value' # 'a' references a mutable list\n" @@ -1079,11 +1085,11 @@ msgstr "" ">>> args\n" "['new-value', 100]" -#: ../../faq/programming.rst:543 +#: ../../faq/programming.rst:544 msgid "By passing in a dictionary that gets mutated::" msgstr "透過傳入一個發生改變的字典: ::" -#: ../../faq/programming.rst:545 +#: ../../faq/programming.rst:546 msgid "" ">>> def func3(args):\n" "... args['a'] = 'new-value' # args is a mutable dictionary\n" @@ -1103,11 +1109,11 @@ msgstr "" ">>> args\n" "{'a': 'new-value', 'b': 100}" -#: ../../faq/programming.rst:554 +#: ../../faq/programming.rst:555 msgid "Or bundle up values in a class instance::" msgstr "或者在類別實例中捆綁值: ::" -#: ../../faq/programming.rst:556 +#: ../../faq/programming.rst:557 msgid "" ">>> class Namespace:\n" "... def __init__(self, /, **args):\n" @@ -1137,19 +1143,19 @@ msgstr "" ">>> vars(args)\n" "{'a': 'new-value', 'b': 100}" -#: ../../faq/programming.rst:571 +#: ../../faq/programming.rst:572 msgid "There's almost never a good reason to get this complicated." msgstr "幾乎不會有要讓事情變得如此複雜的充分理由。" -#: ../../faq/programming.rst:573 +#: ../../faq/programming.rst:574 msgid "Your best choice is to return a tuple containing the multiple results." msgstr "你最好的選擇是回傳一個包含多個結果的元組。" -#: ../../faq/programming.rst:577 +#: ../../faq/programming.rst:578 msgid "How do you make a higher order function in Python?" msgstr "你如何在 Python 中建立高階函式?" -#: ../../faq/programming.rst:579 +#: ../../faq/programming.rst:580 msgid "" "You have two choices: you can use nested scopes or you can use callable " "objects. For example, suppose you wanted to define ``linear(a,b)`` which " @@ -1160,7 +1166,7 @@ msgstr "" "``linear(a,b)``,它會回傳 ``a*x+b`` 計算值的函式 ``f(x)``。使用巢狀作用" "域: ::" -#: ../../faq/programming.rst:583 +#: ../../faq/programming.rst:584 msgid "" "def linear(a, b):\n" " def result(x):\n" @@ -1172,11 +1178,11 @@ msgstr "" " return a * x + b\n" " return result" -#: ../../faq/programming.rst:588 +#: ../../faq/programming.rst:589 msgid "Or using a callable object::" msgstr "或者使用可呼叫物件: ::" -#: ../../faq/programming.rst:590 +#: ../../faq/programming.rst:591 msgid "" "class linear:\n" "\n" @@ -1194,19 +1200,19 @@ msgstr "" " def __call__(self, x):\n" " return self.a * x + self.b" -#: ../../faq/programming.rst:598 +#: ../../faq/programming.rst:599 msgid "In both cases, ::" msgstr "在這兩種情況下: ::" -#: ../../faq/programming.rst:600 +#: ../../faq/programming.rst:601 msgid "taxes = linear(0.3, 2)" msgstr "taxes = linear(0.3, 2)" -#: ../../faq/programming.rst:602 +#: ../../faq/programming.rst:603 msgid "gives a callable object where ``taxes(10e6) == 0.3 * 10e6 + 2``." msgstr "給定一個可呼叫物件,其中 ``taxes(10e6) == 0.3 * 10e6 + 2``。" -#: ../../faq/programming.rst:604 +#: ../../faq/programming.rst:605 #, fuzzy msgid "" "The callable object approach has the disadvantage that it is a bit slower " @@ -1216,7 +1222,7 @@ msgstr "" "可呼叫物件方法的缺點是它有點慢並且導致程式碼稍長。但是,請注意,可呼叫集合可" "以透過繼承共享它們的簽名: ::" -#: ../../faq/programming.rst:608 +#: ../../faq/programming.rst:609 msgid "" "class exponential(linear):\n" " # __init__ inherited\n" @@ -1228,11 +1234,11 @@ msgstr "" " def __call__(self, x):\n" " return self.a * (x ** self.b)" -#: ../../faq/programming.rst:613 +#: ../../faq/programming.rst:614 msgid "Object can encapsulate state for several methods::" msgstr "物件可以封裝多個方法的狀態: ::" -#: ../../faq/programming.rst:615 +#: ../../faq/programming.rst:616 msgid "" "class counter:\n" "\n" @@ -1266,18 +1272,18 @@ msgstr "" "count = counter()\n" "inc, dec, reset = count.up, count.down, count.set" -#: ../../faq/programming.rst:631 +#: ../../faq/programming.rst:632 msgid "" "Here ``inc()``, ``dec()`` and ``reset()`` act like functions which share the " "same counting variable." msgstr "" "這裡的 ``inc()``、``dec()`` 和 ``reset()`` 就像共享相同計數變數的函式一樣。" -#: ../../faq/programming.rst:636 +#: ../../faq/programming.rst:637 msgid "How do I copy an object in Python?" msgstr "如何在 Python 中複製物件?" -#: ../../faq/programming.rst:638 +#: ../../faq/programming.rst:639 #, fuzzy msgid "" "In general, try :func:`copy.copy` or :func:`copy.deepcopy` for the general " @@ -1286,30 +1292,30 @@ msgstr "" "一般來說,對於一般情況,請嘗試 :func:`copy.copy` 或 :func:`copy.deepcopy`。並" "非所有物件都可以複製,但大多數都可以。" -#: ../../faq/programming.rst:641 +#: ../../faq/programming.rst:642 #, fuzzy msgid "" "Some objects can be copied more easily. Dictionaries have a :meth:`~dict." "copy` method::" msgstr "可以更輕鬆地複製某些物件。字典有一個 :meth:`~dict.copy` 方法: ::" -#: ../../faq/programming.rst:644 +#: ../../faq/programming.rst:645 msgid "newdict = olddict.copy()" msgstr "newdict = olddict.copy()" -#: ../../faq/programming.rst:646 +#: ../../faq/programming.rst:647 msgid "Sequences can be copied by slicing::" msgstr "序列可以透過切片 (slicing) 複製: ::" -#: ../../faq/programming.rst:648 +#: ../../faq/programming.rst:649 msgid "new_l = l[:]" msgstr "new_l = l[:]" -#: ../../faq/programming.rst:652 +#: ../../faq/programming.rst:653 msgid "How can I find the methods or attributes of an object?" msgstr "如何找到物件的方法或屬性?" -#: ../../faq/programming.rst:654 +#: ../../faq/programming.rst:655 #, fuzzy msgid "" "For an instance ``x`` of a user-defined class, :func:`dir(x) ` returns " @@ -1319,11 +1325,11 @@ msgstr "" "對於使用者定義類別的實例 ``x``,:func:`dir(x) ` 回傳一個按字母順序排列的" "名稱list,其中包含其類別定義的實例屬性、方法和屬性。" -#: ../../faq/programming.rst:660 +#: ../../faq/programming.rst:661 msgid "How can my code discover the name of an object?" msgstr "我的程式碼如何發現物件的名稱?" -#: ../../faq/programming.rst:662 +#: ../../faq/programming.rst:663 #, fuzzy msgid "" "Generally speaking, it can't, because objects don't really have names. " @@ -1335,7 +1341,7 @@ msgstr "" "``def`` 和 ``class`` 陳述式也是如此,但在那種情況下,值是可呼叫的。考慮以下程" "式碼: ::" -#: ../../faq/programming.rst:667 +#: ../../faq/programming.rst:668 msgid "" ">>> class A:\n" "... pass\n" @@ -1359,7 +1365,7 @@ msgstr "" ">>> print(a)\n" "<__main__.A object at 0x16D07CC>" -#: ../../faq/programming.rst:678 +#: ../../faq/programming.rst:679 #, fuzzy msgid "" "Arguably the class has a name: even though it is bound to two names and " @@ -1372,7 +1378,7 @@ msgstr "" "仍然被報告為類別 ``A`` 的實例。但是,無法確定實例的名稱是 ``a`` 還是 ``b`` ," "因為這兩個名稱都綁定到相同的值。" -#: ../../faq/programming.rst:683 +#: ../../faq/programming.rst:684 #, fuzzy msgid "" "Generally speaking it should not be necessary for your code to \"know the " @@ -1383,14 +1389,14 @@ msgstr "" "一般來說,你的程式碼不必「知道特定值的名稱」。除非你有意編寫內省程式,否則這" "通常表明改變方法可能是有益的。" -#: ../../faq/programming.rst:688 +#: ../../faq/programming.rst:689 msgid "" "In comp.lang.python, Fredrik Lundh once gave an excellent analogy in answer " "to this question:" msgstr "" "在 comp.lang.python 中,Fredrik Lundh 曾針對這個問題給出了一個極好的比喻:" -#: ../../faq/programming.rst:691 +#: ../../faq/programming.rst:692 msgid "" "The same way as you get the name of that cat you found on your porch: the " "cat (object) itself cannot tell you its name, and it doesn't really care -- " @@ -1401,22 +1407,22 @@ msgstr "" "不關心 - 所以找出它叫什麼的唯一方法是詢問所有鄰居(命名空間)是否是他們的貓" "(物件)..." -#: ../../faq/programming.rst:696 +#: ../../faq/programming.rst:697 msgid "" "....and don't be surprised if you'll find that it's known by many names, or " "no name at all!" msgstr "....如果你發現它有很多名字,或者根本沒有名字,請不要感到驚訝!" -#: ../../faq/programming.rst:701 +#: ../../faq/programming.rst:702 msgid "What's up with the comma operator's precedence?" msgstr "逗號運算子的優先級是什麼?" -#: ../../faq/programming.rst:703 +#: ../../faq/programming.rst:704 #, fuzzy msgid "Comma is not an operator in Python. Consider this session::" msgstr "逗號不是 Python 中的運算子。考慮這個會話: ::" -#: ../../faq/programming.rst:705 +#: ../../faq/programming.rst:706 msgid "" ">>> \"a\" in \"b\", \"a\"\n" "(False, 'a')" @@ -1424,7 +1430,7 @@ msgstr "" ">>> \"a\" in \"b\", \"a\"\n" "(False, 'a')" -#: ../../faq/programming.rst:708 +#: ../../faq/programming.rst:709 msgid "" "Since the comma is not an operator, but a separator between expressions the " "above is evaluated as if you had entered::" @@ -1432,37 +1438,37 @@ msgstr "" "由於逗號不是運算子,而是運算式之間的分隔符,因此上面的計算就會像你輸入的那" "樣: ::" -#: ../../faq/programming.rst:711 +#: ../../faq/programming.rst:712 msgid "(\"a\" in \"b\"), \"a\"" msgstr "(\"a\" in \"b\"), \"a\"" -#: ../../faq/programming.rst:713 +#: ../../faq/programming.rst:714 msgid "not::" msgstr "而不是: ::" -#: ../../faq/programming.rst:715 +#: ../../faq/programming.rst:716 msgid "\"a\" in (\"b\", \"a\")" msgstr "\"a\" in (\"b\", \"a\")" -#: ../../faq/programming.rst:717 +#: ../../faq/programming.rst:718 #, fuzzy msgid "" -"The same is true of the various assignment operators (``=``, ``+=`` etc). " -"They are not truly operators but syntactic delimiters in assignment " +"The same is true of the various assignment operators (``=``, ``+=``, and so " +"on). They are not truly operators but syntactic delimiters in assignment " "statements." msgstr "" "各種賦值運算子(``=``、``+=`` 等)也是如此。它們不是真正的運算子,而是賦值語" "句中的句法定界符。" -#: ../../faq/programming.rst:722 +#: ../../faq/programming.rst:723 msgid "Is there an equivalent of C's \"?:\" ternary operator?" msgstr "是否有等效於 C 的 \"?:\" 三元運算子?" -#: ../../faq/programming.rst:724 +#: ../../faq/programming.rst:725 msgid "Yes, there is. The syntax is as follows::" msgstr "有的,語法如下: ::" -#: ../../faq/programming.rst:726 +#: ../../faq/programming.rst:727 msgid "" "[on_true] if [expression] else [on_false]\n" "\n" @@ -1474,7 +1480,7 @@ msgstr "" "x, y = 50, 25\n" "small = x if x < y else y" -#: ../../faq/programming.rst:731 +#: ../../faq/programming.rst:732 #, fuzzy msgid "" "Before this syntax was introduced in Python 2.5, a common idiom was to use " @@ -1482,11 +1488,11 @@ msgid "" msgstr "" "在 Python 2.5 中引入此語法之前,一個常見的習慣用法是使用邏輯運算子: ::" -#: ../../faq/programming.rst:734 +#: ../../faq/programming.rst:735 msgid "[expression] and [on_true] or [on_false]" msgstr "[expression] and [on_true] or [on_false]" -#: ../../faq/programming.rst:736 +#: ../../faq/programming.rst:737 #, fuzzy msgid "" "However, this idiom is unsafe, as it can give wrong results when *on_true* " @@ -1496,12 +1502,12 @@ msgstr "" "然而,這個慣用語是不安全的,因為當 *on_true* 有一個錯誤的布林值時它會給出錯誤" "的結果。因此,最好使用 ``... if ... else ...`` 形式。" -#: ../../faq/programming.rst:742 +#: ../../faq/programming.rst:743 #, fuzzy msgid "Is it possible to write obfuscated one-liners in Python?" msgstr "是否可以在 Python 中編寫混淆的單行程式碼?" -#: ../../faq/programming.rst:744 +#: ../../faq/programming.rst:745 #, fuzzy msgid "" "Yes. Usually this is done by nesting :keyword:`lambda` within :keyword:`!" @@ -1511,7 +1517,7 @@ msgstr "" "是的。通常這是透過在 :keyword:`!lambda` 中嵌套 :keyword:`lambda` 來完成的。請" "參閱以下三個範例,稍微改編自 Ulf Bartelt: ::" -#: ../../faq/programming.rst:747 +#: ../../faq/programming.rst:748 msgid "" "from functools import reduce\n" "\n" @@ -1539,15 +1545,15 @@ msgid "" "# |____________________________ range on x axis" msgstr "" -#: ../../faq/programming.rst:771 +#: ../../faq/programming.rst:772 msgid "Don't try this at home, kids!" msgstr "孩子們,不要在家裡嘗試這個!" -#: ../../faq/programming.rst:777 +#: ../../faq/programming.rst:778 msgid "What does the slash(/) in the parameter list of a function mean?" msgstr "函式參數串列中的斜線 (/) 是什麼意思?" -#: ../../faq/programming.rst:779 +#: ../../faq/programming.rst:780 #, fuzzy msgid "" "A slash in the argument list of a function denotes that the parameters prior " @@ -1561,7 +1567,7 @@ msgstr "" "的參數。在呼叫接受僅位置參數的函式時,參數僅根據其位置對映到參數。例如,:" "func:`divmod` 是一個只接受位置參數的函式。它的文件看起來像這樣: ::" -#: ../../faq/programming.rst:786 +#: ../../faq/programming.rst:787 msgid "" ">>> help(divmod)\n" "Help on built-in function divmod in module builtins:\n" @@ -1575,7 +1581,7 @@ msgstr "" "divmod(x, y, /)\n" " Return the tuple (x//y, x%y). Invariant: div*y + mod == x." -#: ../../faq/programming.rst:792 +#: ../../faq/programming.rst:793 msgid "" "The slash at the end of the parameter list means that both parameters are " "positional-only. Thus, calling :func:`divmod` with keyword arguments would " @@ -1584,7 +1590,7 @@ msgstr "" "參數串列最後的斜線表示兩個參數都是僅限位置參數。因此使用關鍵字引數呼叫 :func:" "`divmod` 會導致錯誤: ::" -#: ../../faq/programming.rst:796 +#: ../../faq/programming.rst:797 msgid "" ">>> divmod(x=3, y=4)\n" "Traceback (most recent call last):\n" @@ -1596,15 +1602,15 @@ msgstr "" " File \"\", line 1, in \n" "TypeError: divmod() takes no keyword arguments" -#: ../../faq/programming.rst:803 +#: ../../faq/programming.rst:804 msgid "Numbers and strings" msgstr "數字和字串" -#: ../../faq/programming.rst:806 +#: ../../faq/programming.rst:807 msgid "How do I specify hexadecimal and octal integers?" msgstr "如何指定十六進位和八進位整數?" -#: ../../faq/programming.rst:808 +#: ../../faq/programming.rst:809 #, fuzzy msgid "" "To specify an octal digit, precede the octal value with a zero, and then a " @@ -1614,7 +1620,7 @@ msgstr "" "要指定八進位數字,請在八進位值前面加上零,然後是小寫或大寫的 \"o\" 。例如,要" "將變數 \"a\" 設定為八進位值 \"10\" (十進位為 8),請鍵入: ::" -#: ../../faq/programming.rst:812 +#: ../../faq/programming.rst:813 msgid "" ">>> a = 0o10\n" ">>> a\n" @@ -1624,7 +1630,7 @@ msgstr "" ">>> a\n" "8" -#: ../../faq/programming.rst:816 +#: ../../faq/programming.rst:817 #, fuzzy msgid "" "Hexadecimal is just as easy. Simply precede the hexadecimal number with a " @@ -1634,7 +1640,7 @@ msgstr "" "十六進位也很容易。只需在十六進位數前面加上一個零,然後是一個小寫或大寫的 " "\"x\" 。可以用小寫或大寫形式指定十六進位數字。例如,在 Python 直譯器中: ::" -#: ../../faq/programming.rst:820 +#: ../../faq/programming.rst:821 msgid "" ">>> a = 0xa5\n" ">>> a\n" @@ -1650,11 +1656,11 @@ msgstr "" ">>> b\n" "178" -#: ../../faq/programming.rst:829 +#: ../../faq/programming.rst:830 msgid "Why does -22 // 10 return -3?" msgstr "為什麼 -22 // 10 回傳 -3?" -#: ../../faq/programming.rst:831 +#: ../../faq/programming.rst:832 #, fuzzy msgid "" "It's primarily driven by the desire that ``i % j`` have the same sign as " @@ -1663,11 +1669,11 @@ msgstr "" "它主要是由希望 ``i % j`` 與 ``j`` 具有相同的符號驅動的。如果你想要那個,也想" "要: ::" -#: ../../faq/programming.rst:834 +#: ../../faq/programming.rst:835 msgid "i == (i // j) * j + (i % j)" msgstr "i == (i // j) * j + (i % j)" -#: ../../faq/programming.rst:836 +#: ../../faq/programming.rst:837 msgid "" "then integer division has to return the floor. C also requires that " "identity to hold, and then compilers that truncate ``i // j`` need to make " @@ -1676,7 +1682,7 @@ msgstr "" "那麼整數除法必須回傳向下取整的結果。 C 還要求保留​​該識別性,然後截斷 ``i // " "j`` 的編譯器需要使 ``i % j`` 具有與 ``i`` 相同的符號。" -#: ../../faq/programming.rst:840 +#: ../../faq/programming.rst:841 #, fuzzy msgid "" "There are few real use cases for ``i % j`` when ``j`` is negative. When " @@ -1690,12 +1696,12 @@ msgstr "" "什麼? ``-190 % 12 == 2`` 很有用; ``-190 % 12 == -10`` 是一個等著咬人的錯" "誤。" -#: ../../faq/programming.rst:848 +#: ../../faq/programming.rst:849 #, fuzzy msgid "How do I get int literal attribute instead of SyntaxError?" msgstr "如何取得 int 文字屬性而不是 SyntaxError?" -#: ../../faq/programming.rst:850 +#: ../../faq/programming.rst:851 msgid "" "Trying to lookup an ``int`` literal attribute in the normal manner gives a :" "exc:`SyntaxError` because the period is seen as a decimal point::" @@ -1703,7 +1709,7 @@ msgstr "" "嘗試以正常方式查找 ``int`` 字面值屬性會給出一個 :exc:`SyntaxError`,因為句點" "被視為小數點: ::" -#: ../../faq/programming.rst:853 +#: ../../faq/programming.rst:854 msgid "" ">>> 1.__class__\n" " File \"\", line 1\n" @@ -1717,27 +1723,27 @@ msgstr "" " ^\n" "SyntaxError: invalid decimal literal" -#: ../../faq/programming.rst:859 +#: ../../faq/programming.rst:860 msgid "" "The solution is to separate the literal from the period with either a space " "or parentheses." msgstr "解決方式是用空格或圓括號將字面值與句點分開。" -#: ../../faq/programming.rst:869 +#: ../../faq/programming.rst:870 msgid "How do I convert a string to a number?" msgstr "如何將字串轉換為數字?" -#: ../../faq/programming.rst:871 +#: ../../faq/programming.rst:872 #, fuzzy msgid "" -"For integers, use the built-in :func:`int` type constructor, e.g. " +"For integers, use the built-in :func:`int` type constructor, for example, " "``int('144') == 144``. Similarly, :func:`float` converts to a floating-" -"point number, e.g. ``float('144') == 144.0``." +"point number, for example, ``float('144') == 144.0``." msgstr "" "對於整數,使用內建的 int 型別建構函式,例如``int('144') == 144``。同樣,:" "func:`float` 轉換為浮點數,例如``浮動('144')== 144.0``。" -#: ../../faq/programming.rst:875 +#: ../../faq/programming.rst:876 #, fuzzy msgid "" "By default, these interpret the number as decimal, so that ``int('0144') == " @@ -1753,7 +1759,7 @@ msgstr "" "使用 Python 的規則解釋該數字:前導 \"0o\" 表示八進位, \"0x\" 表示十六進位" "數。" -#: ../../faq/programming.rst:882 +#: ../../faq/programming.rst:883 #, fuzzy msgid "" "Do not use the built-in function :func:`eval` if all you need is to convert " @@ -1768,29 +1774,29 @@ msgstr "" "Python 運算式。例如,有人可以透過 ``__import__('os').system(\"rm -rf " "$HOME\")`` 來清除你的主目錄。" -#: ../../faq/programming.rst:889 +#: ../../faq/programming.rst:890 #, fuzzy msgid "" ":func:`eval` also has the effect of interpreting numbers as Python " -"expressions, so that e.g. ``eval('09')`` gives a syntax error because Python " -"does not allow leading '0' in a decimal number (except '0')." +"expressions, so that, for example, ``eval('09')`` gives a syntax error " +"because Python does not allow leading '0' in a decimal number (except '0')." msgstr "" ":func:`eval` 還具有將數字解釋為 Python 運算式的效果,例如``eval('09')`` 會給" "出語法錯誤,因為 Python 不允許在十進位數中前導 '0'('0' 除外)。" -#: ../../faq/programming.rst:895 +#: ../../faq/programming.rst:896 msgid "How do I convert a number to a string?" msgstr "如何將數字轉換為字串?" -#: ../../faq/programming.rst:897 +#: ../../faq/programming.rst:898 #, fuzzy msgid "" -"To convert, e.g., the number ``144`` to the string ``'144'``, use the built-" -"in type constructor :func:`str`. If you want a hexadecimal or octal " +"For example, to convert the number ``144`` to the string ``'144'``, use the " +"built-in type constructor :func:`str`. If you want a hexadecimal or octal " "representation, use the built-in functions :func:`hex` or :func:`oct`. For " "fancy formatting, see the :ref:`f-strings` and :ref:`formatstrings` " -"sections, e.g. ``\"{:04d}\".format(144)`` yields ``'0144'`` and ``\"{:.3f}\"." -"format(1.0/3.0)`` yields ``'0.333'``." +"sections. For example, ``\"{:04d}\".format(144)`` yields ``'0144'`` and " +"``\"{:.3f}\".format(1.0/3.0)`` yields ``'0.333'``." msgstr "" "例如,要將數字 ``144`` 轉換為字串 ``'144'``,請使用內建型別建構函式 :func:" "`str`。如果你想要十六進製或八進製表示,請使用內建函式 :func:`hex` 或 :func:" @@ -1798,23 +1804,24 @@ msgstr "" "如``\"{:04d}\".format(144)`` 產生 ``'0144'`` 和 ``\"{:.3f}\"." "format(1.0/3.0)`` 產生 ``'0.333'`` ." -#: ../../faq/programming.rst:906 +#: ../../faq/programming.rst:907 msgid "How do I modify a string in place?" msgstr "如何原地修改字串?" -#: ../../faq/programming.rst:908 +#: ../../faq/programming.rst:909 +#, fuzzy msgid "" "You can't, because strings are immutable. In most situations, you should " "simply construct a new string from the various parts you want to assemble it " "from. However, if you need an object with the ability to modify in-place " -"unicode data, try using an :class:`io.StringIO` object or the :mod:`array` " +"Unicode data, try using an :class:`io.StringIO` object or the :mod:`array` " "module::" msgstr "" "這沒辦法做到,因為字串是不可變的。在大多數情況下,你應以要拿來組裝的各個部分" "建構出一個新字串。但是如果你需要一個能夠原地修改 unicode 資料的物件,請嘗試使" "用 :class:`io.StringIO` 物件或 :mod:`array` 模組: ::" -#: ../../faq/programming.rst:914 +#: ../../faq/programming.rst:915 msgid "" ">>> import io\n" ">>> s = \"Hello, world\"\n" @@ -1860,15 +1867,15 @@ msgstr "" ">>> a.tounicode()\n" "'yello, world'" -#: ../../faq/programming.rst:938 +#: ../../faq/programming.rst:939 msgid "How do I use strings to call functions/methods?" msgstr "如何使用字串呼叫函式/方法?" -#: ../../faq/programming.rst:940 +#: ../../faq/programming.rst:941 msgid "There are various techniques." msgstr "有各式各樣的技法。" -#: ../../faq/programming.rst:942 +#: ../../faq/programming.rst:943 #, fuzzy msgid "" "The best is to use a dictionary that maps strings to functions. The primary " @@ -1879,7 +1886,7 @@ msgstr "" "最好的方法是使用將字串對映到函式的字典。這種技術的主要優點是字串不需要與函式" "名稱相匹配。這也是用於模擬案例建構的主要技術: ::" -#: ../../faq/programming.rst:947 +#: ../../faq/programming.rst:948 msgid "" "def a():\n" " pass\n" @@ -1892,11 +1899,11 @@ msgid "" "dispatch[get_input()]() # Note trailing parens to call function" msgstr "" -#: ../../faq/programming.rst:957 +#: ../../faq/programming.rst:958 msgid "Use the built-in function :func:`getattr`::" msgstr "使用內建函式 :func:`getattr`: ::" -#: ../../faq/programming.rst:959 +#: ../../faq/programming.rst:960 msgid "" "import foo\n" "getattr(foo, 'bar')()" @@ -1904,17 +1911,17 @@ msgstr "" "import foo\n" "getattr(foo, 'bar')()" -#: ../../faq/programming.rst:962 +#: ../../faq/programming.rst:963 msgid "" "Note that :func:`getattr` works on any object, including classes, class " "instances, modules, and so on." msgstr "請注意 :func:`getattr` 適用於任何物件,包括類別、類別實例、模組等。" -#: ../../faq/programming.rst:965 +#: ../../faq/programming.rst:966 msgid "This is used in several places in the standard library, like this::" msgstr "這在標準函式庫中的幾個地方被使用,如: ::" -#: ../../faq/programming.rst:967 +#: ../../faq/programming.rst:968 msgid "" "class Foo:\n" " def do_foo(self):\n" @@ -1936,11 +1943,11 @@ msgstr "" "f = getattr(foo_instance, 'do_' + opname)\n" "f()" -#: ../../faq/programming.rst:978 +#: ../../faq/programming.rst:979 msgid "Use :func:`locals` to resolve the function name::" msgstr "使用 :func:`locals` 解析函式名稱: ::" -#: ../../faq/programming.rst:980 +#: ../../faq/programming.rst:981 msgid "" "def myFunc():\n" " print(\"hello\")\n" @@ -1958,7 +1965,7 @@ msgstr "" "f = locals()[fname]\n" "f()" -#: ../../faq/programming.rst:990 +#: ../../faq/programming.rst:991 #, fuzzy msgid "" "Is there an equivalent to Perl's ``chomp()`` for removing trailing newlines " @@ -1966,7 +1973,7 @@ msgid "" msgstr "" "是否有與 Perl 的 chomp() 等效的方法,能用於從字串中刪除後綴的換行符號?" -#: ../../faq/programming.rst:992 +#: ../../faq/programming.rst:993 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 " @@ -1975,7 +1982,7 @@ msgid "" "removed::" msgstr "" -#: ../../faq/programming.rst:998 +#: ../../faq/programming.rst:999 msgid "" ">>> lines = (\"line 1 \\r\\n\"\n" "... \"\\r\\n\"\n" @@ -1989,7 +1996,7 @@ msgstr "" ">>> lines.rstrip(\"\\n\\r\")\n" "'line 1 '" -#: ../../faq/programming.rst:1004 +#: ../../faq/programming.rst:1005 #, fuzzy msgid "" "Since this is typically only desired when reading text one line at a time, " @@ -1998,17 +2005,17 @@ msgstr "" "由於這通常只在一次讀取一行文本時才需要,因此使用 ``S.rstrip()`` 這種方式效果" "很好。" -#: ../../faq/programming.rst:1009 +#: ../../faq/programming.rst:1010 #, fuzzy msgid "Is there a ``scanf()`` or ``sscanf()`` equivalent?" msgstr "是否有 scanf() 或 sscanf() 的等效方法?" -#: ../../faq/programming.rst:1011 +#: ../../faq/programming.rst:1012 #, fuzzy msgid "Not as such." msgstr "不是這樣的。" -#: ../../faq/programming.rst:1013 +#: ../../faq/programming.rst:1014 #, fuzzy msgid "" "For simple input parsing, the easiest approach is usually to split the line " @@ -2023,7 +2030,7 @@ msgstr "" "func:`浮動`。 :meth:`!split` 支援可選的 \"sep\" 參數,如果該行使用空格以外的" "其他內容作為分隔符,該參數很有用。" -#: ../../faq/programming.rst:1019 +#: ../../faq/programming.rst:1020 #, fuzzy msgid "" "For more complicated input parsing, regular expressions are more powerful " @@ -2031,28 +2038,28 @@ msgid "" msgstr "" "對於更複雜的輸入解析,正則運算式比 C 的 ``sscanf`` 更強大,更適合這項任務。" -#: ../../faq/programming.rst:1024 +#: ../../faq/programming.rst:1025 #, fuzzy msgid "What does ``UnicodeDecodeError`` or ``UnicodeEncodeError`` error mean?" msgstr "'UnicodeDecodeError' 或 'UnicodeEncodeErro' 錯誤是什麼意思?" -#: ../../faq/programming.rst:1026 +#: ../../faq/programming.rst:1027 msgid "See the :ref:`unicode-howto`." msgstr "請參閱 :ref:`unicode-howto`。" -#: ../../faq/programming.rst:1032 +#: ../../faq/programming.rst:1033 #, fuzzy msgid "Can I end a raw string with an odd number of backslashes?" msgstr "我可以用奇數個反斜線結束原始字串嗎?" -#: ../../faq/programming.rst:1034 +#: ../../faq/programming.rst:1035 #, fuzzy msgid "" "A raw string ending with an odd number of backslashes will escape the " "string's quote::" msgstr "以奇數個反斜線結尾的原始字串將跳脫字串的引號: ::" -#: ../../faq/programming.rst:1036 +#: ../../faq/programming.rst:1037 msgid "" ">>> r'C:\\this\\will\\not\\work\\'\n" " File \"\", line 1\n" @@ -2066,14 +2073,14 @@ msgstr "" " ^\n" "SyntaxError: unterminated string literal (detected at line 1)" -#: ../../faq/programming.rst:1042 +#: ../../faq/programming.rst:1043 #, fuzzy msgid "" "There are several workarounds for this. One is to use regular strings and " "double the backslashes::" msgstr "有幾種解決方法。一種是使用常規字串並加倍反斜線: ::" -#: ../../faq/programming.rst:1045 +#: ../../faq/programming.rst:1046 msgid "" ">>> 'C:\\\\this\\\\will\\\\work\\\\'\n" "'C:\\\\this\\\\will\\\\work\\\\'" @@ -2081,14 +2088,14 @@ msgstr "" ">>> 'C:\\\\this\\\\will\\\\work\\\\'\n" "'C:\\\\this\\\\will\\\\work\\\\'" -#: ../../faq/programming.rst:1048 +#: ../../faq/programming.rst:1049 #, fuzzy msgid "" "Another is to concatenate a regular string containing an escaped backslash " "to the raw string::" msgstr "另一種方法是將包含跳脫反斜線的常規字串連接到原始字串: ::" -#: ../../faq/programming.rst:1051 +#: ../../faq/programming.rst:1052 msgid "" ">>> r'C:\\this\\will\\work' '\\\\'\n" "'C:\\\\this\\\\will\\\\work\\\\'" @@ -2096,14 +2103,14 @@ msgstr "" ">>> r'C:\\this\\will\\work' '\\\\'\n" "'C:\\\\this\\\\will\\\\work\\\\'" -#: ../../faq/programming.rst:1054 +#: ../../faq/programming.rst:1055 #, fuzzy msgid "" "It is also possible to use :func:`os.path.join` to append a backslash on " "Windows::" msgstr "也可以使用 :func:`os.path.join` 在 Windows 上附加反斜線: ::" -#: ../../faq/programming.rst:1056 +#: ../../faq/programming.rst:1057 msgid "" ">>> os.path.join(r'C:\\this\\will\\work', '')\n" "'C:\\\\this\\\\will\\\\work\\\\'" @@ -2111,7 +2118,7 @@ msgstr "" ">>> os.path.join(r'C:\\this\\will\\work', '')\n" "'C:\\\\this\\\\will\\\\work\\\\'" -#: ../../faq/programming.rst:1059 +#: ../../faq/programming.rst:1060 #, fuzzy msgid "" "Note that while a backslash will \"escape\" a quote for the purposes of " @@ -2122,7 +2129,7 @@ msgstr "" "請注意,雖然為了確定原始字串的結束位置而使用反斜線「跳脫」引號,但在解釋原始" "字串的值時不會發生跳脫。也就是說,反斜線仍然存在於原始字串的值中: ::" -#: ../../faq/programming.rst:1064 +#: ../../faq/programming.rst:1065 msgid "" ">>> r'backslash\\'preserved'\n" "\"backslash\\\\'preserved\"" @@ -2130,42 +2137,42 @@ msgstr "" ">>> r'backslash\\'preserved'\n" "\"backslash\\\\'preserved\"" -#: ../../faq/programming.rst:1067 +#: ../../faq/programming.rst:1068 #, fuzzy msgid "Also see the specification in the :ref:`language reference `." msgstr "另請參閱 :ref:`語言參考 ` 中的規範。" -#: ../../faq/programming.rst:1070 +#: ../../faq/programming.rst:1072 msgid "Performance" msgstr "效能" -#: ../../faq/programming.rst:1073 +#: ../../faq/programming.rst:1075 msgid "My program is too slow. How do I speed it up?" msgstr "我的程式太慢了。我該如何加快速度?" -#: ../../faq/programming.rst:1075 +#: ../../faq/programming.rst:1077 #, fuzzy msgid "" -"That's a tough one, in general. First, here are a list of things to " -"remember before diving further:" +"That's a tough one, in general. First, here is a list of things to remember " +"before diving further:" msgstr "" "總的來說,這是一個艱難的過程。首先,這裡列出了在進一步潛水之前要記住的事項:" -#: ../../faq/programming.rst:1078 +#: ../../faq/programming.rst:1080 #, fuzzy msgid "" "Performance characteristics vary across Python implementations. This FAQ " "focuses on :term:`CPython`." msgstr "性能特徵因 Python 實作而異。此 FAQ 重點關注 :term:`CPython`。" -#: ../../faq/programming.rst:1080 +#: ../../faq/programming.rst:1082 #, fuzzy msgid "" "Behaviour can vary across operating systems, especially when talking about I/" "O or multi-threading." msgstr "行為可能因作業系統而異,尤其是在談論 I/O 或多執行緒時。" -#: ../../faq/programming.rst:1082 +#: ../../faq/programming.rst:1084 #, fuzzy msgid "" "You should always find the hot spots in your program *before* attempting to " @@ -2174,7 +2181,7 @@ msgstr "" "在嘗試最佳化任何程式碼\\ *之前*,你應該始終找到程式中的熱點(請參閱 :mod:" "`profile` 模組)。" -#: ../../faq/programming.rst:1084 +#: ../../faq/programming.rst:1086 #, fuzzy msgid "" "Writing benchmark scripts will allow you to iterate quickly when searching " @@ -2182,7 +2189,7 @@ msgid "" msgstr "" "編寫基準測試腳本將允許你在搜尋改進時快速疊代(請參閱 :mod:`timeit` 模組)。" -#: ../../faq/programming.rst:1086 +#: ../../faq/programming.rst:1088 #, fuzzy msgid "" "It is highly recommended to have good code coverage (through unit testing or " @@ -2192,7 +2199,7 @@ msgstr "" "強烈建議在可能引入隱藏在復雜最佳化中的回歸之前擁有良好的程式碼覆蓋率(透過單" "元測試或任何其他技術)。" -#: ../../faq/programming.rst:1090 +#: ../../faq/programming.rst:1092 #, fuzzy msgid "" "That being said, there are many tricks to speed up Python code. Here are " @@ -2202,7 +2209,7 @@ msgstr "" "也就是說,有很多技巧可以加速 Python 程式碼。以下是一些對達到可接受的性能水平" "大有幫助的一般原則:" -#: ../../faq/programming.rst:1094 +#: ../../faq/programming.rst:1096 #, fuzzy msgid "" "Making your algorithms faster (or changing to faster ones) can yield much " @@ -2212,7 +2219,7 @@ msgstr "" "讓你的演算法更快(或更改為更快的演算法)可以產生比嘗試在你的程式碼中散佈微最" "佳化技巧大得多的好處。" -#: ../../faq/programming.rst:1098 +#: ../../faq/programming.rst:1100 #, fuzzy msgid "" "Use the right data structures. Study documentation for the :ref:`bltin-" @@ -2221,7 +2228,7 @@ msgstr "" "使用正確的資料結構。研究 :ref:`bltin-types` 和 :mod:`collections` 模組的文" "件。" -#: ../../faq/programming.rst:1101 +#: ../../faq/programming.rst:1103 #, fuzzy msgid "" "When the standard library provides a primitive for doing something, it is " @@ -2237,7 +2244,7 @@ msgstr "" "更是如此。例如,請務必使用 :meth:`list.sort` 內建方法或相關的 :func:`sorted` " "函式進行排序(有關高階用法的範例,請參閱 :ref:`sortinghowto` )." -#: ../../faq/programming.rst:1109 +#: ../../faq/programming.rst:1111 #, fuzzy msgid "" "Abstractions tend to create indirections and force the interpreter to work " @@ -2250,7 +2257,7 @@ msgstr "" "量,你的程式就會變慢。你應該避免過度抽象,尤其是在微小的函式或方法的形式下" "(這通常也不利於可讀性)。" -#: ../../faq/programming.rst:1115 +#: ../../faq/programming.rst:1117 #, fuzzy msgid "" "If you have reached the limit of what pure Python can allow, there are tools " @@ -2268,7 +2275,7 @@ msgstr "" "你的程式碼比解釋時快得多。如果你對自己的 C 程式設計技能有信心,你也可以\\ :" "ref:`自己編寫一個 C 擴充模組 `。" -#: ../../faq/programming.rst:1125 +#: ../../faq/programming.rst:1127 msgid "" "The wiki page devoted to `performance tips `_." @@ -2276,12 +2283,12 @@ msgstr "" "有個 wiki 頁面專門介紹\\ `效能改進小提示 `_。" -#: ../../faq/programming.rst:1131 +#: ../../faq/programming.rst:1134 #, fuzzy msgid "What is the most efficient way to concatenate many strings together?" msgstr "將多個字串連接在一起的最有效方法是什麼?" -#: ../../faq/programming.rst:1133 +#: ../../faq/programming.rst:1136 #, fuzzy msgid "" ":class:`str` and :class:`bytes` objects are immutable, therefore " @@ -2293,7 +2300,7 @@ msgstr "" "下,因為每次連接都會建立一個新物件。在一般情況下,總執行環境 (runtime) 成本是" "總字串長度的二次方。" -#: ../../faq/programming.rst:1138 +#: ../../faq/programming.rst:1141 #, fuzzy msgid "" "To accumulate many :class:`str` objects, the recommended idiom is to place " @@ -2302,7 +2309,7 @@ msgstr "" "要累積許多 :class:`str` 物件,推薦的習慣用法是將它們放入list中並在末尾呼叫 :" "meth:`str.join`: ::" -#: ../../faq/programming.rst:1141 +#: ../../faq/programming.rst:1144 msgid "" "chunks = []\n" "for s in my_strings:\n" @@ -2314,12 +2321,12 @@ msgstr "" " chunks.append(s)\n" "result = ''.join(chunks)" -#: ../../faq/programming.rst:1146 +#: ../../faq/programming.rst:1149 #, fuzzy -msgid "(another reasonably efficient idiom is to use :class:`io.StringIO`)" +msgid "(Another reasonably efficient idiom is to use :class:`io.StringIO`.)" msgstr "(另一個相當有效的習慣用法是使用 :class:`io.StringIO`)" -#: ../../faq/programming.rst:1148 +#: ../../faq/programming.rst:1151 #, fuzzy msgid "" "To accumulate many :class:`bytes` objects, the recommended idiom is to " @@ -2329,7 +2336,7 @@ msgstr "" "要累積許多 :class:`bytes` 物件,推薦的習慣用法是使用原地連接(``+=`` 運算子)" "擴充一個 :class:`bytearray` 物件: ::" -#: ../../faq/programming.rst:1151 +#: ../../faq/programming.rst:1154 msgid "" "result = bytearray()\n" "for b in my_bytes_objects:\n" @@ -2339,15 +2346,16 @@ msgstr "" "for b in my_bytes_objects:\n" " result += b" -#: ../../faq/programming.rst:1157 -msgid "Sequences (Tuples/Lists)" +#: ../../faq/programming.rst:1160 +#, fuzzy +msgid "Sequences (tuples/lists)" msgstr "序列(元組/串列)" -#: ../../faq/programming.rst:1160 +#: ../../faq/programming.rst:1163 msgid "How do I convert between tuples and lists?" msgstr "如何在元組和串列之間進行轉換?" -#: ../../faq/programming.rst:1162 +#: ../../faq/programming.rst:1165 msgid "" "The type constructor ``tuple(seq)`` converts any sequence (actually, any " "iterable) into a tuple with the same items in the same order." @@ -2355,7 +2363,7 @@ msgstr "" "型別建構函式 ``tuple(seq)`` 將任何序列(實際上是任何可疊代物件)轉換為具有相" "同順序的相同項的元組。" -#: ../../faq/programming.rst:1165 +#: ../../faq/programming.rst:1168 #, fuzzy msgid "" "For example, ``tuple([1, 2, 3])`` yields ``(1, 2, 3)`` and ``tuple('abc')`` " @@ -2367,7 +2375,7 @@ msgstr "" "``('a', 'b ', 'c')``。如果引數是一個元組,它不會復製而是回傳同一個物件,所以" "當你不確定一個物件是否已經是一個元組時呼叫 :func:`tuple` 是便宜的。" -#: ../../faq/programming.rst:1170 +#: ../../faq/programming.rst:1173 #, fuzzy msgid "" "The type constructor ``list(seq)`` converts any sequence or iterable into a " @@ -2380,11 +2388,11 @@ msgstr "" "``['a', 'b ', 'c']``。如果引數是一個list,它會像 ``seq[:]`` 那樣製作一個副" "本。" -#: ../../faq/programming.rst:1177 +#: ../../faq/programming.rst:1180 msgid "What's a negative index?" msgstr "什麼是負索引?" -#: ../../faq/programming.rst:1179 +#: ../../faq/programming.rst:1182 #, fuzzy msgid "" "Python sequences are indexed with positive numbers and negative numbers. " @@ -2397,7 +2405,7 @@ msgstr "" "依此類推。對於負索引,-1 是最後一個索引,-2 是倒數第二個(倒數第二個)索引," "依此類推。將 ``seq[-n]`` 視為與 ``seq[len(seq)-n]`` 相同。" -#: ../../faq/programming.rst:1184 +#: ../../faq/programming.rst:1187 #, fuzzy msgid "" "Using negative indices can be very convenient. For example ``S[:-1]`` is " @@ -2407,42 +2415,42 @@ msgstr "" "使用負索引會非常方便。例如 ``S[:-1]`` 是除最後一個字元之外的所有字串,這對於" "從字串中刪除尾隨換行符很有用。" -#: ../../faq/programming.rst:1190 +#: ../../faq/programming.rst:1193 #, fuzzy msgid "How do I iterate over a sequence in reverse order?" msgstr "如何以相反的順序疊代序列?" -#: ../../faq/programming.rst:1192 +#: ../../faq/programming.rst:1195 #, fuzzy msgid "Use the :func:`reversed` built-in function::" msgstr "使用 :func:`reversed` 內建函式: ::" -#: ../../faq/programming.rst:1194 +#: ../../faq/programming.rst:1197 msgid "" "for x in reversed(sequence):\n" " ... # do something with x ..." msgstr "" -#: ../../faq/programming.rst:1197 +#: ../../faq/programming.rst:1200 #, fuzzy msgid "" "This won't touch your original sequence, but build a new copy with reversed " "order to iterate over." msgstr "這不會觸及你的原始序列,但會構建一個具有相反順序的新副本以進行疊代。" -#: ../../faq/programming.rst:1202 +#: ../../faq/programming.rst:1205 msgid "How do you remove duplicates from a list?" msgstr "如何從串列中刪除重複項?" -#: ../../faq/programming.rst:1204 +#: ../../faq/programming.rst:1207 msgid "See the Python Cookbook for a long discussion of many ways to do this:" msgstr "請參閱 Python Cookbook 以得到有關執行此操作的各種方法的詳細討論:" -#: ../../faq/programming.rst:1206 +#: ../../faq/programming.rst:1209 msgid "https://code.activestate.com/recipes/52560/" msgstr "https://code.activestate.com/recipes/52560/" -#: ../../faq/programming.rst:1208 +#: ../../faq/programming.rst:1211 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::" @@ -2450,7 +2458,7 @@ msgstr "" "如果你不介意重新排序串列,可以對其進行排序,然後從串列末尾開始掃描,同時刪除" "重複項: ::" -#: ../../faq/programming.rst:1211 +#: ../../faq/programming.rst:1214 msgid "" "if mylist:\n" " mylist.sort()\n" @@ -2470,30 +2478,31 @@ msgstr "" " else:\n" " last = mylist[i]" -#: ../../faq/programming.rst:1220 +#: ../../faq/programming.rst:1223 +#, fuzzy msgid "" -"If all elements of the list may be used as set keys (i.e. they are all :term:" -"`hashable`) this is often faster ::" +"If all elements of the list may be used as set keys (that is, they are all :" +"term:`hashable`) this is often faster::" msgstr "" "如果串列的所有元素都可以做為集合的鍵(即它們都必須是 :term:`hashable`),那這" "通常會更快: ::" -#: ../../faq/programming.rst:1223 +#: ../../faq/programming.rst:1226 msgid "mylist = list(set(mylist))" msgstr "mylist = list(set(mylist))" -#: ../../faq/programming.rst:1225 +#: ../../faq/programming.rst:1228 msgid "" "This converts the list into a set, thereby removing duplicates, and then " "back into a list." msgstr "這會將串列轉換為一個集合,從而刪除重複項,然後再轉換回串列。" -#: ../../faq/programming.rst:1230 +#: ../../faq/programming.rst:1233 #, fuzzy msgid "How do you remove multiple items from a list?" msgstr "如何從串列中刪除多個項目" -#: ../../faq/programming.rst:1232 +#: ../../faq/programming.rst:1235 #, fuzzy msgid "" "As with removing duplicates, explicitly iterating in reverse with a delete " @@ -2504,33 +2513,33 @@ msgstr "" "與刪除重複項一樣,使用刪除條件顯式反向疊代是一種可能性。但是,透過隱式或顯式" "前向疊代使用切片替換更容易和更快。這是三種變體: ::" -#: ../../faq/programming.rst:1237 +#: ../../faq/programming.rst:1240 msgid "" "mylist[:] = filter(keep_function, mylist)\n" "mylist[:] = (x for x in mylist if keep_condition)\n" "mylist[:] = [x for x in mylist if keep_condition]" msgstr "" -#: ../../faq/programming.rst:1241 +#: ../../faq/programming.rst:1244 #, fuzzy msgid "The list comprehension may be fastest." msgstr "list理解可能是最快的。" -#: ../../faq/programming.rst:1245 +#: ../../faq/programming.rst:1248 #, fuzzy msgid "How do you make an array in Python?" msgstr "你如何在 Python 中建立數組?" -#: ../../faq/programming.rst:1247 +#: ../../faq/programming.rst:1250 #, fuzzy msgid "Use a list::" msgstr "使用 list: ::" -#: ../../faq/programming.rst:1249 +#: ../../faq/programming.rst:1252 msgid "[\"this\", 1, \"is\", \"an\", \"array\"]" msgstr "" -#: ../../faq/programming.rst:1251 +#: ../../faq/programming.rst:1254 #, fuzzy msgid "" "Lists are equivalent to C or Pascal arrays in their time complexity; the " @@ -2540,29 +2549,29 @@ msgstr "" "list在時間複雜度上等同於 C 或 Pascal 數組;主要區別在於 Python list可以包含許" "多不同型別的物件。" -#: ../../faq/programming.rst:1254 +#: ../../faq/programming.rst:1257 #, fuzzy msgid "" "The ``array`` module also provides methods for creating arrays of fixed " "types with compact representations, but they are slower to index than " -"lists. Also note that `NumPy `_ and other third party " +"lists. Also note that `NumPy `_ and other third-party " "packages define array-like structures with various characteristics as well." msgstr "" "``array`` 模組還提供了建立具有緊湊表示的固定型別數組的方法,但它們的索引速度" "比list慢。另請注意,`NumPy `_ 和其他第三方包也定義了具有" "各種特徵的類似數組的結構。" -#: ../../faq/programming.rst:1260 +#: ../../faq/programming.rst:1263 #, fuzzy msgid "" "To get Lisp-style linked lists, you can emulate *cons cells* using tuples::" msgstr "要獲得 Lisp 風格的鍊錶,你可以使用元組模擬 *cons cells*: ::" -#: ../../faq/programming.rst:1262 +#: ../../faq/programming.rst:1265 msgid "lisp_list = (\"like\", (\"this\", (\"example\", None) ) )" msgstr "" -#: ../../faq/programming.rst:1264 +#: ../../faq/programming.rst:1267 #, fuzzy msgid "" "If mutability is desired, you could use lists instead of tuples. Here the " @@ -2574,23 +2583,23 @@ msgstr "" "``lisp_list[0]`` 而 *cdr* 的類比是 ``lisp_list[1]``。只有在確定確實需要時才這" "樣做,因為它通常比使用 Python list慢很多。" -#: ../../faq/programming.rst:1273 +#: ../../faq/programming.rst:1276 msgid "How do I create a multidimensional list?" msgstr "如何建立多維度串列?" -#: ../../faq/programming.rst:1275 +#: ../../faq/programming.rst:1278 msgid "You probably tried to make a multidimensional array like this::" msgstr "你可能會這樣建立一個多維度陣列: ::" -#: ../../faq/programming.rst:1277 +#: ../../faq/programming.rst:1280 msgid ">>> A = [[None] * 2] * 3" msgstr ">>> A = [[None] * 2] * 3" -#: ../../faq/programming.rst:1279 +#: ../../faq/programming.rst:1282 msgid "This looks correct if you print it:" msgstr "如果你印出它,這看起來是正確的:" -#: ../../faq/programming.rst:1285 +#: ../../faq/programming.rst:1288 msgid "" ">>> A\n" "[[None, None], [None, None], [None, None]]" @@ -2598,11 +2607,11 @@ msgstr "" ">>> A\n" "[[None, None], [None, None], [None, None]]" -#: ../../faq/programming.rst:1290 +#: ../../faq/programming.rst:1293 msgid "But when you assign a value, it shows up in multiple places:" msgstr "但是當你賦予一個值時,它會出現在多個地方:" -#: ../../faq/programming.rst:1296 +#: ../../faq/programming.rst:1299 msgid "" ">>> A[0][0] = 5\n" ">>> A\n" @@ -2612,7 +2621,7 @@ msgstr "" ">>> A\n" "[[5, None], [5, None], [5, None]]" -#: ../../faq/programming.rst:1302 +#: ../../faq/programming.rst:1305 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 " @@ -2623,13 +2632,13 @@ msgstr "" "建立一個串列,其中包含 3 個對長度為 2 的相同串列的參照。對其中一列的變更也將" "顯示在所有其他列中,而這幾乎不會是你想要的。" -#: ../../faq/programming.rst:1307 +#: ../../faq/programming.rst:1310 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:1310 +#: ../../faq/programming.rst:1313 msgid "" "A = [None] * 3\n" "for i in range(3):\n" @@ -2639,7 +2648,7 @@ msgstr "" "for i in range(3):\n" " A[i] = [None] * 2" -#: ../../faq/programming.rst:1314 +#: ../../faq/programming.rst:1317 msgid "" "This generates a list containing 3 different lists of length two. You can " "also use a list comprehension::" @@ -2647,7 +2656,7 @@ msgstr "" "這會產生一個包含 3 個長度為 2 的不同串列的串列。你也可以使用串列綜合運算" "式: ::" -#: ../../faq/programming.rst:1317 +#: ../../faq/programming.rst:1320 msgid "" "w, h = 2, 3\n" "A = [[None] * w for i in range(h)]" @@ -2655,7 +2664,7 @@ msgstr "" "w, h = 2, 3\n" "A = [[None] * w for i in range(h)]" -#: ../../faq/programming.rst:1320 +#: ../../faq/programming.rst:1323 msgid "" "Or, you can use an extension that provides a matrix datatype; `NumPy " "`_ is the best known." @@ -2663,20 +2672,20 @@ msgstr "" "或者你也可以使用提供矩陣資料型別的擴充套件;`NumPy `_ 是" "其中最著名的一個。" -#: ../../faq/programming.rst:1325 +#: ../../faq/programming.rst:1328 msgid "How do I apply a method or function to a sequence of objects?" msgstr "如何將方法或函式應用於物件序列?" -#: ../../faq/programming.rst:1327 +#: ../../faq/programming.rst:1330 #, fuzzy msgid "" -"To call a method or function and accumulate the return values is a list, a :" +"To call a method or function and accumulate the return values in a list, a :" "term:`list comprehension` is an elegant solution::" msgstr "" "呼叫一個方法或函式並累積回傳值是一個list,一個 :term:`list comprehension` 是" "一個優雅的解決方案: ::" -#: ../../faq/programming.rst:1330 +#: ../../faq/programming.rst:1333 msgid "" "result = [obj.method() for obj in mylist]\n" "\n" @@ -2686,14 +2695,14 @@ msgstr "" "\n" "result = [function(obj) for obj in mylist]" -#: ../../faq/programming.rst:1334 +#: ../../faq/programming.rst:1337 #, fuzzy msgid "" "To just run the method or function without saving the return values, a " "plain :keyword:`for` loop will suffice::" msgstr "要只運行方法或函式而不保存回傳值,一個普通的 for 迴圈就足夠了: ::" -#: ../../faq/programming.rst:1337 +#: ../../faq/programming.rst:1340 msgid "" "for obj in mylist:\n" " obj.method()\n" @@ -2707,12 +2716,12 @@ msgstr "" "for obj in mylist:\n" " function(obj)" -#: ../../faq/programming.rst:1346 +#: ../../faq/programming.rst:1350 msgid "" "Why does a_tuple[i] += ['item'] raise an exception when the addition works?" msgstr "為什麼 a_tuple[i] += ['item'] 做加法時會引發例外?" -#: ../../faq/programming.rst:1348 +#: ../../faq/programming.rst:1352 #, fuzzy msgid "" "This is because of a combination of the fact that augmented assignment " @@ -2722,7 +2731,7 @@ msgstr "" "這是因為增強賦值運算子是 *assignment* 運算子這一事實,以及 Python 中可變物件" "和不可變物件之間的區別。" -#: ../../faq/programming.rst:1352 +#: ../../faq/programming.rst:1356 #, fuzzy msgid "" "This discussion applies in general when augmented assignment operators are " @@ -2732,11 +2741,11 @@ msgstr "" "當擴充賦值運算子應用於指向可變物件的元組元素時,此討論通常適用,但我們將使用 " "``list`` 和 ``+=\" 作為範例。" -#: ../../faq/programming.rst:1356 +#: ../../faq/programming.rst:1360 msgid "If you wrote::" msgstr "如果你寫了: ::" -#: ../../faq/programming.rst:1358 +#: ../../faq/programming.rst:1362 msgid "" ">>> a_tuple = (1, 2)\n" ">>> a_tuple[0] += 1\n" @@ -2750,7 +2759,7 @@ msgstr "" " ...\n" "TypeError: 'tuple' object does not support item assignment" -#: ../../faq/programming.rst:1364 +#: ../../faq/programming.rst:1368 #, fuzzy msgid "" "The reason for the exception should be immediately clear: ``1`` is added to " @@ -2763,13 +2772,13 @@ msgstr "" "果物件,``2``,但是當我們嘗試將計算結果 ``2`` 分配給元組的元素 ``0`` 時,我們" "會得到一個錯誤,因為我們無法更改元組的元素指向的內容。" -#: ../../faq/programming.rst:1370 +#: ../../faq/programming.rst:1374 msgid "" "Under the covers, what this augmented assignment statement is doing is " "approximately this::" msgstr "這個增強賦值陳述式在背後大致是做這些事情: ::" -#: ../../faq/programming.rst:1373 +#: ../../faq/programming.rst:1377 msgid "" ">>> result = a_tuple[0] + 1\n" ">>> a_tuple[0] = result\n" @@ -2783,18 +2792,18 @@ msgstr "" " ...\n" "TypeError: 'tuple' object does not support item assignment" -#: ../../faq/programming.rst:1379 +#: ../../faq/programming.rst:1383 #, fuzzy msgid "" "It is the assignment part of the operation that produces the error, since a " "tuple is immutable." msgstr "產生錯誤的是操作的賦值部分,因為元組是不可變的。" -#: ../../faq/programming.rst:1382 +#: ../../faq/programming.rst:1386 msgid "When you write something like::" msgstr "當你寫這樣的東西時: ::" -#: ../../faq/programming.rst:1384 +#: ../../faq/programming.rst:1388 msgid "" ">>> a_tuple = (['foo'], 'bar')\n" ">>> a_tuple[0] += ['item']\n" @@ -2808,14 +2817,14 @@ msgstr "" " ...\n" "TypeError: 'tuple' object does not support item assignment" -#: ../../faq/programming.rst:1390 +#: ../../faq/programming.rst:1394 #, fuzzy 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:1393 +#: ../../faq/programming.rst:1397 msgid "" ">>> a_tuple[0]\n" "['foo', 'item']" @@ -2823,7 +2832,7 @@ msgstr "" ">>> a_tuple[0]\n" "['foo', 'item']" -#: ../../faq/programming.rst:1396 +#: ../../faq/programming.rst:1400 #, fuzzy msgid "" "To see why this happens, you need to know that (a) if an object implements " @@ -2840,7 +2849,7 @@ msgstr "" "呼叫 :meth:`!extend` 並回傳list。這就是為什麼我們說對於list,``+=`` 是 :meth:" "`!list.extend` 的「簡寫」: ::" -#: ../../faq/programming.rst:1404 +#: ../../faq/programming.rst:1408 msgid "" ">>> a_list = []\n" ">>> a_list += [1]\n" @@ -2852,11 +2861,11 @@ msgstr "" ">>> a_list\n" "[1]" -#: ../../faq/programming.rst:1409 +#: ../../faq/programming.rst:1413 msgid "This is equivalent to::" msgstr "這等價於: ::" -#: ../../faq/programming.rst:1411 +#: ../../faq/programming.rst:1415 msgid "" ">>> result = a_list.__iadd__([1])\n" ">>> a_list = result" @@ -2864,7 +2873,7 @@ msgstr "" ">>> result = a_list.__iadd__([1])\n" ">>> a_list = result" -#: ../../faq/programming.rst:1414 +#: ../../faq/programming.rst:1418 #, fuzzy msgid "" "The object pointed to by a_list has been mutated, and the pointer to the " @@ -2876,11 +2885,11 @@ msgstr "" "最終結果是空操作,因為它是一個指向與 ``a_list`` 先前指向的同一物件的指標,但" "賦值仍然發生。" -#: ../../faq/programming.rst:1419 +#: ../../faq/programming.rst:1423 msgid "Thus, in our tuple example what is happening is equivalent to::" msgstr "因此,在我們的元組範例中,發生的事情等同於: ::" -#: ../../faq/programming.rst:1421 +#: ../../faq/programming.rst:1425 msgid "" ">>> result = a_tuple[0].__iadd__(['item'])\n" ">>> a_tuple[0] = result\n" @@ -2894,7 +2903,7 @@ msgstr "" " ...\n" "TypeError: 'tuple' object does not support item assignment" -#: ../../faq/programming.rst:1427 +#: ../../faq/programming.rst:1431 #, fuzzy msgid "" "The :meth:`!__iadd__` succeeds, and thus the list is extended, but even " @@ -2906,13 +2915,13 @@ msgstr "" "``a_tuple[0]`` 已經指向的同一個物件,最終的賦值仍然導致一個錯誤,因為元組是不" "可變的。" -#: ../../faq/programming.rst:1433 +#: ../../faq/programming.rst:1437 msgid "" "I want to do a complicated sort: can you do a Schwartzian Transform in " "Python?" msgstr "我想做一個複雜的排序:你能用 Python 做一個 Schwartzian 變換嗎?" -#: ../../faq/programming.rst:1435 +#: ../../faq/programming.rst:1439 #, fuzzy msgid "" "The technique, attributed to Randal Schwartz of the Perl community, sorts " @@ -2924,7 +2933,7 @@ msgstr "" "的度量對串列的元素進行排序。在 Python 中,對 :meth:`list.sort` 方法使用 " "``key`` 引數: ::" -#: ../../faq/programming.rst:1439 +#: ../../faq/programming.rst:1443 msgid "" "Isorted = L[:]\n" "Isorted.sort(key=lambda s: int(s[10:15]))" @@ -2932,51 +2941,28 @@ msgstr "" "Isorted = L[:]\n" "Isorted.sort(key=lambda s: int(s[10:15]))" -#: ../../faq/programming.rst:1444 +#: ../../faq/programming.rst:1448 msgid "How can I sort one list by values from another list?" msgstr "如何根據另一個串列中的值對一個串列進行排序?" -#: ../../faq/programming.rst:1446 +#: ../../faq/programming.rst:1450 +#, fuzzy msgid "" "Merge them into an iterator of tuples, sort the resulting list, and then " -"pick out the element you want. ::" +"pick out the element you want." msgstr "" "將它們合併到一個元組疊代器中,對結果的串列進行排序,然後挑選出你想要的元" "素。 ::" -#: ../../faq/programming.rst:1449 -msgid "" -">>> list1 = [\"what\", \"I'm\", \"sorting\", \"by\"]\n" -">>> list2 = [\"something\", \"else\", \"to\", \"sort\"]\n" -">>> pairs = zip(list1, list2)\n" -">>> pairs = sorted(pairs)\n" -">>> pairs\n" -"[(\"I'm\", 'else'), ('by', 'sort'), ('sorting', 'to'), ('what', " -"'something')]\n" -">>> result = [x[1] for x in pairs]\n" -">>> result\n" -"['else', 'sort', 'to', 'something']" -msgstr "" -">>> list1 = [\"what\", \"I'm\", \"sorting\", \"by\"]\n" -">>> list2 = [\"something\", \"else\", \"to\", \"sort\"]\n" -">>> pairs = zip(list1, list2)\n" -">>> pairs = sorted(pairs)\n" -">>> pairs\n" -"[(\"I'm\", 'else'), ('by', 'sort'), ('sorting', 'to'), ('what', " -"'something')]\n" -">>> result = [x[1] for x in pairs]\n" -">>> result\n" -"['else', 'sort', 'to', 'something']" - -#: ../../faq/programming.rst:1461 +#: ../../faq/programming.rst:1465 msgid "Objects" msgstr "物件" -#: ../../faq/programming.rst:1464 +#: ../../faq/programming.rst:1468 msgid "What is a class?" msgstr "什麼是類別 (class)?" -#: ../../faq/programming.rst:1466 +#: ../../faq/programming.rst:1470 #, fuzzy msgid "" "A class is the particular object type created by executing a class " @@ -2987,7 +2973,7 @@ msgstr "" "類別是透過執行類別陳述式建立的特定物件型別。類別物件用作建立實例物件的模板," "實例物件包含特定於資料型別的資料(屬性)和程式碼(方法)。" -#: ../../faq/programming.rst:1470 +#: ../../faq/programming.rst:1474 #, fuzzy msgid "" "A class can be based on one or more other classes, called its base " @@ -3002,11 +2988,11 @@ msgstr "" "類別,它為郵箱提供基本的存取器方法,以及處理各種特定郵箱格式的子類別,例如 " "``MboxMailbox`` 、 ``MaildirMailbox`` 、 ``OutlookMailbox`` 。" -#: ../../faq/programming.rst:1479 +#: ../../faq/programming.rst:1483 msgid "What is a method?" msgstr "什麼是方法 (method)?" -#: ../../faq/programming.rst:1481 +#: ../../faq/programming.rst:1485 #, fuzzy msgid "" "A method is a function on some object ``x`` that you normally call as ``x." @@ -3016,7 +3002,7 @@ msgstr "" "方法是一些物件 ``x`` 上的函式,你通常將其稱為 ``x.name(arguments...)`` 。方法" "在類別定義中被定義為函式: ::" -#: ../../faq/programming.rst:1485 +#: ../../faq/programming.rst:1489 msgid "" "class C:\n" " def meth(self, arg):\n" @@ -3026,11 +3012,11 @@ msgstr "" " def meth(self, arg):\n" " return arg * 2 + self.attribute" -#: ../../faq/programming.rst:1491 +#: ../../faq/programming.rst:1495 msgid "What is self?" msgstr "什麼是 self?" -#: ../../faq/programming.rst:1493 +#: ../../faq/programming.rst:1497 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, " @@ -3041,25 +3027,25 @@ msgstr "" "為 ``meth(self, a, b, c)`` 的方法應該以 ``x.meth(a, b, c)`` 形式來呼叫;被呼" "叫的方法會認為它是以 ``meth(x, a, b, c)`` 來呼叫的。" -#: ../../faq/programming.rst:1498 +#: ../../faq/programming.rst:1502 msgid "See also :ref:`why-self`." msgstr "另請參閱 :ref:`why-self`。" -#: ../../faq/programming.rst:1502 +#: ../../faq/programming.rst:1506 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:1504 +#: ../../faq/programming.rst:1508 #, fuzzy 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 " -"providing a tuple instead of a single class, e.g. ``isinstance(obj, (class1, " -"class2, ...))``, and can also check whether an object is one of Python's " -"built-in types, e.g. ``isinstance(obj, str)`` or ``isinstance(obj, (int, " -"float, complex))``." +"providing a tuple instead of a single class, for example, ``isinstance(obj, " +"(class1, class2, ...))``, and can also check whether an object is one of " +"Python's built-in types, for example, ``isinstance(obj, str)`` or " +"``isinstance(obj, (int, float, complex))``." msgstr "" "使用內建函式 :func:`isinstance(obj, cls) `。你可以透過提供元組而" "不是單個類別來檢查物件是否是多個類別中的任何一個的實例,例如" @@ -3067,19 +3053,21 @@ msgstr "" "置型別之一,例如``isinstance(obj, str)`` 或 ``isinstance(obj, (int, float, " "complex))``。" -#: ../../faq/programming.rst:1511 +#: ../../faq/programming.rst:1515 +#, fuzzy msgid "" "Note that :func:`isinstance` also checks for virtual inheritance from an :" "term:`abstract base class`. So, the test will return ``True`` for a " "registered class even if hasn't directly or indirectly inherited from it. " -"To test for \"true inheritance\", scan the :term:`MRO` of the class:" +"To test for \"true inheritance\", scan the :term:`method resolution order` " +"(MRO) of the class:" msgstr "" "請注意,:func:`isinstance` 還會檢查來自\\ :term:`抽象基底類別 (abstract base " "class) ` 的虛擬繼承。因此對已註冊類別的檢驗會回傳 " "``True``,即使沒有直接或間接繼承自它。要測試「真正繼承」,請掃描該類別的 :" "term:`MRO`:" -#: ../../faq/programming.rst:1516 +#: ../../faq/programming.rst:1521 msgid "" "from collections.abc import Mapping\n" "\n" @@ -3101,7 +3089,7 @@ msgstr "" "\n" "Mapping.register(P)" -#: ../../faq/programming.rst:1528 +#: ../../faq/programming.rst:1533 msgid "" ">>> c = C()\n" ">>> isinstance(c, C) # direct\n" @@ -3135,7 +3123,7 @@ msgstr "" ">>> Mapping in type(c).__mro__\n" "False" -#: ../../faq/programming.rst:1546 +#: ../../faq/programming.rst:1551 #, fuzzy msgid "" "Note that most programs do not use :func:`isinstance` on user-defined " @@ -3149,7 +3137,7 @@ msgstr "" "自己開發類別,更合適的面向物件風格是在封裝特定行為的類別上定義方法,而不是檢" "查物件的類別並根據它是什麼類別做不同的事情。例如,如果你有一個函式做某事: ::" -#: ../../faq/programming.rst:1553 +#: ../../faq/programming.rst:1558 msgid "" "def search(obj):\n" " if isinstance(obj, Mailbox):\n" @@ -3165,13 +3153,13 @@ msgstr "" " ... # 搜尋文件的程式碼\n" " elif ..." -#: ../../faq/programming.rst:1560 +#: ../../faq/programming.rst:1565 msgid "" "A better approach is to define a ``search()`` method on all the classes and " "just call it::" msgstr "更好的方法是在所有類別上定義一個 ``search()`` 方法然後呼叫它: ::" -#: ../../faq/programming.rst:1563 +#: ../../faq/programming.rst:1568 msgid "" "class Mailbox:\n" " def search(self):\n" @@ -3193,13 +3181,14 @@ msgstr "" "\n" "obj.search()" -#: ../../faq/programming.rst:1575 +#: ../../faq/programming.rst:1580 msgid "What is delegation?" msgstr "什麼是委派 (delegation)?" -#: ../../faq/programming.rst:1577 +#: ../../faq/programming.rst:1582 +#, fuzzy msgid "" -"Delegation is an object oriented technique (also called a design pattern). " +"Delegation is an object-oriented technique (also called a design pattern). " "Let's say you have an object ``x`` and want to change the behaviour of just " "one of its methods. You can create a new class that provides a new " "implementation of the method you're interested in changing and delegates all " @@ -3209,7 +3198,7 @@ msgstr "" "改其中一個方法的行為。你可以建立一個新類別,它提供你想改變的那個方法的新實" "作,並將所有其他方法委派給 ``x`` 的相應方法。" -#: ../../faq/programming.rst:1583 +#: ../../faq/programming.rst:1588 msgid "" "Python programmers can easily implement delegation. For example, the " "following class implements a class that behaves like a file but converts all " @@ -3218,7 +3207,7 @@ msgstr "" "Python 程式設計師可以輕鬆地實作委派。舉例來說,以下類別實作了一個行為類似檔案" "的類別,但將所有寫入的資料轉換為大寫:" -#: ../../faq/programming.rst:1587 +#: ../../faq/programming.rst:1592 msgid "" "class UpperOut:\n" "\n" @@ -3242,7 +3231,7 @@ msgstr "" " def __getattr__(self, name):\n" " return getattr(self._outfile, name)" -#: ../../faq/programming.rst:1598 +#: ../../faq/programming.rst:1603 #, fuzzy msgid "" "Here the ``UpperOut`` class redefines the ``write()`` method to convert the " @@ -3257,7 +3246,7 @@ msgstr "" "``self._outfile`` 物件。委託是透過 :meth:`~object.__getattr__` 方法完成的;有" "關控制屬性存取的更多資訊,請參閱語言參考 。" -#: ../../faq/programming.rst:1605 +#: ../../faq/programming.rst:1610 #, fuzzy msgid "" "Note that for more general cases delegation can get trickier. When " @@ -3270,7 +3259,7 @@ msgstr "" "類別也必須定義一個 :meth:`~object.__setattr__` 方法,而且必須小心謹慎。 :" "meth:`!__setattr__` 的基本實作大致等同於以下: ::" -#: ../../faq/programming.rst:1610 +#: ../../faq/programming.rst:1615 msgid "" "class X:\n" " ...\n" @@ -3284,7 +3273,7 @@ msgstr "" " self.__dict__[name] = value\n" " ..." -#: ../../faq/programming.rst:1616 +#: ../../faq/programming.rst:1621 msgid "" "Many :meth:`~object.__setattr__` implementations call :meth:`!object." "__setattr__` to set an attribute on self without causing infinite recursion::" @@ -3292,7 +3281,7 @@ msgstr "" "許多 :meth:`~object.__setattr__` 的實作會呼叫 :meth:`!object.__setattr__` 以" "設定 self 的屬性,而不會導致無限遞迴。" -#: ../../faq/programming.rst:1619 +#: ../../faq/programming.rst:1624 msgid "" "class X:\n" " def __setattr__(self, name, value):\n" @@ -3304,24 +3293,24 @@ msgstr "" " # 自訂邏輯放在這裡...\n" " object.__setattr__(self, name, value)" -#: ../../faq/programming.rst:1624 +#: ../../faq/programming.rst:1629 msgid "" "Alternatively, it is possible to set attributes by inserting entries into :" "attr:`self.__dict__ ` directly." msgstr "" -#: ../../faq/programming.rst:1629 +#: ../../faq/programming.rst:1634 #, fuzzy msgid "" "How do I call a method defined in a base class from a derived class that " "extends it?" msgstr "如何從擴充它的衍生類別呼叫基底類別中定義的方法?" -#: ../../faq/programming.rst:1631 +#: ../../faq/programming.rst:1636 msgid "Use the built-in :func:`super` function::" msgstr "使用內建的 :func:`super` 函式: ::" -#: ../../faq/programming.rst:1633 +#: ../../faq/programming.rst:1638 msgid "" "class Derived(Base):\n" " def meth(self):\n" @@ -3331,7 +3320,7 @@ msgstr "" " def meth(self):\n" " super().meth() # 呼叫 Base.meth" -#: ../../faq/programming.rst:1637 +#: ../../faq/programming.rst:1642 msgid "" "In the example, :func:`super` will automatically determine the instance from " "which it was called (the ``self`` value), look up the :term:`method " @@ -3339,23 +3328,23 @@ msgid "" "line after ``Derived`` in the MRO: ``Base``." msgstr "" -#: ../../faq/programming.rst:1644 +#: ../../faq/programming.rst:1649 msgid "How can I organize my code to make it easier to change the base class?" msgstr "我可以如何組織我的程式碼以使得更改基底類別變的更容易?" -#: ../../faq/programming.rst:1646 +#: ../../faq/programming.rst:1651 #, fuzzy 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, " -"this trick is also handy if you want to decide dynamically (e.g. depending " -"on availability of resources) which base class to use. Example::" +"this trick is also handy if you want to decide dynamically (such as " +"depending on availability of resources) which base class to use. Example::" msgstr "" "你可以將基底類別分配給別名並從別名衍生。然後,你只需更改分配給別名的值。順便" "說一句,如果你想動態決定(例如,取決於資源的可用性)使用哪個基底類別,這個技" "巧也很方便。例子: ::" -#: ../../faq/programming.rst:1651 +#: ../../faq/programming.rst:1656 msgid "" "class Base:\n" " ...\n" @@ -3373,17 +3362,17 @@ msgstr "" "class Derived(BaseAlias):\n" " ..." -#: ../../faq/programming.rst:1661 +#: ../../faq/programming.rst:1666 msgid "How do I create static class data and static class methods?" msgstr "如何建立靜態類別資料和靜態類別方法?" -#: ../../faq/programming.rst:1663 +#: ../../faq/programming.rst:1668 msgid "" "Both static data and static methods (in the sense of C++ or Java) are " "supported in Python." msgstr "Python 支援靜態資料和靜態方法(在 C++ 或 Java 的意義上)。" -#: ../../faq/programming.rst:1666 +#: ../../faq/programming.rst:1671 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::" @@ -3391,7 +3380,7 @@ msgstr "" "對於靜態資料,只需定義一個類別屬性即可。要為屬性分配新值,你必須在分配中顯式" "使用類別名稱: ::" -#: ../../faq/programming.rst:1669 +#: ../../faq/programming.rst:1674 msgid "" "class C:\n" " count = 0 # number of times C.__init__ called\n" @@ -3411,7 +3400,7 @@ msgstr "" " def getcount(self):\n" " return C.count # 或回傳 self.count" -#: ../../faq/programming.rst:1678 +#: ../../faq/programming.rst:1683 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 " @@ -3421,7 +3410,7 @@ msgstr "" "除非被 ``c`` 本身或某些人覆蓋從 ``c.__class__`` 回到 ``C`` 的基底類別搜尋路徑" "上的類別。" -#: ../../faq/programming.rst:1682 +#: ../../faq/programming.rst:1687 #, fuzzy msgid "" "Caution: within a method of C, an assignment like ``self.count = 42`` " @@ -3433,15 +3422,15 @@ msgstr "" "一個名為 \"count\" 的新的不相關實例。類別靜態資料名稱的重新綁定必須始終指定類" "別是否在方法內: ::" -#: ../../faq/programming.rst:1687 +#: ../../faq/programming.rst:1692 msgid "C.count = 314" msgstr "C.count = 314" -#: ../../faq/programming.rst:1689 +#: ../../faq/programming.rst:1694 msgid "Static methods are possible::" msgstr "靜態方法是可能的: ::" -#: ../../faq/programming.rst:1691 +#: ../../faq/programming.rst:1696 msgid "" "class C:\n" " @staticmethod\n" @@ -3455,7 +3444,7 @@ msgstr "" " # 沒有 'self' 參數!\n" " ..." -#: ../../faq/programming.rst:1697 +#: ../../faq/programming.rst:1702 #, fuzzy msgid "" "However, a far more straightforward way to get the effect of a static method " @@ -3463,7 +3452,7 @@ msgid "" msgstr "" "然而,獲得靜態方法效果的一種更直接的方法是透過一個簡單的模組級函式: ::" -#: ../../faq/programming.rst:1700 +#: ../../faq/programming.rst:1705 msgid "" "def getcount():\n" " return C.count" @@ -3471,7 +3460,7 @@ msgstr "" "def getcount():\n" " return C.count" -#: ../../faq/programming.rst:1703 +#: ../../faq/programming.rst:1708 #, fuzzy msgid "" "If your code is structured so as to define one class (or tightly related " @@ -3480,22 +3469,23 @@ msgstr "" "如果你的程式碼結構化以便為每個模組定義一個類別(或緊密相關的類別層次結構)," "則這提供了所需的封裝。" -#: ../../faq/programming.rst:1708 +#: ../../faq/programming.rst:1713 msgid "How can I overload constructors (or methods) in Python?" msgstr "如何在 Python 中多載 (overload) 建構函式(或方法)?" -#: ../../faq/programming.rst:1710 +#: ../../faq/programming.rst:1715 msgid "" "This answer actually applies to all methods, but the question usually comes " "up first in the context of constructors." msgstr "" "這個答案實際上適用於所有方法,但這個問題通常會先出現在建構函式的情境中。" -#: ../../faq/programming.rst:1713 -msgid "In C++ you'd write" +#: ../../faq/programming.rst:1718 +#, fuzzy +msgid "In C++ you'd write:" msgstr "在 C++ 中你會寫成" -#: ../../faq/programming.rst:1715 +#: ../../faq/programming.rst:1720 msgid "" "class C {\n" " C() { cout << \"No arguments\\n\"; }\n" @@ -3507,14 +3497,14 @@ msgstr "" " C(int i) { cout << \"Argument is \" << i << \"\\n\"; }\n" "}" -#: ../../faq/programming.rst:1722 +#: ../../faq/programming.rst:1727 msgid "" "In Python you have to write a single constructor that catches all cases " "using default arguments. For example::" msgstr "" "在 Python 中,你必須編寫一個建構函式來捕獲所有使用預設引數的情況。例如: ::" -#: ../../faq/programming.rst:1725 +#: ../../faq/programming.rst:1730 msgid "" "class C:\n" " def __init__(self, i=None):\n" @@ -3530,15 +3520,16 @@ msgstr "" " else:\n" " print(\"Argument is\", i)" -#: ../../faq/programming.rst:1732 +#: ../../faq/programming.rst:1737 msgid "This is not entirely equivalent, but close enough in practice." msgstr "這並不完全等價,但在實際情況中已夠接近。" -#: ../../faq/programming.rst:1734 -msgid "You could also try a variable-length argument list, e.g. ::" +#: ../../faq/programming.rst:1739 +#, fuzzy +msgid "You could also try a variable-length argument list, for example::" msgstr "你也可以嘗試長度可變的引數串列,例如: ::" -#: ../../faq/programming.rst:1736 +#: ../../faq/programming.rst:1741 msgid "" "def __init__(self, *args):\n" " ..." @@ -3546,15 +3537,15 @@ msgstr "" "def __init__(self, *args):\n" " ..." -#: ../../faq/programming.rst:1739 +#: ../../faq/programming.rst:1744 msgid "The same approach works for all method definitions." msgstr "相同的手段適用於所有方法的定義。" -#: ../../faq/programming.rst:1743 +#: ../../faq/programming.rst:1748 msgid "I try to use __spam and I get an error about _SomeClassName__spam." msgstr "我嘗試使用 __spam,但收到有關 _SomeClassName__spam 的錯誤。" -#: ../../faq/programming.rst:1745 +#: ../../faq/programming.rst:1750 msgid "" "Variable names with double leading underscores are \"mangled\" to provide a " "simple but effective way to define class private variables. Any identifier " @@ -3568,13 +3559,13 @@ msgstr "" "底線)在文字上會被替換為 ``_classname__spam``,其中 ``classname`` 是目前類別" "之所有前導底線被去除的名稱。" -#: ../../faq/programming.rst:1751 +#: ../../faq/programming.rst:1756 msgid "" "The identifier can be used unchanged within the class, but to access it " "outside the class, the mangled name must be used:" msgstr "" -#: ../../faq/programming.rst:1754 +#: ../../faq/programming.rst:1759 msgid "" "class A:\n" " def __one(self):\n" @@ -3600,7 +3591,7 @@ msgstr "" "\n" "four = 4 * A()._A__one()" -#: ../../faq/programming.rst:1768 +#: ../../faq/programming.rst:1773 #, fuzzy msgid "" "In particular, this does not guarantee privacy since an outside user can " @@ -3610,21 +3601,21 @@ msgstr "" "這並不能保證隱私:外部使用者仍然可以故意存取 \"_classname__spam\" 屬性,並且" "私有值在物件的 __dict__ 中可見。許多 Python 程式員根本懶得使用私有變數名。" -#: ../../faq/programming.rst:1774 +#: ../../faq/programming.rst:1779 msgid "" "The :ref:`private name mangling specifications ` for " "details and special cases." msgstr "" -#: ../../faq/programming.rst:1778 +#: ../../faq/programming.rst:1784 msgid "My class defines __del__ but it is not called when I delete the object." msgstr "我的類別定義了 __del__ 但是當我刪除物件時它沒有被呼叫。" -#: ../../faq/programming.rst:1780 +#: ../../faq/programming.rst:1786 msgid "There are several possible reasons for this." msgstr "這有幾個可能的原因。" -#: ../../faq/programming.rst:1782 +#: ../../faq/programming.rst:1788 msgid "" "The :keyword:`del` statement does not necessarily call :meth:`~object." "__del__` -- it simply decrements the object's reference count, and if this " @@ -3633,19 +3624,19 @@ msgstr "" ":keyword:`del` 陳述式不一定會呼叫 :meth:`~object.__del__` -- 它只是減少物件的" "參照計數,如果達到零則呼叫 :meth:`!__del__`。" -#: ../../faq/programming.rst:1786 +#: ../../faq/programming.rst:1792 #, fuzzy msgid "" -"If your data structures contain circular links (e.g. a tree where each child " -"has a parent reference and each parent has a list of children) the reference " -"counts will never go back to zero. Once in a while Python runs an algorithm " -"to detect such cycles, but the garbage collector might run some time after " -"the last reference to your data structure vanishes, so your :meth:`!__del__` " -"method may be called at an inconvenient and random time. This is " -"inconvenient if you're trying to reproduce a problem. Worse, the order in " -"which object's :meth:`!__del__` methods are executed is arbitrary. You can " -"run :func:`gc.collect` to force a collection, but there *are* pathological " -"cases where objects will never be collected." +"If your data structures contain circular links (for example, a tree where " +"each child has a parent reference and each parent has a list of children) " +"the reference counts will never go back to zero. Once in a while Python " +"runs an algorithm to detect such cycles, but the garbage collector might run " +"some time after the last reference to your data structure vanishes, so your :" +"meth:`!__del__` method may be called at an inconvenient and random time. " +"This is inconvenient if you're trying to reproduce a problem. Worse, the " +"order in which object's :meth:`!__del__` methods are executed is arbitrary. " +"You can run :func:`gc.collect` to force a collection, but there *are* " +"pathological cases where objects will never be collected." msgstr "" "如果你的資料結構包含循環鏈接(例如,一棵樹,其中每個子項都有一個父項參照,每" "個父項都有一個子項list),參照計數將永遠不會回到零。 Python 偶爾會運行一種演" @@ -3655,7 +3646,7 @@ msgstr "" "行順序是任意的。你可以運行 :func:`gc.collect` 來強制收集,但*存在*永遠不會收" "集物件的病態情況。" -#: ../../faq/programming.rst:1797 +#: ../../faq/programming.rst:1803 #, fuzzy msgid "" "Despite the cycle collector, it's still a good idea to define an explicit " @@ -3670,7 +3661,7 @@ msgstr "" "性。不要直接呼叫 :meth:`!__del__` -- :meth:`!__del__` 應該呼叫 ``close()`` 並" "且 ``close()`` 應該確保它可以多次呼叫同一個物件。" -#: ../../faq/programming.rst:1804 +#: ../../faq/programming.rst:1810 #, fuzzy msgid "" "Another way to avoid cyclical references is to use the :mod:`weakref` " @@ -3682,7 +3673,7 @@ msgstr "" "的情況下指向物件。例如,樹資料結構應該對其父參照和同級參照使用弱參照(如果需" "要的話!)。" -#: ../../faq/programming.rst:1817 +#: ../../faq/programming.rst:1823 msgid "" "Finally, if your :meth:`!__del__` method raises an exception, a warning " "message is printed to :data:`sys.stderr`." @@ -3690,11 +3681,11 @@ msgstr "" "最後,如果你的 :meth:`!__del__` 方法引發例外,則會將一條警告訊息印出到 :data:" "`sys.stderr`。" -#: ../../faq/programming.rst:1822 +#: ../../faq/programming.rst:1828 msgid "How do I get a list of all instances of a given class?" msgstr "我該如何取得給定類別的所有實例的串列?" -#: ../../faq/programming.rst:1824 +#: ../../faq/programming.rst:1830 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 " @@ -3703,11 +3694,11 @@ msgstr "" "Python 不會追蹤類別(或內建型別)的所有實例。你可以將類別的建構函式進行改寫," "以透過保留對每個實例之弱參照串列來追蹤所有實例。" -#: ../../faq/programming.rst:1830 +#: ../../faq/programming.rst:1836 msgid "Why does the result of ``id()`` appear to be not unique?" msgstr "為什麼 ``id()`` 的結果看起來不唯一?" -#: ../../faq/programming.rst:1832 +#: ../../faq/programming.rst:1838 #, fuzzy msgid "" "The :func:`id` builtin returns an integer that is guaranteed to be unique " @@ -3720,7 +3711,7 @@ msgstr "" "CPython 中,這是物件的記憶體地址,所以經常發生在從記憶體中刪除一個物件後,下" "一個新建立的物件被分配在記憶體中的相同位置。這個例子說明了這一點:" -#: ../../faq/programming.rst:1843 +#: ../../faq/programming.rst:1849 #, fuzzy msgid "" "The two ids belong to different integer objects that are created before, and " @@ -3731,18 +3722,18 @@ msgstr "" "這兩個 id 屬於之前建立的不同整數物件,並在執行 ``id()`` 呼叫後立即刪除。要確" "保你要檢查其 id 的物件仍然存在,請建立對該物件的另一個參照:" -#: ../../faq/programming.rst:1858 +#: ../../faq/programming.rst:1864 msgid "When can I rely on identity tests with the *is* operator?" msgstr "我什麼時候可以依靠 *is* 運算子進行識別性測試?" -#: ../../faq/programming.rst:1860 +#: ../../faq/programming.rst:1866 msgid "" "The ``is`` operator tests for object identity. The test ``a is b`` is " "equivalent to ``id(a) == id(b)``." msgstr "" "``is`` 運算子測試物件識別性。測試 ``a is b`` 等同於 ``id(a) == id(b)`` 。" -#: ../../faq/programming.rst:1863 +#: ../../faq/programming.rst:1869 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 " @@ -3753,7 +3744,7 @@ msgstr "" "識別性測試通常比相等性測試更快。與相等性測試不同,識別性測試保證回傳布林值 " "``True`` 或 ``False`` 。" -#: ../../faq/programming.rst:1868 +#: ../../faq/programming.rst:1874 msgid "" "However, identity tests can *only* be substituted for equality tests when " "object identity is assured. Generally, there are three circumstances where " @@ -3762,7 +3753,7 @@ msgstr "" "然而,*只有*\\ 當物件識別性得到保證時,識別性測試才能代替相等性測試。一般來" "說,保證識別性的情況有以下三種:" -#: ../../faq/programming.rst:1872 +#: ../../faq/programming.rst:1878 #, fuzzy msgid "" "Assignments create new names but do not change object identity. After the " @@ -3771,7 +3762,7 @@ msgstr "" "1) 賦值建立新名稱但不改變物件識別性。賦值 ``new = old`` 後,保證 ``new is " "old``。" -#: ../../faq/programming.rst:1875 +#: ../../faq/programming.rst:1881 #, fuzzy msgid "" "Putting an object in a container that stores object references does not " @@ -3781,7 +3772,7 @@ msgstr "" "2) 將物件放入儲存物件參照的容器中不會改變物件識別性。在 list 賦值 ``s[0] = " "x`` 之後,保證 ``s[0] 是 x``。" -#: ../../faq/programming.rst:1879 +#: ../../faq/programming.rst:1885 #, fuzzy msgid "" "If an object is a singleton, it means that only one instance of that object " @@ -3791,7 +3782,7 @@ msgstr "" "3)如果一個物件是單例,則意味著該物件只能存在一個實例。在賦值 ``a = None`` " "和 ``b = None`` 之後,可以保證 ``a is b`` 因為 ``None`` 是單例。" -#: ../../faq/programming.rst:1883 +#: ../../faq/programming.rst:1889 msgid "" "In most other circumstances, identity tests are inadvisable and equality " "tests are preferred. In particular, identity tests should not be used to " @@ -3801,11 +3792,12 @@ msgstr "" "在大多數其他情況下,識別性測試是不可取的,相等性測試是首選。特別是,識別性測" "試不應用於檢查常數,例如不能保證是單例的 :class:`int` 和 :class:`str`: ::" -#: ../../faq/programming.rst:1888 +#: ../../faq/programming.rst:1894 +#, fuzzy msgid "" -">>> a = 1000\n" -">>> b = 500\n" -">>> c = b + 500\n" +">>> a = 10_000_000\n" +">>> b = 5_000_000\n" +">>> c = b + 5_000_000\n" ">>> a is c\n" "False\n" "\n" @@ -3827,11 +3819,11 @@ msgstr "" ">>> a is c\n" "False" -#: ../../faq/programming.rst:1900 +#: ../../faq/programming.rst:1906 msgid "Likewise, new instances of mutable containers are never identical::" msgstr "同樣地,可變容器的新實例永遠不會相同: ::" -#: ../../faq/programming.rst:1902 +#: ../../faq/programming.rst:1908 msgid "" ">>> a = []\n" ">>> b = []\n" @@ -3843,13 +3835,13 @@ msgstr "" ">>> a is b\n" "False" -#: ../../faq/programming.rst:1907 +#: ../../faq/programming.rst:1913 msgid "" "In the standard library code, you will see several common patterns for " "correctly using identity tests:" msgstr "在標準函式庫程式碼中,你將看到幾種正確使用識別性測試的常見模式:" -#: ../../faq/programming.rst:1910 +#: ../../faq/programming.rst:1916 msgid "" "As recommended by :pep:`8`, an identity test is the preferred way to check " "for ``None``. This reads like plain English in code and avoids confusion " @@ -3858,7 +3850,7 @@ msgstr "" "正如 :pep:`8` 所推薦的,識別性測試是檢查 ``None`` 的首選方法。這在程式碼中讀" "起來像簡單的英語,並避免與其他可能具有評估為 false 的布林值的物件混淆。" -#: ../../faq/programming.rst:1914 +#: ../../faq/programming.rst:1920 #, fuzzy msgid "" "Detecting optional arguments can be tricky when ``None`` is a valid input " @@ -3870,7 +3862,7 @@ msgstr "" "立一個保證與其他物件不同的單例哨兵物件。例如,這裡是如何實作一個行為類似於 :" "meth:`dict.pop` 的方法:" -#: ../../faq/programming.rst:1919 +#: ../../faq/programming.rst:1925 msgid "" "_sentinel = object()\n" "\n" @@ -3894,7 +3886,7 @@ msgstr "" " raise KeyError(key)\n" " return default" -#: ../../faq/programming.rst:1932 +#: ../../faq/programming.rst:1938 msgid "" "Container implementations sometimes need to augment equality tests with " "identity tests. This prevents the code from being confused by objects such " @@ -3903,14 +3895,14 @@ msgstr "" "容器實作有時需要透過識別性測試來增強相等性測試。這可以防止程式碼被諸如 " "float('NaN') 之類的不等於自身的物件所混淆。" -#: ../../faq/programming.rst:1936 +#: ../../faq/programming.rst:1942 msgid "" "For example, here is the implementation of :meth:`!collections.abc.Sequence." "__contains__`::" msgstr "" "例如,以下是 :meth:`!collections.abc.Sequence.__contains__` 的實作: ::" -#: ../../faq/programming.rst:1939 +#: ../../faq/programming.rst:1945 msgid "" "def __contains__(self, value):\n" " for v in self:\n" @@ -3924,12 +3916,12 @@ msgstr "" " return True\n" " return False" -#: ../../faq/programming.rst:1947 +#: ../../faq/programming.rst:1953 msgid "" "How can a subclass control what data is stored in an immutable instance?" msgstr "子類別如何控制不可變實例中儲存的資料?" -#: ../../faq/programming.rst:1949 +#: ../../faq/programming.rst:1955 #, fuzzy msgid "" "When subclassing an immutable type, override the :meth:`~object.__new__` " @@ -3941,17 +3933,18 @@ msgstr "" "`~object.__init__` 方法。後者僅在*建立實例後*運行,這為時已晚,無法更改不可變" "實例中的資料。" -#: ../../faq/programming.rst:1954 +#: ../../faq/programming.rst:1960 msgid "" "All of these immutable classes have a different signature than their parent " "class:" msgstr "所有這些不可變類別都具有與其父類別不同的簽名:" -#: ../../faq/programming.rst:1957 +#: ../../faq/programming.rst:1963 +#, fuzzy msgid "" -"from datetime import date\n" +"import datetime as dt\n" "\n" -"class FirstOfMonthDate(date):\n" +"class FirstOfMonthDate(dt.date):\n" " \"Always choose the first day of the month\"\n" " def __new__(cls, year, month, day):\n" " return super().__new__(cls, year, month, 1)\n" @@ -3991,11 +3984,11 @@ msgstr "" " s = ''.join([c for c in s if c.isalnum() or c == '-'])\n" " return super().__new__(cls, s)" -#: ../../faq/programming.rst:1980 +#: ../../faq/programming.rst:1986 msgid "The classes can be used like this:" msgstr "這些類別可以像這樣使用:" -#: ../../faq/programming.rst:1982 +#: ../../faq/programming.rst:1988 msgid "" ">>> FirstOfMonthDate(2012, 2, 14)\n" "FirstOfMonthDate(2012, 2, 1)\n" @@ -4015,11 +4008,11 @@ msgstr "" ">>> TitleStr('Blog: Why Python Rocks')\n" "'blog-why-python-rocks'" -#: ../../faq/programming.rst:1997 +#: ../../faq/programming.rst:2003 msgid "How do I cache method calls?" msgstr "如何快取方法呼叫?" -#: ../../faq/programming.rst:1999 +#: ../../faq/programming.rst:2005 #, fuzzy msgid "" "The two principal tools for caching methods are :func:`functools." @@ -4029,17 +4022,17 @@ msgstr "" "快取方法的兩個主要工具是 func:`functools.cached_property` 和 :func:" "`functools.lru_cache`。前者在實例級別儲存結果,後者在類別級別儲存結果。" -#: ../../faq/programming.rst:2004 +#: ../../faq/programming.rst:2010 #, fuzzy 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 " +"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 "" "*cached_property* 方法僅適用於不帶任何引數的方法,它不會建立對實例的參照,只" "要實例還活著,快取的方法結果就會被保留。" -#: ../../faq/programming.rst:2008 +#: ../../faq/programming.rst:2014 #, fuzzy msgid "" "The advantage is that when an instance is no longer used, the cached method " @@ -4050,16 +4043,17 @@ msgstr "" "好處是當一個實例不再使用時,快取的方法結果會立即釋放。缺點是如果實例累積,累" "積的方法結果也會累積。他們可以不受限制地成長。" -#: ../../faq/programming.rst:2013 +#: ../../faq/programming.rst:2019 +#, fuzzy msgid "" -"The *lru_cache* approach works with methods that have :term:`hashable` " +"The ``lru_cache`` approach works with methods that have :term:`hashable` " "arguments. It creates a reference to the instance unless special efforts " "are made to pass in weak references." msgstr "" "*lru_cache* 方法適用於具有\\ :term:`可雜湊 `\\ 引數的方法。除非特別" "努力傳遞弱參照,否則它會建立對實例的參照。" -#: ../../faq/programming.rst:2017 +#: ../../faq/programming.rst:2023 #, fuzzy msgid "" "The advantage of the least recently used algorithm is that the cache is " @@ -4069,11 +4063,11 @@ msgstr "" "最近最少使用演算法的優點是快取受指定的 *maxsize* 限制。缺點是實例會一直保持活" "動狀態,直到它們從快取中老化或快取被清除。" -#: ../../faq/programming.rst:2022 +#: ../../faq/programming.rst:2028 msgid "This example shows the various techniques::" msgstr "這個例子展示了各種技術: ::" -#: ../../faq/programming.rst:2024 +#: ../../faq/programming.rst:2030 msgid "" "class Weather:\n" " \"Lookup weather information on a government website\"\n" @@ -4098,28 +4092,28 @@ msgid "" " # Depends on the station_id, date, and units." msgstr "" -#: ../../faq/programming.rst:2046 +#: ../../faq/programming.rst:2052 #, fuzzy msgid "" "The above example assumes that the *station_id* never changes. If the " -"relevant instance attributes are mutable, the *cached_property* approach " +"relevant instance attributes are mutable, the ``cached_property`` approach " "can't be made to work because it cannot detect changes to the attributes." msgstr "" "上面的例子假設 *station_id* 永遠不會改變。如果相關的實例屬性是可變的,則 " "*cached_property* 方法無法工作,因為它無法檢測到屬性的更改。" -#: ../../faq/programming.rst:2051 +#: ../../faq/programming.rst:2057 #, fuzzy 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." +"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 "" "要在 *station_id* 可變時使 *lru_cache* 方法起作用,該類別需要定義 :meth:" "`~object.__eq__` 和 :meth:`~object.__hash__` 方法,以便快取可以檢測相關屬性更" "新: ::" -#: ../../faq/programming.rst:2055 +#: ../../faq/programming.rst:2061 msgid "" "class Weather:\n" " \"Example with a mutable station identifier\"\n" @@ -4142,15 +4136,15 @@ msgid "" " # Depends on the station_id, date, and units." msgstr "" -#: ../../faq/programming.rst:2077 +#: ../../faq/programming.rst:2083 msgid "Modules" msgstr "模組" -#: ../../faq/programming.rst:2080 +#: ../../faq/programming.rst:2086 msgid "How do I create a .pyc file?" msgstr "如何建立 .pyc 檔案?" -#: ../../faq/programming.rst:2082 +#: ../../faq/programming.rst:2088 #, fuzzy msgid "" "When a module is imported for the first time (or when the source file has " @@ -4167,7 +4161,7 @@ msgstr "" "間部分依賴於特定的``python `` 建立它的二進製檔案。(有關詳細資訊,請參閱 :" "pep:`3147`。)" -#: ../../faq/programming.rst:2090 +#: ../../faq/programming.rst:2096 #, fuzzy msgid "" "One reason that a ``.pyc`` file may not be created is a permissions problem " @@ -4180,12 +4174,12 @@ msgstr "" "__pycache__ 子目錄。例如,如果你以一個使用者的身份開發但以另一個使用者的身份" "運行,例如你正在使用 Web 伺服器進行測試,就會發生這種情況。" -#: ../../faq/programming.rst:2095 +#: ../../faq/programming.rst:2101 #, fuzzy msgid "" "Unless the :envvar:`PYTHONDONTWRITEBYTECODE` environment variable is set, " "creation of a .pyc file is automatic if you're importing a module and Python " -"has the ability (permissions, free space, etc...) to create a " +"has the ability (permissions, free space, and so on) to create a " "``__pycache__`` subdirectory and write the compiled module to that " "subdirectory." msgstr "" @@ -4193,10 +4187,10 @@ msgstr "" "組並且 Python 有能力(權限、空閒空間等)建立一個 .pyc 檔案是自動的建立一個" "``__pycache__ `` 子目錄並將編譯後的模組寫入該子目錄。" -#: ../../faq/programming.rst:2100 +#: ../../faq/programming.rst:2106 #, fuzzy msgid "" -"Running Python on a top level script is not considered an import and no ``." +"Running Python on a top-level script is not considered an import and no ``." "pyc`` will be created. For example, if you have a top-level module ``foo." "py`` that imports another module ``xyz.py``, when you run ``foo`` (by typing " "``python foo.py`` as a shell command), a ``.pyc`` will be created for " @@ -4208,7 +4202,7 @@ msgstr "" "入 ``python foo.py`` 作為一個 shell 命令),將為 xyz 建立一個 .pyc 因為引入" "了 xyz,但是不會為 foo 建立 .pyc 檔案,因為 ` `foo.py`` 沒有被引入。" -#: ../../faq/programming.rst:2107 +#: ../../faq/programming.rst:2113 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:" @@ -4218,7 +4212,7 @@ msgstr "" "建立一個 ``.pyc`` 檔案 —— 你可以使用 :mod:`py_compile` 和 :mod:`compileall` " "模組。" -#: ../../faq/programming.rst:2111 +#: ../../faq/programming.rst:2117 msgid "" "The :mod:`py_compile` module can manually compile any module. One way is to " "use the ``compile()`` function in that module interactively::" @@ -4226,7 +4220,7 @@ msgstr "" ":mod:`py_compile` 模組允許手動編譯任何模組。其中一種方法是在該模組中以交互方" "式使用 ``compile()`` 函式: ::" -#: ../../faq/programming.rst:2114 +#: ../../faq/programming.rst:2120 msgid "" ">>> import py_compile\n" ">>> py_compile.compile('foo.py')" @@ -4234,16 +4228,17 @@ msgstr "" ">>> import py_compile\n" ">>> py_compile.compile('foo.py')" -#: ../../faq/programming.rst:2117 +#: ../../faq/programming.rst:2123 +#, fuzzy 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``)." +"*cfile*)." msgstr "" "這會將 ``.pyc`` 寫入與 ``foo.py`` 相同位置的 ``__pycache__`` 子目錄(或者你可" "以使用可選參數 ``cfile`` 覆蓋它)。" -#: ../../faq/programming.rst:2121 +#: ../../faq/programming.rst:2127 #, fuzzy msgid "" "You can also automatically compile all files in a directory or directories " @@ -4254,15 +4249,15 @@ msgstr "" "你還可以使用 :mod:`compileall` 模組自動編譯目錄中的所有檔案。你可以在 shell " "提示符下運行 ``compileall.py`` 並提供包含要編譯的 Python 檔案的目錄路徑: ::" -#: ../../faq/programming.rst:2126 +#: ../../faq/programming.rst:2132 msgid "python -m compileall ." msgstr "python -m compileall ." -#: ../../faq/programming.rst:2130 +#: ../../faq/programming.rst:2136 msgid "How do I find the current module name?" msgstr "如何找到目前模組名稱?" -#: ../../faq/programming.rst:2132 +#: ../../faq/programming.rst:2138 #, fuzzy msgid "" "A module can find out its own module name by looking at the predefined " @@ -4275,7 +4270,7 @@ msgstr "" "值為``'__main__'``,則該程式作為腳本運行。許多通常透過引入使用的模組還提供命" "令行介面或自檢,只有在檢查 ``__name__`` 後才執行此程式碼: ::" -#: ../../faq/programming.rst:2138 +#: ../../faq/programming.rst:2144 msgid "" "def main():\n" " print('Running test...')\n" @@ -4291,19 +4286,19 @@ msgstr "" "if __name__ == '__main__':\n" " main()" -#: ../../faq/programming.rst:2147 +#: ../../faq/programming.rst:2153 msgid "How can I have modules that mutually import each other?" msgstr "要怎樣才能擁有相互引入的模組?" -#: ../../faq/programming.rst:2149 +#: ../../faq/programming.rst:2155 msgid "Suppose you have the following modules:" msgstr "假設你有以下模組:" -#: ../../faq/programming.rst:2151 +#: ../../faq/programming.rst:2157 msgid ":file:`foo.py`::" msgstr ":file:`foo.py`: ::" -#: ../../faq/programming.rst:2153 +#: ../../faq/programming.rst:2159 msgid "" "from bar import bar_var\n" "foo_var = 1" @@ -4311,11 +4306,11 @@ msgstr "" "from bar import bar_var\n" "foo_var = 1" -#: ../../faq/programming.rst:2156 +#: ../../faq/programming.rst:2162 msgid ":file:`bar.py`::" msgstr ":file:`bar.py`: ::" -#: ../../faq/programming.rst:2158 +#: ../../faq/programming.rst:2164 msgid "" "from foo import foo_var\n" "bar_var = 2" @@ -4323,42 +4318,42 @@ msgstr "" "from foo import foo_var\n" "bar_var = 2" -#: ../../faq/programming.rst:2161 +#: ../../faq/programming.rst:2167 msgid "The problem is that the interpreter will perform the following steps:" msgstr "問題是直譯器將執行以下步驟:" -#: ../../faq/programming.rst:2163 +#: ../../faq/programming.rst:2169 msgid "main imports ``foo``" msgstr "主要引入 ``foo``" -#: ../../faq/programming.rst:2164 +#: ../../faq/programming.rst:2170 msgid "Empty globals for ``foo`` are created" msgstr "建立了 ``foo`` 的空全域變數" -#: ../../faq/programming.rst:2165 +#: ../../faq/programming.rst:2171 msgid "``foo`` is compiled and starts executing" msgstr "``foo`` 被編譯並開始執行" -#: ../../faq/programming.rst:2166 +#: ../../faq/programming.rst:2172 msgid "``foo`` imports ``bar``" msgstr "``foo`` 引入 ``bar``" -#: ../../faq/programming.rst:2167 +#: ../../faq/programming.rst:2173 msgid "Empty globals for ``bar`` are created" msgstr "建立了 ``bar`` 的空全域變數" -#: ../../faq/programming.rst:2168 +#: ../../faq/programming.rst:2174 msgid "``bar`` is compiled and starts executing" msgstr "``bar`` 已被編譯並開始執行" -#: ../../faq/programming.rst:2169 +#: ../../faq/programming.rst:2175 msgid "" "``bar`` imports ``foo`` (which is a no-op since there already is a module " "named ``foo``)" msgstr "" "``bar`` 引入 ``foo``\\ (這是一個空操作,因為已經有一個名為 ``foo`` 的模組)" -#: ../../faq/programming.rst:2170 +#: ../../faq/programming.rst:2176 msgid "" "The import mechanism tries to read ``foo_var`` from ``foo`` globals, to set " "``bar.foo_var = foo.foo_var``" @@ -4366,7 +4361,7 @@ msgstr "" "引入機制嘗試從 ``foo`` 全域變數中讀取 ``foo_var``,以設定 ``bar.foo_var = " "foo.foo_var``" -#: ../../faq/programming.rst:2172 +#: ../../faq/programming.rst:2178 msgid "" "The last step fails, because Python isn't done with interpreting ``foo`` yet " "and the global symbol dictionary for ``foo`` is still empty." @@ -4374,7 +4369,7 @@ msgstr "" "最後一步失敗了,因為 Python 還沒有完成對 ``foo`` 的直譯,而 ``foo`` 的全域符" "號字典仍然是空的。" -#: ../../faq/programming.rst:2175 +#: ../../faq/programming.rst:2181 #, fuzzy msgid "" "The same thing happens when you use ``import foo``, and then try to access " @@ -4383,11 +4378,11 @@ msgstr "" "當你使用 ``import foo``,然後嘗試在全域程式碼中存取 ``foo.foo_var`` 時,也會" "發生同樣的事情。" -#: ../../faq/programming.rst:2178 +#: ../../faq/programming.rst:2184 msgid "There are (at least) three possible workarounds for this problem." msgstr "此問題有(至少)三種可能的解決方法。" -#: ../../faq/programming.rst:2180 +#: ../../faq/programming.rst:2186 #, fuzzy msgid "" "Guido van Rossum recommends avoiding all uses of ``from import ..." @@ -4400,35 +4395,35 @@ msgstr "" "函式中。全域變數和類別變數的初始化應該只使用常數或內建函式。這意味著來自引入" "模組的所有內容都被參照為 ``.``。" -#: ../../faq/programming.rst:2185 +#: ../../faq/programming.rst:2191 msgid "" "Jim Roskind suggests performing steps in the following order in each module:" msgstr "Jim Roskind 建議在每個模組中按以下順序執行各個步驟:" -#: ../../faq/programming.rst:2187 +#: ../../faq/programming.rst:2193 #, fuzzy msgid "" "exports (globals, functions, and classes that don't need imported base " "classes)" msgstr "匯出(不需要引入基底類別的全域變數、函式和類別)" -#: ../../faq/programming.rst:2189 +#: ../../faq/programming.rst:2195 msgid "``import`` statements" msgstr "``import`` 陳述式" -#: ../../faq/programming.rst:2190 +#: ../../faq/programming.rst:2196 msgid "" "active code (including globals that are initialized from imported values)." msgstr "活躍程式碼(包括從引入值初始化的全域變數)。" -#: ../../faq/programming.rst:2192 +#: ../../faq/programming.rst:2198 msgid "" "Van Rossum doesn't like this approach much because the imports appear in a " "strange place, but it does work." msgstr "" "Van Rossum 不太喜歡這種方法,因為引入出現在一個奇怪的地方,但它確實有效。" -#: ../../faq/programming.rst:2195 +#: ../../faq/programming.rst:2201 msgid "" "Matthias Urlichs recommends restructuring your code so that the recursive " "import is not necessary in the first place." @@ -4436,15 +4431,15 @@ msgstr "" "Matthias Urlichs 建議重組 (restructuring) 你的程式碼,以便打從一開始就不需要" "遞迴引入。" -#: ../../faq/programming.rst:2198 +#: ../../faq/programming.rst:2204 msgid "These solutions are not mutually exclusive." msgstr "這些方案並不衝突。" -#: ../../faq/programming.rst:2202 +#: ../../faq/programming.rst:2208 msgid "__import__('x.y.z') returns ; how do I get z?" msgstr "__import__('x.y.z') 回傳 ,那我怎麼得到 z?" -#: ../../faq/programming.rst:2204 +#: ../../faq/programming.rst:2210 #, fuzzy msgid "" "Consider using the convenience function :func:`~importlib.import_module` " @@ -4453,17 +4448,17 @@ msgstr "" "考慮使用來自 :mod:`importlib` 的便利函式 :func:`~importlib.import_module` 代" "替: ::" -#: ../../faq/programming.rst:2207 +#: ../../faq/programming.rst:2213 msgid "z = importlib.import_module('x.y.z')" msgstr "z = importlib.import_module('x.y.z')" -#: ../../faq/programming.rst:2211 +#: ../../faq/programming.rst:2217 msgid "" "When I edit an imported module and reimport it, the changes don't show up. " "Why does this happen?" msgstr "當我編輯需要引入的模組並重新引入它時,更動沒有反應出來。為什麼會這樣?" -#: ../../faq/programming.rst:2213 +#: ../../faq/programming.rst:2219 #, fuzzy msgid "" "For reasons of efficiency as well as consistency, Python only reads the " @@ -4476,7 +4471,7 @@ msgstr "" "一個由許多模組組成的程式中,每個模組都引入相同的基本模組,基本模組將被解析和" "重新解析很多次。要強制重新讀取已更改的模組,請執行以下操作: ::" -#: ../../faq/programming.rst:2219 +#: ../../faq/programming.rst:2225 msgid "" "import importlib\n" "import modname\n" @@ -4486,17 +4481,18 @@ msgstr "" "import modname\n" "importlib.reload(modname)" -#: ../../faq/programming.rst:2223 +#: ../../faq/programming.rst:2229 +#, fuzzy msgid "" "Warning: this technique is not 100% fool-proof. In particular, modules " -"containing statements like ::" +"containing statements like::" msgstr "警告:此技術並非 100% 萬無一失。尤其是包含像這樣陳述式的模組: ::" -#: ../../faq/programming.rst:2226 +#: ../../faq/programming.rst:2232 msgid "from modname import some_objects" msgstr "from modname import some_objects" -#: ../../faq/programming.rst:2228 +#: ../../faq/programming.rst:2234 #, fuzzy msgid "" "will continue to work with the old version of the imported objects. If the " @@ -4507,7 +4503,7 @@ msgstr "" "將繼續使用舊版本的引入物件。如果模組包含類別定義,現有的類別實例將*不會*更新" "為使用新的類別定義。這可能會導致以下自相矛盾的行為: ::" -#: ../../faq/programming.rst:2233 +#: ../../faq/programming.rst:2239 msgid "" ">>> import importlib\n" ">>> import cls\n" @@ -4525,13 +4521,13 @@ msgstr "" ">>> isinstance(c, cls.C) # isinstance 為 false?!?\n" "False" -#: ../../faq/programming.rst:2241 +#: ../../faq/programming.rst:2247 msgid "" "The nature of the problem is made clear if you print out the \"identity\" of " "the class objects::" msgstr "如果印出類別物件的「識別性」,問題的本質就很清楚了: ::" -#: ../../faq/programming.rst:2244 +#: ../../faq/programming.rst:2250 msgid "" ">>> hex(id(c.__class__))\n" "'0x7352a0'\n" @@ -4543,18 +4539,44 @@ msgstr "" ">>> hex(id(cls.C))\n" "'0x4198d0'" -#: ../../faq/programming.rst:408 +#: ../../faq/programming.rst:409 msgid "argument" msgstr "argument(引數)" -#: ../../faq/programming.rst:408 +#: ../../faq/programming.rst:409 msgid "difference from parameter" msgstr "與 parameter(參數)的差異" -#: ../../faq/programming.rst:408 +#: ../../faq/programming.rst:409 msgid "parameter" msgstr "parameter(參數)" -#: ../../faq/programming.rst:408 +#: ../../faq/programming.rst:409 msgid "difference from argument" msgstr "與 argument(引數)的差異" + +#~ msgid "`Komodo IDE `_" +#~ msgstr "`Komodo IDE `_" + +#~ msgid "" +#~ ">>> list1 = [\"what\", \"I'm\", \"sorting\", \"by\"]\n" +#~ ">>> list2 = [\"something\", \"else\", \"to\", \"sort\"]\n" +#~ ">>> pairs = zip(list1, list2)\n" +#~ ">>> pairs = sorted(pairs)\n" +#~ ">>> pairs\n" +#~ "[(\"I'm\", 'else'), ('by', 'sort'), ('sorting', 'to'), ('what', " +#~ "'something')]\n" +#~ ">>> result = [x[1] for x in pairs]\n" +#~ ">>> result\n" +#~ "['else', 'sort', 'to', 'something']" +#~ msgstr "" +#~ ">>> list1 = [\"what\", \"I'm\", \"sorting\", \"by\"]\n" +#~ ">>> list2 = [\"something\", \"else\", \"to\", \"sort\"]\n" +#~ ">>> pairs = zip(list1, list2)\n" +#~ ">>> pairs = sorted(pairs)\n" +#~ ">>> pairs\n" +#~ "[(\"I'm\", 'else'), ('by', 'sort'), ('sorting', 'to'), ('what', " +#~ "'something')]\n" +#~ ">>> result = [x[1] for x in pairs]\n" +#~ ">>> result\n" +#~ "['else', 'sort', 'to', 'something']" diff --git a/howto/logging.po b/howto/logging.po index 9337a55f282..d22ef0a2b32 100644 --- a/howto/logging.po +++ b/howto/logging.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-09-08 15:25+0800\n" +"POT-Creation-Date: 2026-03-06 00:23+0000\n" "PO-Revision-Date: 2018-05-23 14:36+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -62,8 +62,8 @@ msgstr "什麼時候使用 logging" #: ../../howto/logging.rst:30 msgid "" "You can access logging functionality by creating a logger via ``logger = " -"getLogger(__name__)``, and then calling the " -"logger's :meth:`~Logger.debug`, :meth:`~Logger.info`, :meth:`~Logger.warning`, :meth:`~Logger.error` " +"logging.getLogger(__name__)``, and then calling the logger's :meth:`~Logger." +"debug`, :meth:`~Logger.info`, :meth:`~Logger.warning`, :meth:`~Logger.error` " "and :meth:`~Logger.critical` methods. To determine when to use logging, and " "to see which logger methods to use when, see the table below. It states, for " "each of a set of common tasks, the best tool to use for that task." @@ -130,8 +130,8 @@ msgstr "" #: ../../howto/logging.rst:63 msgid "" -"A logger's :meth:`~Logger.error`, :meth:`~Logger.exception` " -"or :meth:`~Logger.critical` method as appropriate for the specific error and " +"A logger's :meth:`~Logger.error`, :meth:`~Logger.exception` or :meth:" +"`~Logger.critical` method as appropriate for the specific error and " "application domain" msgstr "" @@ -242,8 +242,8 @@ msgstr "WARNING:root:Watch out!" msgid "" "printed out on the console. The ``INFO`` message doesn't appear because the " "default level is ``WARNING``. The printed message includes the indication of " -"the level and the description of the event provided in the logging call, " -"i.e. 'Watch out!'. The actual output can be formatted quite flexibly if you " +"the level and the description of the event provided in the logging call, i." +"e. 'Watch out!'. The actual output can be formatted quite flexibly if you " "need that; formatting options will also be explained later." msgstr "" @@ -275,8 +275,8 @@ msgstr "" msgid "" "import logging\n" "logger = logging.getLogger(__name__)\n" -"logging.basicConfig(filename='example.log', encoding='utf-8', " -"level=logging.DEBUG)\n" +"logging.basicConfig(filename='example.log', encoding='utf-8', level=logging." +"DEBUG)\n" "logger.debug('This message should go to the log file')\n" "logger.info('So should this')\n" "logger.warning('And this, too')\n" @@ -284,8 +284,8 @@ msgid "" msgstr "" "import logging\n" "logger = logging.getLogger(__name__)\n" -"logging.basicConfig(filename='example.log', encoding='utf-8', " -"level=logging.DEBUG)\n" +"logging.basicConfig(filename='example.log', encoding='utf-8', level=logging." +"DEBUG)\n" "logger.debug('This message should go to the log file')\n" "logger.info('So should this')\n" "logger.warning('And this, too')\n" @@ -375,11 +375,11 @@ msgstr "" #: ../../howto/logging.rst:204 msgid "" -"logging.basicConfig(filename='example.log', filemode='w', " -"level=logging.DEBUG)" +"logging.basicConfig(filename='example.log', filemode='w', level=logging." +"DEBUG)" msgstr "" -"logging.basicConfig(filename='example.log', filemode='w', " -"level=logging.DEBUG)" +"logging.basicConfig(filename='example.log', filemode='w', level=logging." +"DEBUG)" #: ../../howto/logging.rst:206 msgid "" @@ -436,15 +436,15 @@ msgstr "" #: ../../howto/logging.rst:239 msgid "" "import logging\n" -"logging.basicConfig(format='%(levelname)s:%(message)s', " -"level=logging.DEBUG)\n" +"logging.basicConfig(format='%(levelname)s:%(message)s', level=logging." +"DEBUG)\n" "logging.debug('This message should appear on the console')\n" "logging.info('So should this')\n" "logging.warning('And this, too')" msgstr "" "import logging\n" -"logging.basicConfig(format='%(levelname)s:%(message)s', " -"level=logging.DEBUG)\n" +"logging.basicConfig(format='%(levelname)s:%(message)s', level=logging." +"DEBUG)\n" "logging.debug('This message should appear on the console')\n" "logging.info('So should this')\n" "logging.warning('And this, too')" @@ -500,9 +500,9 @@ msgstr "" #: ../../howto/logging.rst:277 msgid "" -"The default format for date/time display (shown above) is like ISO8601 " -"or :rfc:`3339`. If you need more control over the formatting of the date/" -"time, provide a *datefmt* argument to ``basicConfig``, as in this example::" +"The default format for date/time display (shown above) is like ISO8601 or :" +"rfc:`3339`. If you need more control over the formatting of the date/time, " +"provide a *datefmt* argument to ``basicConfig``, as in this example::" msgstr "" #: ../../howto/logging.rst:281 @@ -527,8 +527,8 @@ msgstr "" #: ../../howto/logging.rst:291 msgid "" -"The format of the *datefmt* argument is the same as supported " -"by :func:`time.strftime`." +"The format of the *datefmt* argument is the same as supported by :func:`time." +"strftime`." msgstr "" #: ../../howto/logging.rst:296 @@ -626,11 +626,10 @@ msgstr "" #: ../../howto/logging.rst:348 msgid "" "The root of the hierarchy of loggers is called the root logger. That's the " -"logger used by the " -"functions :func:`debug`, :func:`info`, :func:`warning`, :func:`error` " -"and :func:`critical`, which just call the same-named method of the root " -"logger. The functions and the methods have the same signatures. The root " -"logger's name is printed as 'root' in the logged output." +"logger used by the functions :func:`debug`, :func:`info`, :func:`warning`, :" +"func:`error` and :func:`critical`, which just call the same-named method of " +"the root logger. The functions and the methods have the same signatures. The " +"root logger's name is printed as 'root' in the logged output." msgstr "" #: ../../howto/logging.rst:354 @@ -648,12 +647,12 @@ msgstr "" msgid "" "By default, no destination is set for any logging messages. You can specify " "a destination (such as console or file) by using :func:`basicConfig` as in " -"the tutorial examples. If you call the " -"functions :func:`debug`, :func:`info`, :func:`warning`, :func:`error` " -"and :func:`critical`, they will check to see if no destination is set; and " -"if one is not set, they will set a destination of the console " -"(``sys.stderr``) and a default format for the displayed message before " -"delegating to the root logger to do the actual message output." +"the tutorial examples. If you call the functions :func:`debug`, :func:" +"`info`, :func:`warning`, :func:`error` and :func:`critical`, they will check " +"to see if no destination is set; and if one is not set, they will set a " +"destination of the console (``sys.stderr``) and a default format for the " +"displayed message before delegating to the root logger to do the actual " +"message output." msgstr "" #: ../../howto/logging.rst:369 @@ -741,23 +740,22 @@ msgstr "" #: ../../howto/logging.rst:465 msgid "" -":meth:`Logger.debug`, :meth:`Logger.info`, :meth:`Logger.warning`, :meth:`Logger.error`, " -"and :meth:`Logger.critical` all create log records with a message and a " -"level that corresponds to their respective method names. The message is " -"actually a format string, which may contain the standard string substitution " -"syntax of ``%s``, ``%d``, ``%f``, and so on. The rest of their arguments is " -"a list of objects that correspond with the substitution fields in the " -"message. With regard to ``**kwargs``, the logging methods care only about a " -"keyword of ``exc_info`` and use it to determine whether to log exception " -"information." +":meth:`Logger.debug`, :meth:`Logger.info`, :meth:`Logger.warning`, :meth:" +"`Logger.error`, and :meth:`Logger.critical` all create log records with a " +"message and a level that corresponds to their respective method names. The " +"message is actually a format string, which may contain the standard string " +"substitution syntax of ``%s``, ``%d``, ``%f``, and so on. The rest of their " +"arguments is a list of objects that correspond with the substitution fields " +"in the message. With regard to ``**kwargs``, the logging methods care only " +"about a keyword of ``exc_info`` and use it to determine whether to log " +"exception information." msgstr "" #: ../../howto/logging.rst:475 msgid "" -":meth:`Logger.exception` creates a log message similar " -"to :meth:`Logger.error`. The difference is that :meth:`Logger.exception` " -"dumps a stack trace along with it. Call this method only from an exception " -"handler." +":meth:`Logger.exception` creates a log message similar to :meth:`Logger." +"error`. The difference is that :meth:`Logger.exception` dumps a stack trace " +"along with it. Call this method only from an exception handler." msgstr "" #: ../../howto/logging.rst:479 @@ -822,8 +820,8 @@ msgstr "" #: ../../howto/logging.rst:522 msgid "" "The standard library includes quite a few handler types (see :ref:`useful-" -"handlers`); the tutorials use mainly :class:`StreamHandler` " -"and :class:`FileHandler` in its examples." +"handlers`); the tutorials use mainly :class:`StreamHandler` and :class:" +"`FileHandler` in its examples." msgstr "" #: ../../howto/logging.rst:526 @@ -858,10 +856,10 @@ msgstr "" #: ../../howto/logging.rst:543 msgid "" -"Application code should not directly instantiate and use instances " -"of :class:`Handler`. Instead, the :class:`Handler` class is a base class " -"that defines the interface that all handlers should have and establishes " -"some default behavior that child classes can use (or override)." +"Application code should not directly instantiate and use instances of :class:" +"`Handler`. Instead, the :class:`Handler` class is a base class that defines " +"the interface that all handlers should have and establishes some default " +"behavior that child classes can use (or override)." msgstr "" #: ../../howto/logging.rst:550 @@ -898,8 +896,8 @@ msgstr "" #: ../../howto/logging.rst:571 msgid "" "If the ``style`` is ``'%'``, the message format string uses ``%()s`` styled string substitution; the possible keys are documented " -"in :ref:`logrecord-attributes`. If the style is ``'{'``, the message format " +"key>)s`` styled string substitution; the possible keys are documented in :" +"ref:`logrecord-attributes`. If the style is ``'{'``, the message format " "string is assumed to be compatible with :meth:`str.format` (using keyword " "arguments), while if the style is ``'$'`` then the message format string " "should conform to what is expected by :meth:`string.Template.substitute`." @@ -953,8 +951,8 @@ msgstr "" #: ../../howto/logging.rst:607 msgid "" -"Creating a dictionary of configuration information and passing it to " -"the :func:`dictConfig` function." +"Creating a dictionary of configuration information and passing it to the :" +"func:`dictConfig` function." msgstr "" #: ../../howto/logging.rst:610 @@ -977,8 +975,8 @@ msgid "" "ch.setLevel(logging.DEBUG)\n" "\n" "# create formatter\n" -"formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %" -"(message)s')\n" +"formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - " +"%(message)s')\n" "\n" "# add formatter to ch\n" "ch.setFormatter(formatter)\n" @@ -1115,11 +1113,11 @@ msgstr "" msgid "" "Note that the class names referenced in config files need to be either " "relative to the logging module, or absolute values which can be resolved " -"using normal import mechanisms. Thus, you could use " -"either :class:`~logging.handlers.WatchedFileHandler` (relative to the " -"logging module) or ``mypackage.mymodule.MyHandler`` (for a class defined in " -"package ``mypackage`` and module ``mymodule``, where ``mypackage`` is " -"available on the Python import path)." +"using normal import mechanisms. Thus, you could use either :class:`~logging." +"handlers.WatchedFileHandler` (relative to the logging module) or ``mypackage." +"mymodule.MyHandler`` (for a class defined in package ``mypackage`` and " +"module ``mymodule``, where ``mypackage`` is available on the Python import " +"path)." msgstr "" #: ../../howto/logging.rst:743 @@ -1184,10 +1182,10 @@ msgstr "" #: ../../howto/logging.rst:789 msgid "" -"The event is output using a 'handler of last resort', stored " -"in :data:`lastResort`. This internal handler is not associated with any " -"logger, and acts like a :class:`~logging.StreamHandler` which writes the " -"event description message to the current value of ``sys.stderr`` (therefore " +"The event is output using a 'handler of last resort', stored in :data:" +"`lastResort`. This internal handler is not associated with any logger, and " +"acts like a :class:`~logging.StreamHandler` which writes the event " +"description message to the current value of ``sys.stderr`` (therefore " "respecting any redirections which may be in effect). No formatting is done " "on the message - just the bare event description message is printed. The " "handler's level is set to ``WARNING``, so all events at this and greater " @@ -1244,13 +1242,13 @@ msgstr "" #: ../../howto/logging.rst:833 msgid "" -"A do-nothing handler is included in the logging " -"package: :class:`~logging.NullHandler` (since Python 3.1). An instance of " -"this handler could be added to the top-level logger of the logging namespace " -"used by the library (*if* you want to prevent your library's logged events " -"being output to ``sys.stderr`` in the absence of logging configuration). If " -"all logging by a library *foo* is done using loggers with names matching " -"'foo.x', 'foo.x.y', etc. then the code::" +"A do-nothing handler is included in the logging package: :class:`~logging." +"NullHandler` (since Python 3.1). An instance of this handler could be added " +"to the top-level logger of the logging namespace used by the library (*if* " +"you want to prevent your library's logged events being output to ``sys." +"stderr`` in the absence of logging configuration). If all logging by a " +"library *foo* is done using loggers with names matching 'foo.x', 'foo.x.y', " +"etc. then the code::" msgstr "" #: ../../howto/logging.rst:841 @@ -1280,14 +1278,13 @@ msgstr "" #: ../../howto/logging.rst:855 msgid "" -"It is strongly advised that you *do not add any handlers other " -"than* :class:`~logging.NullHandler` *to your library's loggers*. This is " -"because the configuration of handlers is the prerogative of the application " -"developer who uses your library. The application developer knows their " -"target audience and what handlers are most appropriate for their " -"application: if you add handlers 'under the hood', you might well interfere " -"with their ability to carry out unit tests and deliver logs which suit their " -"requirements." +"It is strongly advised that you *do not add any handlers other than* :class:" +"`~logging.NullHandler` *to your library's loggers*. This is because the " +"configuration of handlers is the prerogative of the application developer " +"who uses your library. The application developer knows their target audience " +"and what handlers are most appropriate for their application: if you add " +"handlers 'under the hood', you might well interfere with their ability to " +"carry out unit tests and deliver logs which suit their requirements." msgstr "" #: ../../howto/logging.rst:866 @@ -1348,35 +1345,35 @@ msgstr "" #: ../../howto/logging.rst:897 msgid "" "Logging messages are encoded as instances of the :class:`~logging.LogRecord` " -"class. When a logger decides to actually log an event, " -"a :class:`~logging.LogRecord` instance is created from the logging message." +"class. When a logger decides to actually log an event, a :class:`~logging." +"LogRecord` instance is created from the logging message." msgstr "" #: ../../howto/logging.rst:901 msgid "" -"Logging messages are subjected to a dispatch mechanism through the use " -"of :dfn:`handlers`, which are instances of subclasses of " -"the :class:`Handler` class. Handlers are responsible for ensuring that a " -"logged message (in the form of a :class:`LogRecord`) ends up in a particular " -"location (or set of locations) which is useful for the target audience for " -"that message (such as end users, support desk staff, system administrators, " -"developers). Handlers are passed :class:`LogRecord` instances intended for " -"particular destinations. Each logger can have zero, one or more handlers " -"associated with it (via the :meth:`~Logger.addHandler` method " -"of :class:`Logger`). In addition to any handlers directly associated with a " -"logger, *all handlers associated with all ancestors of the logger* are " -"called to dispatch the message (unless the *propagate* flag for a logger is " -"set to a false value, at which point the passing to ancestor handlers stops)." +"Logging messages are subjected to a dispatch mechanism through the use of :" +"dfn:`handlers`, which are instances of subclasses of the :class:`Handler` " +"class. Handlers are responsible for ensuring that a logged message (in the " +"form of a :class:`LogRecord`) ends up in a particular location (or set of " +"locations) which is useful for the target audience for that message (such as " +"end users, support desk staff, system administrators, developers). Handlers " +"are passed :class:`LogRecord` instances intended for particular " +"destinations. Each logger can have zero, one or more handlers associated " +"with it (via the :meth:`~Logger.addHandler` method of :class:`Logger`). In " +"addition to any handlers directly associated with a logger, *all handlers " +"associated with all ancestors of the logger* are called to dispatch the " +"message (unless the *propagate* flag for a logger is set to a false value, " +"at which point the passing to ancestor handlers stops)." msgstr "" #: ../../howto/logging.rst:915 msgid "" "Just as for loggers, handlers can have levels associated with them. A " "handler's level acts as a filter in the same way as a logger's level does. " -"If a handler decides to actually dispatch an event, " -"the :meth:`~Handler.emit` method is used to send the message to its " -"destination. Most user-defined subclasses of :class:`Handler` will need to " -"override this :meth:`~Handler.emit`." +"If a handler decides to actually dispatch an event, the :meth:`~Handler." +"emit` method is used to send the message to its destination. Most user-" +"defined subclasses of :class:`Handler` will need to override this :meth:" +"`~Handler.emit`." msgstr "" #: ../../howto/logging.rst:924 @@ -1420,8 +1417,8 @@ msgstr "" msgid "" ":class:`~handlers.BaseRotatingHandler` is the base class for handlers that " "rotate log files at a certain point. It is not meant to be instantiated " -"directly. Instead, use :class:`~handlers.RotatingFileHandler` " -"or :class:`~handlers.TimedRotatingFileHandler`." +"directly. Instead, use :class:`~handlers.RotatingFileHandler` or :class:" +"`~handlers.TimedRotatingFileHandler`." msgstr "" #: ../../howto/logging.rst:954 @@ -1462,8 +1459,8 @@ msgstr "" #: ../../howto/logging.rst:972 msgid "" -":class:`~handlers.NTEventLogHandler` instances send messages to a Windows NT/" -"2000/XP event log." +":class:`~handlers.NTEventLogHandler` instances send messages to a Windows " +"NT/2000/XP event log." msgstr "" #: ../../howto/logging.rst:975 @@ -1519,27 +1516,27 @@ msgstr "" #: ../../howto/logging.rst:1006 msgid "" -"Logged messages are formatted for presentation through instances of " -"the :class:`Formatter` class. They are initialized with a format string " -"suitable for use with the % operator and a dictionary." +"Logged messages are formatted for presentation through instances of the :" +"class:`Formatter` class. They are initialized with a format string suitable " +"for use with the % operator and a dictionary." msgstr "" #: ../../howto/logging.rst:1010 msgid "" -"For formatting multiple messages in a batch, instances " -"of :class:`BufferingFormatter` can be used. In addition to the format string " -"(which is applied to each message in the batch), there is provision for " -"header and trailer format strings." +"For formatting multiple messages in a batch, instances of :class:" +"`BufferingFormatter` can be used. In addition to the format string (which is " +"applied to each message in the batch), there is provision for header and " +"trailer format strings." msgstr "" #: ../../howto/logging.rst:1015 msgid "" "When filtering based on logger level and/or handler level is not enough, " -"instances of :class:`Filter` can be added to both :class:`Logger` " -"and :class:`Handler` instances (through their :meth:`~Handler.addFilter` " -"method). Before deciding to process a message further, both loggers and " -"handlers consult all their filters for permission. If any filter returns a " -"false value, the message is not processed further." +"instances of :class:`Filter` can be added to both :class:`Logger` and :class:" +"`Handler` instances (through their :meth:`~Handler.addFilter` method). " +"Before deciding to process a message further, both loggers and handlers " +"consult all their filters for permission. If any filter returns a false " +"value, the message is not processed further." msgstr "" #: ../../howto/logging.rst:1022 @@ -1565,16 +1562,16 @@ msgstr "" msgid "" ":class:`SystemExit` and :class:`KeyboardInterrupt` exceptions are never " "swallowed. Other exceptions which occur during the :meth:`~Handler.emit` " -"method of a :class:`Handler` subclass are passed to " -"its :meth:`~Handler.handleError` method." +"method of a :class:`Handler` subclass are passed to its :meth:`~Handler." +"handleError` method." msgstr "" #: ../../howto/logging.rst:1042 msgid "" -"The default implementation of :meth:`~Handler.handleError` " -"in :class:`Handler` checks to see if a module-level " -"variable, :data:`raiseExceptions`, is set. If set, a traceback is printed " -"to :data:`sys.stderr`. If not set, the exception is swallowed." +"The default implementation of :meth:`~Handler.handleError` in :class:" +"`Handler` checks to see if a module-level variable, :data:`raiseExceptions`, " +"is set. If set, a traceback is printed to :data:`sys.stderr`. If not set, " +"the exception is swallowed." msgstr "" #: ../../howto/logging.rst:1048 @@ -1593,12 +1590,12 @@ msgstr "" msgid "" "In the preceding sections and examples, it has been assumed that the message " "passed when logging the event is a string. However, this is not the only " -"possibility. You can pass an arbitrary object as a message, and " -"its :meth:`~object.__str__` method will be called when the logging system " -"needs to convert it to a string representation. In fact, if you want to, you " -"can avoid computing a string representation altogether - for example, " -"the :class:`~handlers.SocketHandler` emits an event by pickling it and " -"sending it over the wire." +"possibility. You can pass an arbitrary object as a message, and its :meth:" +"`~object.__str__` method will be called when the logging system needs to " +"convert it to a string representation. In fact, if you want to, you can " +"avoid computing a string representation altogether - for example, the :class:" +"`~handlers.SocketHandler` emits an event by pickling it and sending it over " +"the wire." msgstr "" #: ../../howto/logging.rst:1071 @@ -1610,10 +1607,10 @@ msgid "" "Formatting of message arguments is deferred until it cannot be avoided. " "However, computing the arguments passed to the logging method can also be " "expensive, and you may want to avoid doing it if the logger will just throw " -"away your event. To decide what to do, you can call " -"the :meth:`~Logger.isEnabledFor` method which takes a level argument and " -"returns true if the event would be created by the Logger for that level of " -"call. You can write code like this::" +"away your event. To decide what to do, you can call the :meth:`~Logger." +"isEnabledFor` method which takes a level argument and returns true if the " +"event would be created by the Logger for that level of call. You can write " +"code like this::" msgstr "" #: ../../howto/logging.rst:1081 @@ -1663,10 +1660,9 @@ msgstr "" #: ../../howto/logging.rst:1105 msgid "" -"Set ``logging._srcfile`` to ``None``. This avoids " -"calling :func:`sys._getframe`, which may help to speed up your code in " -"environments like PyPy (which can't speed up code that " -"uses :func:`sys._getframe`)." +"Set ``logging._srcfile`` to ``None``. This avoids calling :func:`sys." +"_getframe`, which may help to speed up your code in environments like PyPy " +"(which can't speed up code that uses :func:`sys._getframe`)." msgstr "" #: ../../howto/logging.rst:1111 diff --git a/installing/index.po b/installing/index.po index cef15e95ed7..e844abe3312 100644 --- a/installing/index.po +++ b/installing/index.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-09-03 11:11+0800\n" +"POT-Creation-Date: 2026-03-10 00:17+0000\n" "PO-Revision-Date: 2022-06-27 09:37+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -25,15 +25,7 @@ msgstr "" msgid "Installing Python Modules" msgstr "安裝 Python 模組" -#: ../../installing/index.rst:0 -msgid "Email" -msgstr "電子郵件" - #: ../../installing/index.rst:9 -msgid "distutils-sig@python.org" -msgstr "distutils-sig@python.org" - -#: ../../installing/index.rst:11 msgid "" "As a popular open source development project, Python has an active " "supporting community of contributors and users that also make their software " @@ -42,7 +34,7 @@ msgstr "" "作為一個普及的開源開發專案,Python 有一個活躍的支持社群,由其貢獻者及使用者組" "成,而他們也讓他們的軟體可被其他 Python 開發者在開源授權條款下使用。" -#: ../../installing/index.rst:15 +#: ../../installing/index.rst:13 msgid "" "This allows Python users to share and collaborate effectively, benefiting " "from the solutions others have already created to common (and sometimes even " @@ -53,7 +45,7 @@ msgstr "" "罕見)的問題已經建立的解決方案,更可以在公用社群中潛在地貢獻他們自己的解決方" "案。" -#: ../../installing/index.rst:20 +#: ../../installing/index.rst:18 msgid "" "This guide covers the installation part of the process. For a guide to " "creating and sharing your own Python projects, refer to the `Python " @@ -62,7 +54,7 @@ msgstr "" "這份指南涵蓋了上述過程中的安裝部分。如果是要建立及分享你自己的 Python 專案," "請參考 `Python packaging user guide`_。" -#: ../../installing/index.rst:28 +#: ../../installing/index.rst:26 msgid "" "For corporate and other institutional users, be aware that many " "organisations have their own policies around using and contributing to open " @@ -72,11 +64,11 @@ msgstr "" "對於企業和其他機構的使用者,要注意到,許多組織對於使用和貢獻開源軟體都有自己" "的政策。在開始使用配備 Python 的發布及安裝工具時,請將那些政策納入考量。" -#: ../../installing/index.rst:35 +#: ../../installing/index.rst:33 msgid "Key terms" msgstr "關鍵術語" -#: ../../installing/index.rst:37 +#: ../../installing/index.rst:35 msgid "" "``pip`` is the preferred installer program. Starting with Python 3.4, it is " "included by default with the Python binary installers." @@ -84,7 +76,7 @@ msgstr "" "``pip`` 是首選的安裝程式。從 Python 3.4 開始,它被預設包含在 Python 二進制安" "裝程式中。" -#: ../../installing/index.rst:39 +#: ../../installing/index.rst:37 msgid "" "A *virtual environment* is a semi-isolated Python environment that allows " "packages to be installed for use by a particular application, rather than " @@ -93,7 +85,7 @@ msgstr "" "*virtual environment(虛擬環境)*\\ 是一種半隔離的 Python 環境,可以為某個特" "定應用程式安裝其所需的套件,而不用在整個系統上安裝它們。" -#: ../../installing/index.rst:42 +#: ../../installing/index.rst:40 msgid "" "``venv`` is the standard tool for creating virtual environments, and has " "been part of Python since Python 3.3. Starting with Python 3.4, it defaults " @@ -102,7 +94,7 @@ msgstr "" "``venv`` 是建立虛擬環境的標準工具,它從 Python 3.3 開始成為 Python 的一部分。" "從 Python 3.4 開始,它會預設地安裝 ``pip`` 到所有被建立的虛擬環境。" -#: ../../installing/index.rst:45 +#: ../../installing/index.rst:43 msgid "" "``virtualenv`` is a third party alternative (and predecessor) to ``venv``. " "It allows virtual environments to be used on versions of Python prior to " @@ -113,7 +105,7 @@ msgstr "" "在 Python 3.4 之前的版本被使用,那些版本要不是根本沒提供 ``venv``,就是無法自" "動安裝 ``pip`` 到所建立的環境中。" -#: ../../installing/index.rst:49 +#: ../../installing/index.rst:47 msgid "" "The `Python Package Index `__ is a public repository of " "open source licensed packages made available for use by other Python users." @@ -121,7 +113,7 @@ msgstr "" "`Python 套件索引 (Python Package Index) `__ 是開源授權套件" "的一個公共儲存庫,其中的套件皆可被其他 Python 使用者所使用。" -#: ../../installing/index.rst:52 +#: ../../installing/index.rst:50 msgid "" "the `Python Packaging Authority `__ is the group of " "developers and documentation authors responsible for the maintenance and " @@ -134,7 +126,7 @@ msgstr "" "元資料 (metadata) 和檔案格式標準。他們在 `GitHub `__ 平台上維護各種工具、說明文件及問題追蹤系統。" -#: ../../installing/index.rst:58 +#: ../../installing/index.rst:56 msgid "" "``distutils`` is the original build and distribution system first added to " "the Python standard library in 1998. While direct use of ``distutils`` is " @@ -148,12 +140,12 @@ msgstr "" "基礎結構根基,而且它不僅仍然是標準函式庫的一部分,它的名稱也以其他的方式存活" "著(例如:用於協調 Python 封裝標準開發的郵寄清單就是以它命名)。" -#: ../../installing/index.rst:66 +#: ../../installing/index.rst:64 msgid "" "The use of ``venv`` is now recommended for creating virtual environments." msgstr "對於建立虛擬環境,現在推薦使用 ``venv``。" -#: ../../installing/index.rst:71 +#: ../../installing/index.rst:69 msgid "" "`Python Packaging User Guide: Creating and using virtual environments " "`__" @@ -161,17 +153,17 @@ msgstr "" "`Python 封裝使用者指南:建立和使用虛擬環境 `__" -#: ../../installing/index.rst:76 +#: ../../installing/index.rst:74 msgid "Basic usage" msgstr "基本用法" -#: ../../installing/index.rst:78 +#: ../../installing/index.rst:76 msgid "" "The standard packaging tools are all designed to be used from the command " "line." msgstr "標準封裝工具皆是以能從命令列使用的方式被設計的。" -#: ../../installing/index.rst:81 +#: ../../installing/index.rst:79 msgid "" "The following command will install the latest version of a module and its " "dependencies from the Python Package Index::" @@ -179,11 +171,11 @@ msgstr "" "以下指令將從 Python 套件索引安裝一個模組的最新版本及其依賴套件 " "(dependencies): ::" -#: ../../installing/index.rst:84 +#: ../../installing/index.rst:82 msgid "python -m pip install SomePackage" msgstr "python -m pip install SomePackage" -#: ../../installing/index.rst:88 +#: ../../installing/index.rst:86 msgid "" "For POSIX users (including macOS and Linux users), the examples in this " "guide assume the use of a :term:`virtual environment`." @@ -191,7 +183,7 @@ msgstr "" "對於 POSIX 使用者(包括 macOS 和 Linux 使用者),本指南中的範例皆假設有使用 :" "term:`virtual environment`。" -#: ../../installing/index.rst:91 +#: ../../installing/index.rst:89 msgid "" "For Windows users, the examples in this guide assume that the option to " "adjust the system PATH environment variable was selected when installing " @@ -200,7 +192,7 @@ msgstr "" "對於 Windows 使用者,本指南中的範例皆假設在安裝 Python 時,「可調整系統 PATH " "環境變數」的選項已被選取。" -#: ../../installing/index.rst:95 +#: ../../installing/index.rst:93 msgid "" "It's also possible to specify an exact or minimum version directly on the " "command line. When using comparator operators such as ``>``, ``<`` or some " @@ -211,7 +203,7 @@ msgstr "" "的比較運算子,或某些可被 shell 所解釋的其他特殊字元時,套件名稱與版本編號應該" "要放在雙引號內: ::" -#: ../../installing/index.rst:100 +#: ../../installing/index.rst:98 msgid "" "python -m pip install SomePackage==1.0.4 # specific version\n" "python -m pip install \"SomePackage>=1.0.4\" # minimum version" @@ -219,7 +211,7 @@ msgstr "" "python -m pip install SomePackage==1.0.4 # 明確版本\n" "python -m pip install \"SomePackage>=1.0.4\" # 最小版本" -#: ../../installing/index.rst:103 +#: ../../installing/index.rst:101 msgid "" "Normally, if a suitable module is already installed, attempting to install " "it again will have no effect. Upgrading existing modules must be requested " @@ -228,11 +220,11 @@ msgstr "" "通常,如果一個合適的模組已被安裝,嘗試再次安裝它將不會有任何效果。要升級現有" "的模組就必須明確地請求: ::" -#: ../../installing/index.rst:107 +#: ../../installing/index.rst:105 msgid "python -m pip install --upgrade SomePackage" msgstr "python -m pip install --upgrade SomePackage" -#: ../../installing/index.rst:109 +#: ../../installing/index.rst:107 msgid "" "More information and resources regarding ``pip`` and its capabilities can be " "found in the `Python Packaging User Guide `__." @@ -240,7 +232,7 @@ msgstr "" "關於 ``pip`` 及其能力的更多資訊和資源,可以在 `Python 封裝使用者指南 " "`__\\ 中找到。" -#: ../../installing/index.rst:112 +#: ../../installing/index.rst:110 msgid "" "Creation of virtual environments is done through the :mod:`venv` module. " "Installing packages into an active virtual environment uses the commands " @@ -249,7 +241,7 @@ msgstr "" "虛擬環境的建立是使用 :mod:`venv` 模組來完成。要在一個已啟用的虛擬環境中安裝套" "件,可使用前面展示的指令。" -#: ../../installing/index.rst:118 +#: ../../installing/index.rst:116 msgid "" "`Python Packaging User Guide: Installing Python Distribution Packages " "`__" @@ -257,19 +249,19 @@ msgstr "" "`Python 封裝使用者指南:安裝 Python 發布套件 `__" -#: ../../installing/index.rst:123 +#: ../../installing/index.rst:121 msgid "How do I ...?" msgstr "我該如何...?" -#: ../../installing/index.rst:125 +#: ../../installing/index.rst:123 msgid "These are quick answers or links for some common tasks." msgstr "接下來是關於一些常見任務的快速解答或連結。" -#: ../../installing/index.rst:128 +#: ../../installing/index.rst:126 msgid "... install ``pip`` in versions of Python prior to Python 3.4?" msgstr "...在 Python 3.4 之前的 Python 版本中安裝 ``pip``?" -#: ../../installing/index.rst:130 +#: ../../installing/index.rst:128 msgid "" "Python only started bundling ``pip`` with Python 3.4. For earlier versions, " "``pip`` needs to be \"bootstrapped\" as described in the Python Packaging " @@ -278,7 +270,7 @@ msgstr "" "Python 是從 Python 3.4 才開始綁定 ``pip`` 的。對於更早的版本,``pip`` 需要被" "「自助安裝 (bootstrapped)」,請參考 Python 封裝使用者指南中的說明。" -#: ../../installing/index.rst:136 +#: ../../installing/index.rst:134 msgid "" "`Python Packaging User Guide: Requirements for Installing Packages `__" @@ -286,11 +278,11 @@ msgstr "" "`Python 封裝使用者指南:安裝套件的需求 `__" -#: ../../installing/index.rst:143 +#: ../../installing/index.rst:141 msgid "... install packages just for the current user?" msgstr "...只為目前的使用者安裝套件?" -#: ../../installing/index.rst:145 +#: ../../installing/index.rst:143 msgid "" "Passing the ``--user`` option to ``python -m pip install`` will install a " "package just for the current user, rather than for all users of the system." @@ -298,11 +290,11 @@ msgstr "" "把 ``--user`` 選項傳給 ``python -m pip install``,這樣將會只為目前使用者而非" "系統的所有使用者安裝套件。" -#: ../../installing/index.rst:150 +#: ../../installing/index.rst:148 msgid "... install scientific Python packages?" msgstr "...安裝科學的 Python 套件?" -#: ../../installing/index.rst:152 +#: ../../installing/index.rst:150 msgid "" "A number of scientific Python packages have complex binary dependencies, and " "aren't currently easy to install using ``pip`` directly. At this point in " @@ -314,7 +306,7 @@ msgstr "" "``pip`` 安裝。目前為止,使用\\ `其他方法 `__\\ 而非嘗試用 ``pip`` 來安裝它們,對使用者來說通常會更簡單。" -#: ../../installing/index.rst:160 +#: ../../installing/index.rst:158 msgid "" "`Python Packaging User Guide: Installing Scientific Packages `__" @@ -322,11 +314,11 @@ msgstr "" "`Python 封裝使用者指南:安裝科學套件 `__" -#: ../../installing/index.rst:165 +#: ../../installing/index.rst:163 msgid "... work with multiple versions of Python installed in parallel?" msgstr "...平行安裝多個 Python 版本並使用它們?" -#: ../../installing/index.rst:167 +#: ../../installing/index.rst:165 msgid "" "On Linux, macOS, and other POSIX systems, use the versioned Python commands " "in combination with the ``-m`` switch to run the appropriate copy of " @@ -335,7 +327,7 @@ msgstr "" "在 Linux、macOS 以及其他 POSIX 系統中,使用帶有版本編號的 Python 指令並結合 " "``-m`` 開關參數 (switch),來運行 ``pip`` 的適當副本: ::" -#: ../../installing/index.rst:171 +#: ../../installing/index.rst:169 msgid "" "python2 -m pip install SomePackage # default Python 2\n" "python2.7 -m pip install SomePackage # specifically Python 2.7\n" @@ -347,11 +339,11 @@ msgstr "" "python3 -m pip install SomePackage # 預設 Python 3\n" "python3.4 -m pip install SomePackage # 指定 Python 3.4" -#: ../../installing/index.rst:176 +#: ../../installing/index.rst:174 msgid "Appropriately versioned ``pip`` commands may also be available." msgstr "使用帶有合適版本編號的 ``pip`` 指令,也是可行的。" -#: ../../installing/index.rst:178 +#: ../../installing/index.rst:176 msgid "" "On Windows, use the ``py`` Python launcher in combination with the ``-m`` " "switch::" @@ -359,7 +351,7 @@ msgstr "" "在 Windows 中,使用 Python 啟動指令 ``py`` 並結合 ``-m`` 開關參數 " "(switch): ::" -#: ../../installing/index.rst:181 +#: ../../installing/index.rst:179 msgid "" "py -2 -m pip install SomePackage # default Python 2\n" "py -2.7 -m pip install SomePackage # specifically Python 2.7\n" @@ -371,15 +363,15 @@ msgstr "" "py -3 -m pip install SomePackage # 預設 Python 3\n" "py -3.4 -m pip install SomePackage # 指定 Python 3.4" -#: ../../installing/index.rst:195 +#: ../../installing/index.rst:193 msgid "Common installation issues" msgstr "常見的安裝問題" -#: ../../installing/index.rst:198 +#: ../../installing/index.rst:196 msgid "Installing into the system Python on Linux" msgstr "在 Linux 上安裝套件至系統 Python" -#: ../../installing/index.rst:200 +#: ../../installing/index.rst:198 msgid "" "On Linux systems, a Python installation will typically be included as part " "of the distribution. Installing into this Python installation requires root " @@ -391,7 +383,7 @@ msgstr "" "件到這個 Python 版本上需要系統的 root 權限,並且可能會干擾到系統套件管理器的" "運作。如果其他系統組件非預期地以 ``pip`` 被升級,也會干擾這些組件的運作。" -#: ../../installing/index.rst:206 +#: ../../installing/index.rst:204 msgid "" "On such systems, it is often better to use a virtual environment or a per-" "user installation when installing packages with ``pip``." @@ -399,21 +391,21 @@ msgstr "" "在這樣的系統上,以 ``pip`` 安裝套件時,通常較好的方式是使用虛擬環境,或以個別" "使用者安裝。" -#: ../../installing/index.rst:211 +#: ../../installing/index.rst:209 msgid "Pip not installed" msgstr "未安裝 pip" -#: ../../installing/index.rst:213 +#: ../../installing/index.rst:211 msgid "" "It is possible that ``pip`` does not get installed by default. One potential " "fix is::" msgstr "``pip`` 沒有預設被安裝也是有可能的。一個潛在的解法是: ::" -#: ../../installing/index.rst:215 +#: ../../installing/index.rst:213 msgid "python -m ensurepip --default-pip" msgstr "python -m ensurepip --default-pip" -#: ../../installing/index.rst:217 +#: ../../installing/index.rst:215 msgid "" "There are also additional resources for `installing pip. `__\\ 的資源。" -#: ../../installing/index.rst:222 +#: ../../installing/index.rst:220 msgid "Installing binary extensions" msgstr "安裝二進制擴充 (binary extension)" -#: ../../installing/index.rst:224 +#: ../../installing/index.rst:222 msgid "" "Python has typically relied heavily on source based distribution, with end " "users being expected to compile extension modules from source as part of the " @@ -436,7 +428,7 @@ msgstr "" "Python 基本上相當倚賴以原始碼為基礎的發布方式,也會期望使用者在安裝過程的某個" "階段,從原始碼來編譯擴充模組。" -#: ../../installing/index.rst:228 +#: ../../installing/index.rst:226 msgid "" "With the introduction of support for the binary ``wheel`` format, and the " "ability to publish wheels for at least Windows and macOS through the Python " @@ -448,7 +440,7 @@ msgstr "" "Windows 和 macOS 發布 wheel 檔案,這個問題預期將會逐漸消失,因為使用者將能夠" "更頻繁地安裝預建置 (pre-built) 的擴充,而不再需要自己建置它們。" -#: ../../installing/index.rst:234 +#: ../../installing/index.rst:232 msgid "" "Some of the solutions for installing `scientific software `__ that are not yet available as pre-built ``wheel`` " @@ -459,10 +451,16 @@ msgstr "" "軟體 `__,這些方案也有助於取得其他的二" "進制擴充,且無需在本機對它們進行建置。" -#: ../../installing/index.rst:241 +#: ../../installing/index.rst:239 msgid "" "`Python Packaging User Guide: Binary Extensions `__" msgstr "" "`Python 封裝使用者指南:二進制擴充 `__" + +#~ msgid "Email" +#~ msgstr "電子郵件" + +#~ msgid "distutils-sig@python.org" +#~ msgstr "distutils-sig@python.org" diff --git a/library/argparse.po b/library/argparse.po index 5b02d91b023..202c426d5ca 100644 --- a/library/argparse.po +++ b/library/argparse.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-24 00:20+0000\n" +"POT-Creation-Date: 2026-03-04 00:19+0000\n" "PO-Revision-Date: 2018-05-23 14:38+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -39,11 +39,11 @@ msgid "" "option parameter values that start with ``-`` even when they correspond to " "another defined option)." msgstr "" -"雖然 :mod:`!argparse` 是實作基本命令列應用程式時預設推薦的標準函式庫模組,但如" -"果開發者對命令列應用程式的行為有更精確的要求,可能會發現它無法提供足夠的控制" -"程度。當 ``argparse`` 不支援應用程式所需的行為時(例如完全停用交錯選項與位置" -"引數的支援,或是允許以 ``-`` 開頭但可能與其他已定義選項相同的選項參數值),請" -"參閱\\ :ref:`choosing-an-argument-parser`\\ 以了解替代方案。" +"雖然 :mod:`!argparse` 是實作基本命令列應用程式時預設推薦的標準函式庫模組,但" +"如果開發者對命令列應用程式的行為有更精確的要求,可能會發現它無法提供足夠的控" +"制程度。當 ``argparse`` 不支援應用程式所需的行為時(例如完全停用交錯選項與位" +"置引數的支援,或是允許以 ``-`` 開頭但可能與其他已定義選項相同的選項參數值)," +"請參閱\\ :ref:`choosing-an-argument-parser`\\ 以了解替代方案。" #: ../../library/argparse.rst:-1 msgid "Tutorial" @@ -1438,13 +1438,14 @@ msgstr "" "PROG: error: the following arguments are required: bar" #: ../../library/argparse.rst:731 +#, fuzzy msgid "" "By default, :mod:`!argparse` automatically handles the internal naming and " "display names of arguments, simplifying the process without requiring " "additional configuration. As such, you do not need to specify the dest_ and " -"metavar_ parameters. The dest_ parameter defaults to the argument name with " -"underscores ``_`` replacing hyphens ``-`` . The metavar_ parameter defaults " -"to the upper-cased name. For example::" +"metavar_ parameters. For optional arguments, the dest_ parameter defaults to " +"the argument name, with underscores ``_`` replacing hyphens ``-``. The " +"metavar_ parameter defaults to the upper-cased name. For example::" msgstr "" "預設情況下,:mod:`!argparse` 會自動處理引數的內部命名和顯示名稱,簡化流程而不" "需要額外設定。因此,你不需要指定 dest_ 和 metavar_ 參數。dest_ 參數預設為引數" diff --git a/library/bisect.po b/library/bisect.po index d238adae3e4..d0fb58c5f13 100644 --- a/library/bisect.po +++ b/library/bisect.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-07 00:19+0000\n" +"POT-Creation-Date: 2026-03-01 00:20+0000\n" "PO-Revision-Date: 2023-08-01 12:53+0800\n" "Last-Translator: Matt Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -51,9 +51,9 @@ msgid "" "functions only call the :meth:`~object.__lt__` method and will return an " "insertion point between values in an array." msgstr "" -"這個模組被稱為 :mod:`!bisect` 是因為它使用基本二分演算法來完成其工作。不像其它" -"搜尋特定值的二分法工具,本模組中的函式旨在定位插入點。因此,這些函式永遠不會" -"呼叫 :meth:`~object.__eq__` 方法來確認是否找到一個值。相反地,這些函式只呼" +"這個模組被稱為 :mod:`!bisect` 是因為它使用基本二分演算法來完成其工作。不像其" +"它搜尋特定值的二分法工具,本模組中的函式旨在定位插入點。因此,這些函式永遠不" +"會呼叫 :meth:`~object.__eq__` 方法來確認是否找到一個值。相反地,這些函式只呼" "叫 :meth:`~object.__lt__` 方法,並在陣列中的值回傳一個插入點。" #: ../../library/bisect.rst:29 @@ -314,10 +314,11 @@ msgstr "" "績找到相對應的字母等級:90 以上是 'A'、80 到 89 為 'B',依此類推: ::" #: ../../library/bisect.rst:206 +#, fuzzy msgid "" -">>> def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'):\n" -"... i = bisect(breakpoints, score)\n" -"... return grades[i]\n" +">>> def grade(score)\n" +"... i = bisect([60, 70, 80, 90], score)\n" +"... return \"FDCBA\"[i]\n" "...\n" ">>> [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]\n" "['F', 'A', 'C', 'C', 'B', 'A', 'A']" diff --git a/library/concurrent.futures.po b/library/concurrent.futures.po index 92cf8575257..430009d2678 100644 --- a/library/concurrent.futures.po +++ b/library/concurrent.futures.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-07 00:19+0000\n" +"POT-Creation-Date: 2026-03-10 00:17+0000\n" "PO-Revision-Date: 2023-01-24 03:33+0800\n" "Last-Translator: Matt Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -301,6 +301,7 @@ msgid "And::" msgstr "和: ::" #: ../../library/concurrent.futures.rst:152 +#, fuzzy msgid "" "def wait_on_future():\n" " f = executor.submit(pow, 5, 2)\n" @@ -309,7 +310,9 @@ msgid "" " print(f.result())\n" "\n" "executor = ThreadPoolExecutor(max_workers=1)\n" -"executor.submit(wait_on_future)" +"future = executor.submit(wait_on_future)\n" +"# Note: calling future.result() would also cause a deadlock because\n" +"# the single worker thread is already waiting for wait_on_future()." msgstr "" "def wait_on_future():\n" " f = executor.submit(pow, 5, 2)\n" @@ -320,7 +323,7 @@ msgstr "" "executor = ThreadPoolExecutor(max_workers=1)\n" "executor.submit(wait_on_future)" -#: ../../library/concurrent.futures.rst:164 +#: ../../library/concurrent.futures.rst:166 msgid "" "An :class:`Executor` subclass that uses a pool of at most *max_workers* " "threads to execute calls asynchronously." @@ -328,7 +331,7 @@ msgstr "" "一個 :class:`Executor` 子類別,它使用最多有 *max_workers* 個執行緒的池來非同" "步地執行呼叫。" -#: ../../library/concurrent.futures.rst:167 +#: ../../library/concurrent.futures.rst:169 msgid "" "All threads enqueued to ``ThreadPoolExecutor`` will be joined before the " "interpreter can exit. Note that the exit handler which does this is executed " @@ -343,7 +346,7 @@ msgstr "" "退出 (gracefully exit)。因此,建議不要將 ``ThreadPoolExecutor`` 用於長時間運" "行的任務。" -#: ../../library/concurrent.futures.rst:174 +#: ../../library/concurrent.futures.rst:176 msgid "" "*initializer* is an optional callable that is called at the start of each " "worker thread; *initargs* is a tuple of arguments passed to the " @@ -356,7 +359,7 @@ msgstr "" "外,所有目前未定的作業以及任何向池中提交 (submit) 更多作業的嘗試都將引發 :" "exc:`~concurrent.futures.thread.BrokenThreadPool`。" -#: ../../library/concurrent.futures.rst:180 +#: ../../library/concurrent.futures.rst:182 msgid "" "If *max_workers* is ``None`` or not given, it will default to the number of " "processors on the machine, multiplied by ``5``, assuming that :class:" @@ -369,7 +372,7 @@ msgstr "" "作業,並且 worker 的數量應該高於 :class:`ProcessPoolExecutor` 的 worker 數" "量。" -#: ../../library/concurrent.futures.rst:188 +#: ../../library/concurrent.futures.rst:190 msgid "" "Added the *thread_name_prefix* parameter to allow users to control the :" "class:`threading.Thread` names for worker threads created by the pool for " @@ -378,12 +381,12 @@ msgstr "" "新增 *thread_name_prefix* 參數以允許使用者控制由池所建立的工作執行緒 (worker " "thread) 的 :class:`threading.Thread` 名稱,以便於除錯。" -#: ../../library/concurrent.futures.rst:193 -#: ../../library/concurrent.futures.rst:403 +#: ../../library/concurrent.futures.rst:195 +#: ../../library/concurrent.futures.rst:405 msgid "Added the *initializer* and *initargs* arguments." msgstr "新增 *initializer* 與 *initargs* 引數。" -#: ../../library/concurrent.futures.rst:196 +#: ../../library/concurrent.futures.rst:198 msgid "" "Default value of *max_workers* is changed to ``min(32, os.cpu_count() + " "4)``. This default value preserves at least 5 workers for I/O bound tasks. " @@ -394,7 +397,7 @@ msgstr "" "集任務至少保留了 5 個 worker。它最多使用 32 個 CPU 核心來執行CPU 密集任務,以" "釋放 GIL。並且它避免了在多核機器上隱晦地使用非常大量的資源。" -#: ../../library/concurrent.futures.rst:202 +#: ../../library/concurrent.futures.rst:204 msgid "" "ThreadPoolExecutor now reuses idle worker threads before starting " "*max_workers* worker threads too." @@ -402,18 +405,18 @@ msgstr "" "ThreadPoolExecutor 現在在啟動 *max_workers* 工作執行緒之前會重用 (reuse) 空閒" "的工作執行緒。" -#: ../../library/concurrent.futures.rst:205 +#: ../../library/concurrent.futures.rst:207 msgid "" "Default value of *max_workers* is changed to ``min(32, (os." "process_cpu_count() or 1) + 4)``." msgstr "" "*max_workers* 的預設值被改為 ``min(32, (os.process_cpu_count() or 1) + 4)``。" -#: ../../library/concurrent.futures.rst:213 +#: ../../library/concurrent.futures.rst:215 msgid "ThreadPoolExecutor Example" msgstr "ThreadPoolExecutor 範例" -#: ../../library/concurrent.futures.rst:216 +#: ../../library/concurrent.futures.rst:218 msgid "" "import concurrent.futures\n" "import urllib.request\n" @@ -444,11 +447,11 @@ msgid "" " print('%r page is %d bytes' % (url, len(data)))" msgstr "" -#: ../../library/concurrent.futures.rst:245 +#: ../../library/concurrent.futures.rst:247 msgid "InterpreterPoolExecutor" msgstr "InterpreterPoolExecutor" -#: ../../library/concurrent.futures.rst:249 +#: ../../library/concurrent.futures.rst:251 msgid "" "The :class:`InterpreterPoolExecutor` class uses a pool of interpreters to " "execute calls asynchronously. It is a :class:`ThreadPoolExecutor` subclass, " @@ -457,7 +460,7 @@ msgid "" "interpreter." msgstr "" -#: ../../library/concurrent.futures.rst:255 +#: ../../library/concurrent.futures.rst:257 msgid "" "The biggest benefit to using interpreters instead of only threads is true " "multi-core parallelism. Each interpreter has its own :term:`Global " @@ -466,7 +469,7 @@ msgid "" "unblocked on a different core." msgstr "" -#: ../../library/concurrent.futures.rst:261 +#: ../../library/concurrent.futures.rst:263 msgid "" "The tradeoff is that writing concurrent code for use with multiple " "interpreters can take extra effort. However, this is because it forces you " @@ -479,7 +482,7 @@ msgid "" "conditions." msgstr "" -#: ../../library/concurrent.futures.rst:271 +#: ../../library/concurrent.futures.rst:273 msgid "" "Each worker's interpreter is isolated from all the other interpreters. " "\"Isolated\" means each interpreter has its own runtime state and operates " @@ -493,7 +496,7 @@ msgid "" "``__main__``." msgstr "" -#: ../../library/concurrent.futures.rst:283 +#: ../../library/concurrent.futures.rst:285 msgid "" "Isolation means a mutable object, or other data, cannot be used by more than " "one interpreter at the same time. That effectively means interpreters " @@ -503,7 +506,7 @@ msgid "" "strings, and tuples of immutable objects, don't have these limitations." msgstr "" -#: ../../library/concurrent.futures.rst:291 +#: ../../library/concurrent.futures.rst:293 msgid "" "Communicating and synchronizing between interpreters is most effectively " "done using dedicated tools, like those proposed in :pep:`734`. One less " @@ -511,7 +514,7 @@ msgid "" "bytes over a shared :mod:`socket ` or :func:`pipe `." msgstr "" -#: ../../library/concurrent.futures.rst:299 +#: ../../library/concurrent.futures.rst:301 msgid "" "A :class:`ThreadPoolExecutor` subclass that executes calls asynchronously " "using a pool of at most *max_workers* threads. Each thread runs tasks in " @@ -522,7 +525,7 @@ msgid "" "executor has true multi-core parallelism." msgstr "" -#: ../../library/concurrent.futures.rst:307 +#: ../../library/concurrent.futures.rst:309 msgid "" "The optional *initializer* and *initargs* arguments have the same meaning as " "for :class:`!ThreadPoolExecutor`: the initializer is run when each worker is " @@ -531,17 +534,17 @@ msgid "" "when sending them to the worker's interpreter." msgstr "" -#: ../../library/concurrent.futures.rst:315 +#: ../../library/concurrent.futures.rst:317 msgid "" "The executor may replace uncaught exceptions from *initializer* with :class:" "`~concurrent.interpreters.ExecutionFailed`." msgstr "" -#: ../../library/concurrent.futures.rst:318 +#: ../../library/concurrent.futures.rst:320 msgid "Other caveats from parent :class:`ThreadPoolExecutor` apply here." msgstr "" -#: ../../library/concurrent.futures.rst:320 +#: ../../library/concurrent.futures.rst:322 msgid "" ":meth:`~Executor.submit` and :meth:`~Executor.map` work like normal, except " "the worker serializes the callable and arguments using :mod:`pickle` when " @@ -549,7 +552,7 @@ msgid "" "value when sending it back." msgstr "" -#: ../../library/concurrent.futures.rst:325 +#: ../../library/concurrent.futures.rst:327 msgid "" "When a worker's current task raises an uncaught exception, the worker always " "tries to preserve the exception as-is. If that is successful then it also " @@ -560,11 +563,11 @@ msgid "" "`~concurrent.interpreters.ExecutionFailed` instance instead." msgstr "" -#: ../../library/concurrent.futures.rst:337 +#: ../../library/concurrent.futures.rst:339 msgid "ProcessPoolExecutor" msgstr "ProcessPoolExecutor" -#: ../../library/concurrent.futures.rst:339 +#: ../../library/concurrent.futures.rst:341 msgid "" "The :class:`ProcessPoolExecutor` class is an :class:`Executor` subclass that " "uses a pool of processes to execute calls asynchronously. :class:" @@ -579,7 +582,7 @@ msgstr "" "Interpreter Lock) `,但也意味著只能執行和回傳可被 " "pickle 的 (picklable) 物件。" -#: ../../library/concurrent.futures.rst:346 +#: ../../library/concurrent.futures.rst:348 msgid "" "The ``__main__`` module must be importable by worker subprocesses. This " "means that :class:`ProcessPoolExecutor` will not work in the interactive " @@ -589,7 +592,7 @@ msgstr "" "class:`ProcessPoolExecutor` 將無法在交互式直譯器 (interactive interpreter) 中" "工作。" -#: ../../library/concurrent.futures.rst:349 +#: ../../library/concurrent.futures.rst:351 msgid "" "Calling :class:`Executor` or :class:`Future` methods from a callable " "submitted to a :class:`ProcessPoolExecutor` will result in deadlock." @@ -597,7 +600,7 @@ msgstr "" "從提交給 :class:`ProcessPoolExecutor` 的可呼叫物件中呼叫 :class:`Executor` " "或 :class:`Future` 方法將導致死鎖。" -#: ../../library/concurrent.futures.rst:352 +#: ../../library/concurrent.futures.rst:354 msgid "" "Note that the restrictions on functions and arguments needing to picklable " "as per :class:`multiprocessing.Process` apply when using :meth:`~Executor." @@ -605,7 +608,7 @@ msgid "" "function defined in a REPL or a lambda should not be expected to work." msgstr "" -#: ../../library/concurrent.futures.rst:359 +#: ../../library/concurrent.futures.rst:361 msgid "" "An :class:`Executor` subclass that executes calls asynchronously using a " "pool of at most *max_workers* processes. If *max_workers* is ``None`` or " @@ -629,7 +632,7 @@ msgstr "" "或未給定,則使用預設的 :mod:`multiprocessing` 情境。請見 :ref:" "`multiprocessing-start-methods`。" -#: ../../library/concurrent.futures.rst:373 +#: ../../library/concurrent.futures.rst:375 msgid "" "*initializer* is an optional callable that is called at the start of each " "worker process; *initargs* is a tuple of arguments passed to the " @@ -642,7 +645,7 @@ msgstr "" "外,所有目前未定的作業以及任何向池中提交更多作業的嘗試都將引發 :exc:" "`~concurrent.futures.process.BrokenProcessPool`。" -#: ../../library/concurrent.futures.rst:379 +#: ../../library/concurrent.futures.rst:381 msgid "" "*max_tasks_per_child* is an optional argument that specifies the maximum " "number of tasks a single process can execute before it will exit and be " @@ -658,14 +661,14 @@ msgstr "" "數的情況下,將預設使用 \"spawn\" 做為 multiprocessing 啟動方法。此功能與 " "\"fork\" 啟動方法不相容。" -#: ../../library/concurrent.futures.rst:388 +#: ../../library/concurrent.futures.rst:390 msgid "" "Bugs have been reported when using the *max_tasks_per_child* feature that " "can result in the :class:`ProcessPoolExecutor` hanging in some " "circumstances. Follow its eventual resolution in :gh:`115634`." msgstr "" -#: ../../library/concurrent.futures.rst:392 +#: ../../library/concurrent.futures.rst:394 msgid "" "When one of the worker processes terminates abruptly, a :exc:`~concurrent." "futures.process.BrokenProcessPool` error is now raised. Previously, " @@ -676,21 +679,21 @@ msgstr "" "BrokenProcessPool` 錯誤。在過去,此行為是未定義的 (undefined),但對 executor " "或其 future 的操作經常會發生凍結或死鎖。" -#: ../../library/concurrent.futures.rst:399 +#: ../../library/concurrent.futures.rst:401 msgid "" "The *mp_context* argument was added to allow users to control the " "start_method for worker processes created by the pool." msgstr "" "新增了 *mp_context* 引數以允許使用者控制由池所建立的工作行程的 start_method。" -#: ../../library/concurrent.futures.rst:405 +#: ../../library/concurrent.futures.rst:407 msgid "" "The *max_tasks_per_child* argument was added to allow users to control the " "lifetime of workers in the pool." msgstr "" "新增了 *max_tasks_per_child* 引數以允許使用者控制池中 worker 的生命週期。" -#: ../../library/concurrent.futures.rst:409 +#: ../../library/concurrent.futures.rst:411 msgid "" "On POSIX systems, if your application has multiple threads and the :mod:" "`multiprocessing` context uses the ``\"fork\"`` start method: The :func:`os." @@ -703,13 +706,13 @@ msgstr "" "能會引發 :exc:`DeprecationWarning`。傳遞一個 *mp_context* 以配置為使用不同的" "啟動方法。更多說明請參閱 :func:`os.fork` 文件。" -#: ../../library/concurrent.futures.rst:417 +#: ../../library/concurrent.futures.rst:419 msgid "" "*max_workers* uses :func:`os.process_cpu_count` by default, instead of :func:" "`os.cpu_count`." msgstr "" -#: ../../library/concurrent.futures.rst:421 +#: ../../library/concurrent.futures.rst:423 msgid "" "The default process start method (see :ref:`multiprocessing-start-methods`) " "changed away from *fork*. If you require the *fork* start method for :class:" @@ -717,7 +720,7 @@ msgid "" "get_context(\"fork\")``." msgstr "" -#: ../../library/concurrent.futures.rst:429 +#: ../../library/concurrent.futures.rst:431 msgid "" "Attempt to terminate all living worker processes immediately by calling :" "meth:`Process.terminate ` on each of " @@ -725,14 +728,14 @@ msgid "" "all other resources associated with the executor are freed." msgstr "" -#: ../../library/concurrent.futures.rst:434 -#: ../../library/concurrent.futures.rst:446 +#: ../../library/concurrent.futures.rst:436 +#: ../../library/concurrent.futures.rst:448 msgid "" "After calling this method the caller should no longer submit tasks to the " "executor." msgstr "" -#: ../../library/concurrent.futures.rst:441 +#: ../../library/concurrent.futures.rst:443 msgid "" "Attempt to kill all living worker processes immediately by calling :meth:" "`Process.kill ` on each of them. Internally, " @@ -740,11 +743,11 @@ msgid "" "resources associated with the executor are freed." msgstr "" -#: ../../library/concurrent.futures.rst:454 +#: ../../library/concurrent.futures.rst:456 msgid "ProcessPoolExecutor Example" msgstr "ProcessPoolExecutor 範例" -#: ../../library/concurrent.futures.rst:457 +#: ../../library/concurrent.futures.rst:459 msgid "" "import concurrent.futures\n" "import math\n" @@ -812,11 +815,11 @@ msgstr "" "if __name__ == '__main__':\n" " main()" -#: ../../library/concurrent.futures.rst:492 +#: ../../library/concurrent.futures.rst:494 msgid "Future Objects" msgstr "Future 物件" -#: ../../library/concurrent.futures.rst:494 +#: ../../library/concurrent.futures.rst:496 msgid "" "The :class:`Future` class encapsulates the asynchronous execution of a " "callable. :class:`Future` instances are created by :meth:`Executor.submit`." @@ -824,7 +827,7 @@ msgstr "" ":class:`Future` 類別封裝了可呼叫物件的非同步執行。:class:`Future` 實例由 :" "meth:`Executor.submit` 建立。" -#: ../../library/concurrent.futures.rst:499 +#: ../../library/concurrent.futures.rst:501 msgid "" "Encapsulates the asynchronous execution of a callable. :class:`Future` " "instances are created by :meth:`Executor.submit` and should not be created " @@ -833,7 +836,7 @@ msgstr "" "封裝可呼叫物件的非同步執行。:class:`Future` 實例由 :meth:`Executor.submit` 建" "立,且除測試外不應直接建立。" -#: ../../library/concurrent.futures.rst:505 +#: ../../library/concurrent.futures.rst:507 msgid "" "Attempt to cancel the call. If the call is currently being executed or " "finished running and cannot be cancelled then the method will return " @@ -843,22 +846,22 @@ msgstr "" "嘗試取消呼叫。如果呼叫目前正在執行或已完成運行且無法取消,則該方法將回傳 " "``False``,否則呼叫將被取消並且該方法將回傳 ``True``。" -#: ../../library/concurrent.futures.rst:512 +#: ../../library/concurrent.futures.rst:514 msgid "Return ``True`` if the call was successfully cancelled." msgstr "如果該呼叫成功被取消,則回傳 ``True``。" -#: ../../library/concurrent.futures.rst:516 +#: ../../library/concurrent.futures.rst:518 msgid "" "Return ``True`` if the call is currently being executed and cannot be " "cancelled." msgstr "如果呼叫正在執行且無法取消,則回傳 ``True``。" -#: ../../library/concurrent.futures.rst:521 +#: ../../library/concurrent.futures.rst:523 msgid "" "Return ``True`` if the call was successfully cancelled or finished running." msgstr "如果呼叫成功被取消或結束運行,則回傳 ``True``。" -#: ../../library/concurrent.futures.rst:526 +#: ../../library/concurrent.futures.rst:528 msgid "" "Return the value returned by the call. If the call hasn't yet completed then " "this method will wait up to *timeout* seconds. If the call hasn't completed " @@ -870,19 +873,19 @@ msgstr "" "叫在 *timeout* 秒內未完成,則會引發 :exc:`TimeoutError`。*timeout* 可以是整數" "或浮點數。如果未指定 *timeout* 或為 ``None``,則等待時間就不會有限制。" -#: ../../library/concurrent.futures.rst:533 -#: ../../library/concurrent.futures.rst:547 +#: ../../library/concurrent.futures.rst:535 +#: ../../library/concurrent.futures.rst:549 msgid "" "If the future is cancelled before completing then :exc:`.CancelledError` " "will be raised." msgstr "如果 future 在完成之前被取消,那麼 :exc:`.CancelledError` 將被引發。" -#: ../../library/concurrent.futures.rst:536 +#: ../../library/concurrent.futures.rst:538 msgid "" "If the call raised an exception, this method will raise the same exception." msgstr "如果該呼叫引發了例外,此方法將引發相同的例外。" -#: ../../library/concurrent.futures.rst:540 +#: ../../library/concurrent.futures.rst:542 msgid "" "Return the exception raised by the call. If the call hasn't yet completed " "then this method will wait up to *timeout* seconds. If the call hasn't " @@ -894,11 +897,11 @@ msgstr "" "呼叫在 *timeout* 秒內未完成,則會引發 :exc:`TimeoutError`。 *timeout* 可以是" "整數或浮點數。如果未指定 *timeout* 或為 ``None``,則等待時間就不會有限制。" -#: ../../library/concurrent.futures.rst:550 +#: ../../library/concurrent.futures.rst:552 msgid "If the call completed without raising, ``None`` is returned." msgstr "如果呼叫在沒有引發的情況下完成,則回傳 ``None``。" -#: ../../library/concurrent.futures.rst:554 +#: ../../library/concurrent.futures.rst:556 msgid "" "Attaches the callable *fn* to the future. *fn* will be called, with the " "future as its only argument, when the future is cancelled or finishes " @@ -907,7 +910,7 @@ msgstr "" "將可呼叫的 *fn* 附加到 future 上。當 future 被取消或完成運行時,*fn* 將被以 " "future 作為其唯一引數來呼叫。" -#: ../../library/concurrent.futures.rst:558 +#: ../../library/concurrent.futures.rst:560 msgid "" "Added callables are called in the order that they were added and are always " "called in a thread belonging to the process that added them. If the " @@ -919,19 +922,19 @@ msgstr "" "如果可呼叫物件引發 :exc:`Exception` 子類別,它將被記錄 (log) 並忽略。如果可呼" "叫物件引發 :exc:`BaseException` 子類別,該行為未定義。" -#: ../../library/concurrent.futures.rst:564 +#: ../../library/concurrent.futures.rst:566 msgid "" "If the future has already completed or been cancelled, *fn* will be called " "immediately." msgstr "如果 future 已經完成或被取消,*fn* 將立即被呼叫。" -#: ../../library/concurrent.futures.rst:567 +#: ../../library/concurrent.futures.rst:569 msgid "" "The following :class:`Future` methods are meant for use in unit tests and :" "class:`Executor` implementations." msgstr "以下 :class:`Future` 方法旨在用於單元測試和 :class:`Executor` 實作。" -#: ../../library/concurrent.futures.rst:572 +#: ../../library/concurrent.futures.rst:574 msgid "" "This method should only be called by :class:`Executor` implementations " "before executing the work associated with the :class:`Future` and by unit " @@ -940,7 +943,7 @@ msgstr "" "此方法只能在與 :class:`Future` 關聯的工作被執行之前於 :class:`Executor` 實作" "中呼叫,或者在單元測試中呼叫。" -#: ../../library/concurrent.futures.rst:576 +#: ../../library/concurrent.futures.rst:578 msgid "" "If the method returns ``False`` then the :class:`Future` was cancelled, i." "e. :meth:`Future.cancel` was called and returned ``True``. Any threads " @@ -951,7 +954,7 @@ msgstr "" "cancel` 被呼叫並回傳 ``True``。任何等待 :class:`Future` 完成的執行緒(即透" "過 :func:`as_completed` 或 :func:`wait`)將被喚醒。" -#: ../../library/concurrent.futures.rst:581 +#: ../../library/concurrent.futures.rst:583 msgid "" "If the method returns ``True`` then the :class:`Future` was not cancelled " "and has been put in the running state, i.e. calls to :meth:`Future.running` " @@ -960,7 +963,7 @@ msgstr "" "如果該方法回傳 ``True`` 則代表 :class:`Future` 未被取消並已進入運行狀態,意即" "呼叫 :meth:`Future.running` 將回傳 ``True``。" -#: ../../library/concurrent.futures.rst:585 +#: ../../library/concurrent.futures.rst:587 msgid "" "This method can only be called once and cannot be called after :meth:`Future." "set_result` or :meth:`Future.set_exception` have been called." @@ -968,20 +971,20 @@ msgstr "" "此方法只能呼叫一次,且不能在呼叫 :meth:`Future.set_result` 或 :meth:`Future." "set_exception` 之後呼叫。" -#: ../../library/concurrent.futures.rst:591 +#: ../../library/concurrent.futures.rst:593 msgid "" "Sets the result of the work associated with the :class:`Future` to *result*." msgstr "將與 :class:`Future` 關聯的工作結果設定為 *result*。" -#: ../../library/concurrent.futures.rst:594 -#: ../../library/concurrent.futures.rst:607 +#: ../../library/concurrent.futures.rst:596 +#: ../../library/concurrent.futures.rst:609 msgid "" "This method should only be used by :class:`Executor` implementations and " "unit tests." msgstr "此方法只能在 :class:`Executor` 實作中和單元測試中使用。" -#: ../../library/concurrent.futures.rst:597 -#: ../../library/concurrent.futures.rst:610 +#: ../../library/concurrent.futures.rst:599 +#: ../../library/concurrent.futures.rst:612 msgid "" "This method raises :exc:`concurrent.futures.InvalidStateError` if the :class:" "`Future` is already done." @@ -989,18 +992,18 @@ msgstr "" "如果 :class:`Future` 已經完成,此方法會引發 :exc:`concurrent.futures." "InvalidStateError`。" -#: ../../library/concurrent.futures.rst:604 +#: ../../library/concurrent.futures.rst:606 msgid "" "Sets the result of the work associated with the :class:`Future` to the :" "class:`Exception` *exception*." msgstr "" "將與 :class:`Future` 關聯的工作結果設定為 :class:`Exception` *exception*。" -#: ../../library/concurrent.futures.rst:616 +#: ../../library/concurrent.futures.rst:618 msgid "Module Functions" msgstr "模組函式" -#: ../../library/concurrent.futures.rst:620 +#: ../../library/concurrent.futures.rst:622 msgid "" "Wait for the :class:`Future` instances (possibly created by different :class:" "`Executor` instances) given by *fs* to complete. Duplicate futures given to " @@ -1016,7 +1019,7 @@ msgstr "" "完成的 future(已完成或被取消的 future)。第二組名為 ``not_done``,包含未完成" "的 future(未定或運行中的 future)。" -#: ../../library/concurrent.futures.rst:628 +#: ../../library/concurrent.futures.rst:630 msgid "" "*timeout* can be used to control the maximum number of seconds to wait " "before returning. *timeout* can be an int or float. If *timeout* is not " @@ -1025,25 +1028,25 @@ msgstr "" "*timeout* 可用於控制回傳前等待的最大秒數。*timeout* 可以是整數或浮點數。如果" "未指定 *timeout* 或為 ``None``,則等待時間就沒有限制。" -#: ../../library/concurrent.futures.rst:632 +#: ../../library/concurrent.futures.rst:634 msgid "" "*return_when* indicates when this function should return. It must be one of " "the following constants:" msgstr "*return_when* 表示此函式應回傳的時間。它必須是以下常數之一:" -#: ../../library/concurrent.futures.rst:638 +#: ../../library/concurrent.futures.rst:640 msgid "Constant" msgstr "常數" -#: ../../library/concurrent.futures.rst:639 +#: ../../library/concurrent.futures.rst:641 msgid "Description" msgstr "描述" -#: ../../library/concurrent.futures.rst:642 +#: ../../library/concurrent.futures.rst:644 msgid "The function will return when any future finishes or is cancelled." msgstr "當任何 future 完成或被取消時,該函式就會回傳。" -#: ../../library/concurrent.futures.rst:645 +#: ../../library/concurrent.futures.rst:647 msgid "" "The function will return when any future finishes by raising an exception. " "If no future raises an exception then it is equivalent to :const:" @@ -1052,11 +1055,11 @@ msgstr "" "該函式會在任何 future 透過引發例外而完結時回傳。如果 future 沒有引發例外,那" "麼它等同於 :const:`ALL_COMPLETED`。" -#: ../../library/concurrent.futures.rst:650 +#: ../../library/concurrent.futures.rst:652 msgid "The function will return when all futures finish or are cancelled." msgstr "當所有 future 都完成或被取消時,該函式才會回傳。" -#: ../../library/concurrent.futures.rst:654 +#: ../../library/concurrent.futures.rst:656 msgid "" "Returns an iterator over the :class:`Future` instances (possibly created by " "different :class:`Executor` instances) given by *fs* that yields futures as " @@ -1076,36 +1079,36 @@ msgstr "" "`TimeoutError`。*timeout* 可以是整數或浮點數。如果未指定 *timeout* 或為 " "``None``,則等待時間就沒有限制。" -#: ../../library/concurrent.futures.rst:667 +#: ../../library/concurrent.futures.rst:669 msgid ":pep:`3148` -- futures - execute computations asynchronously" msgstr ":pep:`3148` -- futures - 非同步地執行運算" -#: ../../library/concurrent.futures.rst:668 +#: ../../library/concurrent.futures.rst:670 msgid "" "The proposal which described this feature for inclusion in the Python " "standard library." msgstr "描述此功能並提出被包含於 Python 標準函式庫中的提案。" -#: ../../library/concurrent.futures.rst:673 +#: ../../library/concurrent.futures.rst:675 msgid "Exception classes" msgstr "例外類別" -#: ../../library/concurrent.futures.rst:679 +#: ../../library/concurrent.futures.rst:681 msgid "Raised when a future is cancelled." msgstr "當 future 被取消時引發。" -#: ../../library/concurrent.futures.rst:683 +#: ../../library/concurrent.futures.rst:685 msgid "" "A deprecated alias of :exc:`TimeoutError`, raised when a future operation " "exceeds the given timeout." msgstr "" ":exc:`TimeoutError` 的棄用別名,在 future 操作超過給定超時 (timeout) 時引發。" -#: ../../library/concurrent.futures.rst:688 +#: ../../library/concurrent.futures.rst:690 msgid "This class was made an alias of :exc:`TimeoutError`." msgstr "這個類別是 :exc:`TimeoutError` 的別名。" -#: ../../library/concurrent.futures.rst:693 +#: ../../library/concurrent.futures.rst:695 msgid "" "Derived from :exc:`RuntimeError`, this exception class is raised when an " "executor is broken for some reason, and cannot be used to submit or execute " @@ -1114,13 +1117,13 @@ msgstr "" "衍生自 :exc:`RuntimeError`,當執行器因某種原因損壞時會引發此例外類別,並且不" "能用於提交或執行新任務。" -#: ../../library/concurrent.futures.rst:701 +#: ../../library/concurrent.futures.rst:703 msgid "" "Raised when an operation is performed on a future that is not allowed in the " "current state." msgstr "目前狀態下不允許的 future 操作被執行時而引發。" -#: ../../library/concurrent.futures.rst:710 +#: ../../library/concurrent.futures.rst:712 msgid "" "Derived from :exc:`~concurrent.futures.BrokenExecutor`, this exception class " "is raised when one of the workers of a :class:`~concurrent.futures." @@ -1129,7 +1132,7 @@ msgstr "" "衍生自 :exc:`~concurrent.futures.BrokenExecutor`,當 :class:`~concurrent." "futures.ThreadPoolExecutor` 的其中一個 worker 初始化失敗時會引發此例外類別。" -#: ../../library/concurrent.futures.rst:721 +#: ../../library/concurrent.futures.rst:723 msgid "" "Derived from :exc:`~concurrent.futures.thread.BrokenThreadPool`, this " "exception class is raised when one of the workers of a :class:`~concurrent." @@ -1139,7 +1142,7 @@ msgstr "" "`~concurrent.futures.InterpreterPoolExecutor` 的其中一個 worker 初始化失敗時" "會引發此例外類別。" -#: ../../library/concurrent.futures.rst:732 +#: ../../library/concurrent.futures.rst:734 msgid "" "Derived from :exc:`~concurrent.futures.BrokenExecutor` (formerly :exc:" "`RuntimeError`), this exception class is raised when one of the workers of " diff --git a/library/contextlib.po b/library/contextlib.po index 0ddd017f211..e611fc6268f 100644 --- a/library/contextlib.po +++ b/library/contextlib.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-07 00:19+0000\n" +"POT-Creation-Date: 2026-03-03 00:19+0000\n" "PO-Revision-Date: 2018-05-23 14:41+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -43,20 +43,20 @@ msgstr "" #: ../../library/contextlib.rst:23 msgid "" -"An :term:`abstract base class` for classes that implement :meth:`object." -"__enter__` and :meth:`object.__exit__`. A default implementation for :meth:" -"`object.__enter__` is provided which returns ``self`` while :meth:`object." +"An :term:`abstract base class` for classes that implement :meth:`~object." +"__enter__` and :meth:`~object.__exit__`. A default implementation for :meth:" +"`~object.__enter__` is provided which returns ``self`` while :meth:`~object." "__exit__` is an abstract method which by default returns ``None``. See also " "the definition of :ref:`typecontextmanager`." msgstr "" #: ../../library/contextlib.rst:34 msgid "" -"An :term:`abstract base class` for classes that implement :meth:`object." -"__aenter__` and :meth:`object.__aexit__`. A default implementation for :meth:" -"`object.__aenter__` is provided which returns ``self`` while :meth:`object." -"__aexit__` is an abstract method which by default returns ``None``. See also " -"the definition of :ref:`async-context-managers`." +"An :term:`abstract base class` for classes that implement :meth:`~object." +"__aenter__` and :meth:`~object.__aexit__`. A default implementation for :" +"meth:`~object.__aenter__` is provided which returns ``self`` while :meth:" +"`~object.__aexit__` is an abstract method which by default returns ``None``. " +"See also the definition of :ref:`async-context-managers`." msgstr "" #: ../../library/contextlib.rst:46 @@ -352,9 +352,9 @@ msgstr "" #: ../../library/contextlib.rst:231 msgid "" -"Return a context manager that returns *enter_result* from ``__enter__``, but " -"otherwise does nothing. It is intended to be used as a stand-in for an " -"optional context manager, for example::" +"Return a context manager that returns *enter_result* from :meth:`~object." +"__enter__`, but otherwise does nothing. It is intended to be used as a stand-" +"in for an optional context manager, for example::" msgstr "" #: ../../library/contextlib.rst:235 @@ -512,9 +512,9 @@ msgstr "" msgid "" "For example, the output of :func:`help` normally is sent to *sys.stdout*. " "You can capture that output in a string by redirecting the output to an :" -"class:`io.StringIO` object. The replacement stream is returned from the " -"``__enter__`` method and so is available as the target of the :keyword:" -"`with` statement::" +"class:`io.StringIO` object. The replacement stream is returned from the :" +"meth:`~object.__enter__` method and so is available as the target of the :" +"keyword:`with` statement::" msgstr "" #: ../../library/contextlib.rst:341 @@ -592,22 +592,23 @@ msgstr "" #: ../../library/contextlib.rst:398 msgid "" -"Context managers inheriting from ``ContextDecorator`` have to implement " -"``__enter__`` and ``__exit__`` as normal. ``__exit__`` retains its optional " -"exception handling even when used as a decorator." +"Context managers inheriting from ``ContextDecorator`` have to implement :" +"meth:`~object.__enter__` and :meth:`~object.__exit__` as normal. " +"``__exit__`` retains its optional exception handling even when used as a " +"decorator." msgstr "" -#: ../../library/contextlib.rst:402 +#: ../../library/contextlib.rst:403 msgid "" "``ContextDecorator`` is used by :func:`contextmanager`, so you get this " "functionality automatically." msgstr "" -#: ../../library/contextlib.rst:405 +#: ../../library/contextlib.rst:406 msgid "Example of ``ContextDecorator``::" msgstr "``ContextDecorator`` 範例: ::" -#: ../../library/contextlib.rst:407 +#: ../../library/contextlib.rst:408 msgid "" "from contextlib import ContextDecorator\n" "\n" @@ -631,11 +632,11 @@ msgstr "" " print('Finishing')\n" " return False" -#: ../../library/contextlib.rst:418 ../../library/contextlib.rst:490 +#: ../../library/contextlib.rst:419 ../../library/contextlib.rst:491 msgid "The class can then be used like this::" msgstr "這個類別可以這樣使用: ::" -#: ../../library/contextlib.rst:420 +#: ../../library/contextlib.rst:421 msgid "" ">>> @mycontext()\n" "... def function():\n" @@ -669,12 +670,12 @@ msgstr "" "The bit in the middle\n" "Finishing" -#: ../../library/contextlib.rst:436 +#: ../../library/contextlib.rst:437 msgid "" "This change is just syntactic sugar for any construct of the following form::" msgstr "這個變更只是以下形式的語法糖: ::" -#: ../../library/contextlib.rst:438 +#: ../../library/contextlib.rst:439 msgid "" "def f():\n" " with cm():\n" @@ -684,11 +685,11 @@ msgstr "" " with cm():\n" " # Do stuff" -#: ../../library/contextlib.rst:442 +#: ../../library/contextlib.rst:443 msgid "``ContextDecorator`` lets you instead write::" msgstr "``ContextDecorator`` 讓你可以改寫成: ::" -#: ../../library/contextlib.rst:444 +#: ../../library/contextlib.rst:445 msgid "" "@cm()\n" "def f():\n" @@ -698,19 +699,19 @@ msgstr "" "def f():\n" " # Do stuff" -#: ../../library/contextlib.rst:448 +#: ../../library/contextlib.rst:449 msgid "" "It makes it clear that the ``cm`` applies to the whole function, rather than " "just a piece of it (and saving an indentation level is nice, too)." msgstr "" -#: ../../library/contextlib.rst:451 +#: ../../library/contextlib.rst:452 msgid "" "Existing context managers that already have a base class can be extended by " "using ``ContextDecorator`` as a mixin class::" msgstr "" -#: ../../library/contextlib.rst:454 +#: ../../library/contextlib.rst:455 msgid "" "from contextlib import ContextDecorator\n" "\n" @@ -730,7 +731,7 @@ msgstr "" " def __exit__(self, *exc):\n" " return False" -#: ../../library/contextlib.rst:464 +#: ../../library/contextlib.rst:465 msgid "" "As the decorated function must be able to be called multiple times, the " "underlying context manager must support use in multiple :keyword:`with` " @@ -738,16 +739,16 @@ msgid "" "explicit :keyword:`!with` statement inside the function should be used." msgstr "" -#: ../../library/contextlib.rst:474 +#: ../../library/contextlib.rst:475 msgid "" "Similar to :class:`ContextDecorator` but only for asynchronous functions." msgstr "和 :class:`ContextDecorator` 類似,但僅用於非同步函式。" -#: ../../library/contextlib.rst:476 +#: ../../library/contextlib.rst:477 msgid "Example of ``AsyncContextDecorator``::" msgstr "``AsyncContextDecorator`` 範例: ::" -#: ../../library/contextlib.rst:478 +#: ../../library/contextlib.rst:479 msgid "" "from asyncio import run\n" "from contextlib import AsyncContextDecorator\n" @@ -773,7 +774,7 @@ msgstr "" " print('Finishing')\n" " return False" -#: ../../library/contextlib.rst:492 +#: ../../library/contextlib.rst:493 msgid "" ">>> @mycontext()\n" "... async def function():\n" @@ -811,20 +812,20 @@ msgstr "" "The bit in the middle\n" "Finishing" -#: ../../library/contextlib.rst:515 +#: ../../library/contextlib.rst:516 msgid "" "A context manager that is designed to make it easy to programmatically " "combine other context managers and cleanup functions, especially those that " "are optional or otherwise driven by input data." msgstr "" -#: ../../library/contextlib.rst:519 +#: ../../library/contextlib.rst:520 msgid "" "For example, a set of files may easily be handled in a single with statement " "as follows::" msgstr "" -#: ../../library/contextlib.rst:522 +#: ../../library/contextlib.rst:523 msgid "" "with ExitStack() as stack:\n" " files = [stack.enter_context(open(fname)) for fname in filenames]\n" @@ -833,13 +834,13 @@ msgid "" " # in the list raise an exception" msgstr "" -#: ../../library/contextlib.rst:528 +#: ../../library/contextlib.rst:529 msgid "" "The :meth:`~object.__enter__` method returns the :class:`ExitStack` " "instance, and performs no additional operations." msgstr "" -#: ../../library/contextlib.rst:531 +#: ../../library/contextlib.rst:532 msgid "" "Each instance maintains a stack of registered callbacks that are called in " "reverse order when the instance is closed (either explicitly or implicitly " @@ -847,14 +848,14 @@ msgid "" "invoked implicitly when the context stack instance is garbage collected." msgstr "" -#: ../../library/contextlib.rst:536 +#: ../../library/contextlib.rst:537 msgid "" "This stack model is used so that context managers that acquire their " "resources in their ``__init__`` method (such as file objects) can be handled " "correctly." msgstr "" -#: ../../library/contextlib.rst:540 +#: ../../library/contextlib.rst:541 msgid "" "Since registered callbacks are invoked in the reverse order of registration, " "this ends up behaving as if multiple nested :keyword:`with` statements had " @@ -864,7 +865,7 @@ msgid "" "updated state." msgstr "" -#: ../../library/contextlib.rst:547 +#: ../../library/contextlib.rst:548 msgid "" "This is a relatively low level API that takes care of the details of " "correctly unwinding the stack of exit callbacks. It provides a suitable " @@ -872,76 +873,76 @@ msgid "" "in application specific ways." msgstr "" -#: ../../library/contextlib.rst:556 +#: ../../library/contextlib.rst:557 msgid "" "Enters a new context manager and adds its :meth:`~object.__exit__` method to " "the callback stack. The return value is the result of the context manager's " "own :meth:`~object.__enter__` method." msgstr "" -#: ../../library/contextlib.rst:560 +#: ../../library/contextlib.rst:561 msgid "" "These context managers may suppress exceptions just as they normally would " "if used directly as part of a :keyword:`with` statement." msgstr "" -#: ../../library/contextlib.rst:563 +#: ../../library/contextlib.rst:564 msgid "" "Raises :exc:`TypeError` instead of :exc:`AttributeError` if *cm* is not a " "context manager." msgstr "" -#: ../../library/contextlib.rst:569 +#: ../../library/contextlib.rst:570 msgid "" "Adds a context manager's :meth:`~object.__exit__` method to the callback " "stack." msgstr "" -#: ../../library/contextlib.rst:571 +#: ../../library/contextlib.rst:572 msgid "" "As ``__enter__`` is *not* invoked, this method can be used to cover part of " "an :meth:`~object.__enter__` implementation with a context manager's own :" "meth:`~object.__exit__` method." msgstr "" -#: ../../library/contextlib.rst:575 +#: ../../library/contextlib.rst:576 msgid "" "If passed an object that is not a context manager, this method assumes it is " "a callback with the same signature as a context manager's :meth:`~object." "__exit__` method and adds it directly to the callback stack." msgstr "" -#: ../../library/contextlib.rst:579 +#: ../../library/contextlib.rst:580 msgid "" "By returning true values, these callbacks can suppress exceptions the same " "way context manager :meth:`~object.__exit__` methods can." msgstr "" -#: ../../library/contextlib.rst:582 +#: ../../library/contextlib.rst:583 msgid "" "The passed in object is returned from the function, allowing this method to " "be used as a function decorator." msgstr "" -#: ../../library/contextlib.rst:587 +#: ../../library/contextlib.rst:588 msgid "" "Accepts an arbitrary callback function and arguments and adds it to the " "callback stack." msgstr "" -#: ../../library/contextlib.rst:590 +#: ../../library/contextlib.rst:591 msgid "" "Unlike the other methods, callbacks added this way cannot suppress " "exceptions (as they are never passed the exception details)." msgstr "" -#: ../../library/contextlib.rst:593 +#: ../../library/contextlib.rst:594 msgid "" "The passed in callback is returned from the function, allowing this method " "to be used as a function decorator." msgstr "" -#: ../../library/contextlib.rst:598 +#: ../../library/contextlib.rst:599 msgid "" "Transfers the callback stack to a fresh :class:`ExitStack` instance and " "returns it. No callbacks are invoked by this operation - instead, they will " @@ -949,13 +950,13 @@ msgid "" "at the end of a :keyword:`with` statement)." msgstr "" -#: ../../library/contextlib.rst:603 +#: ../../library/contextlib.rst:604 msgid "" "For example, a group of files can be opened as an \"all or nothing\" " "operation as follows::" msgstr "" -#: ../../library/contextlib.rst:606 +#: ../../library/contextlib.rst:607 msgid "" "with ExitStack() as stack:\n" " files = [stack.enter_context(open(fname)) for fname in filenames]\n" @@ -967,57 +968,57 @@ msgid "" " # close_files() can then be invoked explicitly to close them all." msgstr "" -#: ../../library/contextlib.rst:617 +#: ../../library/contextlib.rst:618 msgid "" "Immediately unwinds the callback stack, invoking callbacks in the reverse " "order of registration. For any context managers and exit callbacks " "registered, the arguments passed in will indicate that no exception occurred." msgstr "" -#: ../../library/contextlib.rst:624 +#: ../../library/contextlib.rst:625 msgid "" "An :ref:`asynchronous context manager `, similar to :" "class:`ExitStack`, that supports combining both synchronous and asynchronous " "context managers, as well as having coroutines for cleanup logic." msgstr "" -#: ../../library/contextlib.rst:629 +#: ../../library/contextlib.rst:630 msgid "" "The :meth:`~ExitStack.close` method is not implemented; :meth:`aclose` must " "be used instead." msgstr "" -#: ../../library/contextlib.rst:635 +#: ../../library/contextlib.rst:636 msgid "" "Similar to :meth:`ExitStack.enter_context` but expects an asynchronous " "context manager." msgstr "" -#: ../../library/contextlib.rst:638 +#: ../../library/contextlib.rst:639 msgid "" "Raises :exc:`TypeError` instead of :exc:`AttributeError` if *cm* is not an " "asynchronous context manager." msgstr "" -#: ../../library/contextlib.rst:644 +#: ../../library/contextlib.rst:645 msgid "" "Similar to :meth:`ExitStack.push` but expects either an asynchronous context " "manager or a coroutine function." msgstr "" -#: ../../library/contextlib.rst:649 +#: ../../library/contextlib.rst:650 msgid "Similar to :meth:`ExitStack.callback` but expects a coroutine function." msgstr "和 :meth:`ExitStack.callback` 類似,但預期接受一個協程函式。" -#: ../../library/contextlib.rst:654 +#: ../../library/contextlib.rst:655 msgid "Similar to :meth:`ExitStack.close` but properly handles awaitables." msgstr "和 :meth:`ExitStack.close` 類似,但能夠正確處理可等待物件。" -#: ../../library/contextlib.rst:656 +#: ../../library/contextlib.rst:657 msgid "Continuing the example for :func:`asynccontextmanager`::" msgstr "延續 :func:`asynccontextmanager` 的範例: ::" -#: ../../library/contextlib.rst:658 +#: ../../library/contextlib.rst:659 msgid "" "async with AsyncExitStack() as stack:\n" " connections = [await stack.enter_async_context(get_connection())\n" @@ -1027,21 +1028,21 @@ msgid "" " # later in the list raise an exception." msgstr "" -#: ../../library/contextlib.rst:668 +#: ../../library/contextlib.rst:669 msgid "Examples and Recipes" msgstr "" -#: ../../library/contextlib.rst:670 +#: ../../library/contextlib.rst:671 msgid "" "This section describes some examples and recipes for making effective use of " "the tools provided by :mod:`!contextlib`." msgstr "" -#: ../../library/contextlib.rst:675 +#: ../../library/contextlib.rst:676 msgid "Supporting a variable number of context managers" msgstr "" -#: ../../library/contextlib.rst:677 +#: ../../library/contextlib.rst:678 msgid "" "The primary use case for :class:`ExitStack` is the one given in the class " "documentation: supporting a variable number of context managers and other " @@ -1051,7 +1052,7 @@ msgid "" "of the context managers being optional::" msgstr "" -#: ../../library/contextlib.rst:684 +#: ../../library/contextlib.rst:685 msgid "" "with ExitStack() as stack:\n" " for resource in resources:\n" @@ -1062,27 +1063,28 @@ msgid "" " # Perform operations that use the acquired resources" msgstr "" -#: ../../library/contextlib.rst:692 +#: ../../library/contextlib.rst:693 msgid "" "As shown, :class:`ExitStack` also makes it quite easy to use :keyword:`with` " "statements to manage arbitrary resources that don't natively support the " "context management protocol." msgstr "" -#: ../../library/contextlib.rst:698 +#: ../../library/contextlib.rst:699 msgid "Catching exceptions from ``__enter__`` methods" msgstr "" -#: ../../library/contextlib.rst:700 +#: ../../library/contextlib.rst:701 msgid "" -"It is occasionally desirable to catch exceptions from an ``__enter__`` " -"method implementation, *without* inadvertently catching exceptions from the :" -"keyword:`with` statement body or the context manager's ``__exit__`` method. " -"By using :class:`ExitStack` the steps in the context management protocol can " -"be separated slightly in order to allow this::" +"It is occasionally desirable to catch exceptions from an :meth:`~object." +"__enter__` method implementation, *without* inadvertently catching " +"exceptions from the :keyword:`with` statement body or the context manager's :" +"meth:`~object.__exit__` method. By using :class:`ExitStack` the steps in the " +"context management protocol can be separated slightly in order to allow " +"this::" msgstr "" -#: ../../library/contextlib.rst:706 +#: ../../library/contextlib.rst:707 msgid "" "stack = ExitStack()\n" "try:\n" @@ -1094,7 +1096,7 @@ msgid "" " # Handle normal case" msgstr "" -#: ../../library/contextlib.rst:715 +#: ../../library/contextlib.rst:716 msgid "" "Actually needing to do this is likely to indicate that the underlying API " "should be providing a direct resource management interface for use with :" @@ -1105,25 +1107,25 @@ msgid "" "`with` statement." msgstr "" -#: ../../library/contextlib.rst:725 +#: ../../library/contextlib.rst:726 msgid "Cleaning up in an ``__enter__`` implementation" msgstr "" -#: ../../library/contextlib.rst:727 +#: ../../library/contextlib.rst:728 msgid "" "As noted in the documentation of :meth:`ExitStack.push`, this method can be " "useful in cleaning up an already allocated resource if later steps in the :" "meth:`~object.__enter__` implementation fail." msgstr "" -#: ../../library/contextlib.rst:731 +#: ../../library/contextlib.rst:732 msgid "" "Here's an example of doing this for a context manager that accepts resource " "acquisition and release functions, along with an optional validation " "function, and maps them to the context management protocol::" msgstr "" -#: ../../library/contextlib.rst:735 +#: ../../library/contextlib.rst:736 msgid "" "from contextlib import contextmanager, AbstractContextManager, ExitStack\n" "\n" @@ -1161,11 +1163,11 @@ msgid "" " self.release_resource()" msgstr "" -#: ../../library/contextlib.rst:771 +#: ../../library/contextlib.rst:772 msgid "Replacing any use of ``try-finally`` and flag variables" msgstr "" -#: ../../library/contextlib.rst:773 +#: ../../library/contextlib.rst:774 msgid "" "A pattern you will sometimes see is a ``try-finally`` statement with a flag " "variable to indicate whether or not the body of the ``finally`` clause " @@ -1173,7 +1175,7 @@ msgid "" "by using an ``except`` clause instead), it looks something like this::" msgstr "" -#: ../../library/contextlib.rst:778 +#: ../../library/contextlib.rst:779 msgid "" "cleanup_needed = True\n" "try:\n" @@ -1193,21 +1195,21 @@ msgstr "" " if cleanup_needed:\n" " cleanup_resources()" -#: ../../library/contextlib.rst:787 +#: ../../library/contextlib.rst:788 msgid "" "As with any ``try`` statement based code, this can cause problems for " "development and review, because the setup code and the cleanup code can end " "up being separated by arbitrarily long sections of code." msgstr "" -#: ../../library/contextlib.rst:791 +#: ../../library/contextlib.rst:792 msgid "" ":class:`ExitStack` makes it possible to instead register a callback for " "execution at the end of a ``with`` statement, and then later decide to skip " "executing that callback::" msgstr "" -#: ../../library/contextlib.rst:795 +#: ../../library/contextlib.rst:796 msgid "" "from contextlib import ExitStack\n" "\n" @@ -1225,19 +1227,19 @@ msgstr "" " if result:\n" " stack.pop_all()" -#: ../../library/contextlib.rst:803 +#: ../../library/contextlib.rst:804 msgid "" "This allows the intended cleanup behaviour to be made explicit up front, " "rather than requiring a separate flag variable." msgstr "" -#: ../../library/contextlib.rst:806 +#: ../../library/contextlib.rst:807 msgid "" "If a particular application uses this pattern a lot, it can be simplified " "even further by means of a small helper class::" msgstr "" -#: ../../library/contextlib.rst:809 +#: ../../library/contextlib.rst:810 msgid "" "from contextlib import ExitStack\n" "\n" @@ -1269,14 +1271,14 @@ msgstr "" " if result:\n" " cb.cancel()" -#: ../../library/contextlib.rst:824 +#: ../../library/contextlib.rst:825 msgid "" "If the resource cleanup isn't already neatly bundled into a standalone " "function, then it is still possible to use the decorator form of :meth:" "`ExitStack.callback` to declare the resource cleanup in advance::" msgstr "" -#: ../../library/contextlib.rst:829 +#: ../../library/contextlib.rst:830 msgid "" "from contextlib import ExitStack\n" "\n" @@ -1298,24 +1300,24 @@ msgstr "" " if result:\n" " stack.pop_all()" -#: ../../library/contextlib.rst:839 +#: ../../library/contextlib.rst:840 msgid "" "Due to the way the decorator protocol works, a callback function declared " "this way cannot take any parameters. Instead, any resources to be released " "must be accessed as closure variables." msgstr "" -#: ../../library/contextlib.rst:845 +#: ../../library/contextlib.rst:846 msgid "Using a context manager as a function decorator" msgstr "" -#: ../../library/contextlib.rst:847 +#: ../../library/contextlib.rst:848 msgid "" ":class:`ContextDecorator` makes it possible to use a context manager in both " "an ordinary ``with`` statement and also as a function decorator." msgstr "" -#: ../../library/contextlib.rst:850 +#: ../../library/contextlib.rst:851 msgid "" "For example, it is sometimes useful to wrap functions or groups of " "statements with a logger that can track the time of entry and time of exit. " @@ -1324,7 +1326,7 @@ msgid "" "in a single definition::" msgstr "" -#: ../../library/contextlib.rst:856 +#: ../../library/contextlib.rst:857 msgid "" "from contextlib import ContextDecorator\n" "import logging\n" @@ -1356,11 +1358,11 @@ msgstr "" " def __exit__(self, exc_type, exc, exc_tb):\n" " logging.info('Exiting: %s', self.name)" -#: ../../library/contextlib.rst:871 +#: ../../library/contextlib.rst:872 msgid "Instances of this class can be used as both a context manager::" msgstr "" -#: ../../library/contextlib.rst:873 +#: ../../library/contextlib.rst:874 msgid "" "with track_entry_and_exit('widget loader'):\n" " print('Some time consuming activity goes here')\n" @@ -1370,11 +1372,11 @@ msgstr "" " print('Some time consuming activity goes here')\n" " load_widget()" -#: ../../library/contextlib.rst:877 +#: ../../library/contextlib.rst:878 msgid "And also as a function decorator::" msgstr "" -#: ../../library/contextlib.rst:879 +#: ../../library/contextlib.rst:880 msgid "" "@track_entry_and_exit('widget loader')\n" "def activity():\n" @@ -1386,7 +1388,7 @@ msgstr "" " print('Some time consuming activity goes here')\n" " load_widget()" -#: ../../library/contextlib.rst:884 +#: ../../library/contextlib.rst:885 msgid "" "Note that there is one additional limitation when using context managers as " "function decorators: there's no way to access the return value of :meth:" @@ -1394,21 +1396,21 @@ msgid "" "use an explicit ``with`` statement." msgstr "" -#: ../../library/contextlib.rst:891 +#: ../../library/contextlib.rst:892 msgid ":pep:`343` - The \"with\" statement" msgstr ":pep:`343` - \"with\" 陳述式" -#: ../../library/contextlib.rst:892 +#: ../../library/contextlib.rst:893 msgid "" "The specification, background, and examples for the Python :keyword:`with` " "statement." msgstr "" -#: ../../library/contextlib.rst:898 +#: ../../library/contextlib.rst:899 msgid "Single use, reusable and reentrant context managers" msgstr "" -#: ../../library/contextlib.rst:900 +#: ../../library/contextlib.rst:901 msgid "" "Most context managers are written in a way that means they can only be used " "effectively in a :keyword:`with` statement once. These single use context " @@ -1416,28 +1418,28 @@ msgid "" "them a second time will trigger an exception or otherwise not work correctly." msgstr "" -#: ../../library/contextlib.rst:906 +#: ../../library/contextlib.rst:907 msgid "" "This common limitation means that it is generally advisable to create " "context managers directly in the header of the :keyword:`with` statement " "where they are used (as shown in all of the usage examples above)." msgstr "" -#: ../../library/contextlib.rst:910 +#: ../../library/contextlib.rst:911 msgid "" "Files are an example of effectively single use context managers, since the " "first :keyword:`with` statement will close the file, preventing any further " "IO operations using that file object." msgstr "" -#: ../../library/contextlib.rst:914 +#: ../../library/contextlib.rst:915 msgid "" "Context managers created using :func:`contextmanager` are also single use " "context managers, and will complain about the underlying generator failing " "to yield if an attempt is made to use them a second time::" msgstr "" -#: ../../library/contextlib.rst:918 +#: ../../library/contextlib.rst:919 msgid "" ">>> from contextlib import contextmanager\n" ">>> @contextmanager\n" @@ -1479,11 +1481,11 @@ msgstr "" " ...\n" "RuntimeError: generator didn't yield" -#: ../../library/contextlib.rst:942 +#: ../../library/contextlib.rst:943 msgid "Reentrant context managers" msgstr "" -#: ../../library/contextlib.rst:944 +#: ../../library/contextlib.rst:945 msgid "" "More sophisticated context managers may be \"reentrant\". These context " "managers can not only be used in multiple :keyword:`with` statements, but " @@ -1491,14 +1493,14 @@ msgid "" "the same context manager." msgstr "" -#: ../../library/contextlib.rst:949 +#: ../../library/contextlib.rst:950 msgid "" ":class:`threading.RLock` is an example of a reentrant context manager, as " "are :func:`suppress`, :func:`redirect_stdout`, and :func:`chdir`. Here's a " "very simple example of reentrant use::" msgstr "" -#: ../../library/contextlib.rst:953 +#: ../../library/contextlib.rst:954 msgid "" ">>> from contextlib import redirect_stdout\n" ">>> from io import StringIO\n" @@ -1530,14 +1532,14 @@ msgstr "" "This is written to the stream rather than stdout\n" "This is also written to the stream" -#: ../../library/contextlib.rst:968 +#: ../../library/contextlib.rst:969 msgid "" "Real world examples of reentrancy are more likely to involve multiple " "functions calling each other and hence be far more complicated than this " "example." msgstr "" -#: ../../library/contextlib.rst:972 +#: ../../library/contextlib.rst:973 msgid "" "Note also that being reentrant is *not* the same thing as being thread " "safe. :func:`redirect_stdout`, for example, is definitely not thread safe, " @@ -1545,11 +1547,11 @@ msgid "" "stdout` to a different stream." msgstr "" -#: ../../library/contextlib.rst:981 +#: ../../library/contextlib.rst:982 msgid "Reusable context managers" msgstr "" -#: ../../library/contextlib.rst:983 +#: ../../library/contextlib.rst:984 msgid "" "Distinct from both single use and reentrant context managers are " "\"reusable\" context managers (or, to be completely explicit, \"reusable, " @@ -1559,21 +1561,21 @@ msgid "" "manager instance has already been used in a containing with statement." msgstr "" -#: ../../library/contextlib.rst:990 +#: ../../library/contextlib.rst:991 msgid "" ":class:`threading.Lock` is an example of a reusable, but not reentrant, " "context manager (for a reentrant lock, it is necessary to use :class:" "`threading.RLock` instead)." msgstr "" -#: ../../library/contextlib.rst:994 +#: ../../library/contextlib.rst:995 msgid "" "Another example of a reusable, but not reentrant, context manager is :class:" "`ExitStack`, as it invokes *all* currently registered callbacks when leaving " "any with statement, regardless of where those callbacks were added::" msgstr "" -#: ../../library/contextlib.rst:999 +#: ../../library/contextlib.rst:1000 msgid "" ">>> from contextlib import ExitStack\n" ">>> stack = ExitStack()\n" @@ -1627,7 +1629,7 @@ msgstr "" "Callback: from outer context\n" "Leaving outer context" -#: ../../library/contextlib.rst:1025 +#: ../../library/contextlib.rst:1026 msgid "" "As the output from the example shows, reusing a single stack object across " "multiple with statements works correctly, but attempting to nest them will " @@ -1635,13 +1637,13 @@ msgid "" "which is unlikely to be desirable behaviour." msgstr "" -#: ../../library/contextlib.rst:1030 +#: ../../library/contextlib.rst:1031 msgid "" "Using separate :class:`ExitStack` instances instead of reusing a single " "instance avoids that problem::" msgstr "" -#: ../../library/contextlib.rst:1033 +#: ../../library/contextlib.rst:1034 msgid "" ">>> from contextlib import ExitStack\n" ">>> with ExitStack() as outer_stack:\n" diff --git a/library/ctypes.po b/library/ctypes.po index 0fb583c228b..833b61e3f54 100644 --- a/library/ctypes.po +++ b/library/ctypes.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-07 00:19+0000\n" +"POT-Creation-Date: 2026-03-10 00:17+0000\n" "PO-Revision-Date: 2023-04-26 02:59+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -47,54 +47,49 @@ msgstr "ctypes 教學" #: ../../library/ctypes.rst:25 msgid "" -"Note: The code samples in this tutorial use :mod:`doctest` to make sure that " -"they actually work. Since some code samples behave differently under Linux, " -"Windows, or macOS, they contain doctest directives in comments." -msgstr "" - -#: ../../library/ctypes.rst:29 -msgid "" "Note: Some code samples reference the ctypes :class:`c_int` type. On " "platforms where ``sizeof(long) == sizeof(int)`` it is an alias to :class:" "`c_long`. So, you should not be confused if :class:`c_long` is printed if " "you would expect :class:`c_int` --- they are actually the same type." msgstr "" -#: ../../library/ctypes.rst:37 +#: ../../library/ctypes.rst:33 msgid "Loading dynamic link libraries" msgstr "" -#: ../../library/ctypes.rst:39 +#: ../../library/ctypes.rst:35 msgid "" -":mod:`!ctypes` exports the *cdll*, and on Windows *windll* and *oledll* " -"objects, for loading dynamic link libraries." +":mod:`!ctypes` exports the :py:data:`~ctypes.cdll`, and on Windows :py:data:" +"`~ctypes.windll` and :py:data:`~ctypes.oledll` objects, for loading dynamic " +"link libraries." msgstr "" -#: ../../library/ctypes.rst:42 +#: ../../library/ctypes.rst:39 msgid "" -"You load libraries by accessing them as attributes of these objects. *cdll* " -"loads libraries which export functions using the standard ``cdecl`` calling " -"convention, while *windll* libraries call functions using the ``stdcall`` " -"calling convention. *oledll* also uses the ``stdcall`` calling convention, " -"and assumes the functions return a Windows :c:type:`!HRESULT` error code. " -"The error code is used to automatically raise an :class:`OSError` exception " -"when the function call fails." +"You load libraries by accessing them as attributes of these objects. :py:" +"data:`!cdll` loads libraries which export functions using the standard " +"``cdecl`` calling convention, while :py:data:`!windll` libraries call " +"functions using the ``stdcall`` calling convention. :py:data:`~oledll` also " +"uses the ``stdcall`` calling convention, and assumes the functions return a " +"Windows :c:type:`!HRESULT` error code. The error code is used to " +"automatically raise an :class:`OSError` exception when the function call " +"fails." msgstr "" -#: ../../library/ctypes.rst:50 +#: ../../library/ctypes.rst:49 msgid "" "Windows errors used to raise :exc:`WindowsError`, which is now an alias of :" "exc:`OSError`." msgstr "" -#: ../../library/ctypes.rst:55 +#: ../../library/ctypes.rst:54 msgid "" "Here are some examples for Windows. Note that ``msvcrt`` is the MS standard " "C library containing most standard C functions, and uses the ``cdecl`` " "calling convention::" msgstr "" -#: ../../library/ctypes.rst:59 +#: ../../library/ctypes.rst:58 msgid "" ">>> from ctypes import *\n" ">>> print(windll.kernel32)\n" @@ -112,11 +107,11 @@ msgstr "" ">>> libc = cdll.msvcrt\n" ">>>" -#: ../../library/ctypes.rst:67 +#: ../../library/ctypes.rst:66 msgid "Windows appends the usual ``.dll`` file suffix automatically." msgstr "" -#: ../../library/ctypes.rst:70 +#: ../../library/ctypes.rst:69 msgid "" "Accessing the standard C library through ``cdll.msvcrt`` will use an " "outdated version of the library that may be incompatible with the one being " @@ -124,16 +119,21 @@ msgid "" "import and use the ``msvcrt`` module." msgstr "" -#: ../../library/ctypes.rst:75 +#: ../../library/ctypes.rst:74 msgid "" -"On Linux, it is required to specify the filename *including* the extension " -"to load a library, so attribute access can not be used to load libraries. " -"Either the :meth:`~LibraryLoader.LoadLibrary` method of the dll loaders " -"should be used, or you should load the library by creating an instance of " -"CDLL by calling the constructor::" +"Other systems require the filename *including* the extension to load a " +"library, so attribute access can not be used to load libraries. Either the :" +"meth:`~LibraryLoader.LoadLibrary` method of the dll loaders should be used, " +"or you should load the library by creating an instance of :py:class:`CDLL` " +"by calling the constructor." msgstr "" -#: ../../library/ctypes.rst:81 +#: ../../library/ctypes.rst:80 +#, fuzzy +msgid "For example, on Linux::" +msgstr "舉例來說: ::" + +#: ../../library/ctypes.rst:82 msgid "" ">>> cdll.LoadLibrary(\"libc.so.6\")\n" "\n" @@ -149,15 +149,35 @@ msgstr "" "\n" ">>>" -#: ../../library/ctypes.rst:94 +#: ../../library/ctypes.rst:89 +msgid "On macOS::" +msgstr "" + +#: ../../library/ctypes.rst:91 +#, fuzzy +msgid "" +">>> cdll.LoadLibrary(\"libc.dylib\")\n" +"\n" +">>> libc = CDLL(\"libc.dylib\")\n" +">>> libc\n" +"" +msgstr "" +">>> cdll.LoadLibrary(\"libc.so.6\")\n" +"\n" +">>> libc = CDLL(\"libc.so.6\")\n" +">>> libc\n" +"\n" +">>>" + +#: ../../library/ctypes.rst:102 msgid "Accessing functions from loaded dlls" msgstr "" -#: ../../library/ctypes.rst:96 +#: ../../library/ctypes.rst:104 msgid "Functions are accessed as attributes of dll objects::" msgstr "" -#: ../../library/ctypes.rst:98 +#: ../../library/ctypes.rst:106 msgid "" ">>> libc.printf\n" "<_FuncPtr object at 0x...>\n" @@ -183,7 +203,7 @@ msgstr "" "AttributeError: function 'MyOwnFunction' not found\n" ">>>" -#: ../../library/ctypes.rst:110 +#: ../../library/ctypes.rst:118 msgid "" "Note that win32 system dlls like ``kernel32`` and ``user32`` often export " "ANSI as well as UNICODE versions of a function. The UNICODE version is " @@ -194,7 +214,7 @@ msgid "" "``GetModuleHandle`` depending on whether UNICODE is defined or not::" msgstr "" -#: ../../library/ctypes.rst:118 +#: ../../library/ctypes.rst:126 msgid "" "/* ANSI version */\n" "HMODULE GetModuleHandleA(LPCSTR lpModuleName);\n" @@ -206,21 +226,21 @@ msgstr "" "/* UNICODE 版本 */\n" "HMODULE GetModuleHandleW(LPCWSTR lpModuleName);" -#: ../../library/ctypes.rst:123 +#: ../../library/ctypes.rst:131 msgid "" "*windll* does not try to select one of them by magic, you must access the " "version you need by specifying ``GetModuleHandleA`` or ``GetModuleHandleW`` " "explicitly, and then call it with bytes or string objects respectively." msgstr "" -#: ../../library/ctypes.rst:127 +#: ../../library/ctypes.rst:135 msgid "" "Sometimes, dlls export functions with names which aren't valid Python " "identifiers, like ``\"??2@YAPAXI@Z\"``. In this case you have to use :func:" "`getattr` to retrieve the function::" msgstr "" -#: ../../library/ctypes.rst:131 +#: ../../library/ctypes.rst:139 msgid "" ">>> getattr(cdll.msvcrt, \"??2@YAPAXI@Z\")\n" "<_FuncPtr object at 0x...>\n" @@ -230,14 +250,14 @@ msgstr "" "<_FuncPtr object at 0x...>\n" ">>>" -#: ../../library/ctypes.rst:135 +#: ../../library/ctypes.rst:143 msgid "" "On Windows, some dlls export functions not by name but by ordinal. These " "functions can be accessed by indexing the dll object with the ordinal " "number::" msgstr "" -#: ../../library/ctypes.rst:138 +#: ../../library/ctypes.rst:146 msgid "" ">>> cdll.kernel32[1]\n" "<_FuncPtr object at 0x...>\n" @@ -259,18 +279,18 @@ msgstr "" "AttributeError: function ordinal 0 not found\n" ">>>" -#: ../../library/ctypes.rst:152 +#: ../../library/ctypes.rst:160 msgid "Calling functions" msgstr "呼叫函式" -#: ../../library/ctypes.rst:154 +#: ../../library/ctypes.rst:162 msgid "" "You can call these functions like any other Python callable. This example " "uses the ``rand()`` function, which takes no arguments and returns a pseudo-" "random integer::" msgstr "" -#: ../../library/ctypes.rst:157 +#: ../../library/ctypes.rst:165 msgid "" ">>> print(libc.rand())\n" "1804289383" @@ -278,14 +298,14 @@ msgstr "" ">>> print(libc.rand())\n" "1804289383" -#: ../../library/ctypes.rst:160 +#: ../../library/ctypes.rst:168 msgid "" "On Windows, you can call the ``GetModuleHandleA()`` function, which returns " "a win32 module handle (passing ``None`` as single argument to call it with a " "``NULL`` pointer)::" msgstr "" -#: ../../library/ctypes.rst:163 +#: ../../library/ctypes.rst:171 msgid "" ">>> print(hex(windll.kernel32.GetModuleHandleA(None)))\n" "0x1d000000\n" @@ -295,13 +315,13 @@ msgstr "" "0x1d000000\n" ">>>" -#: ../../library/ctypes.rst:167 +#: ../../library/ctypes.rst:175 msgid "" ":exc:`ValueError` is raised when you call an ``stdcall`` function with the " "``cdecl`` calling convention, or vice versa::" msgstr "" -#: ../../library/ctypes.rst:170 +#: ../../library/ctypes.rst:178 msgid "" ">>> cdll.kernel32.GetModuleHandleA(None)\n" "Traceback (most recent call last):\n" @@ -331,20 +351,20 @@ msgstr "" "excess)\n" ">>>" -#: ../../library/ctypes.rst:182 +#: ../../library/ctypes.rst:190 msgid "" "To find out the correct calling convention you have to look into the C " "header file or the documentation for the function you want to call." msgstr "" -#: ../../library/ctypes.rst:185 +#: ../../library/ctypes.rst:193 msgid "" "On Windows, :mod:`!ctypes` uses win32 structured exception handling to " "prevent crashes from general protection faults when functions are called " "with invalid argument values::" msgstr "" -#: ../../library/ctypes.rst:189 +#: ../../library/ctypes.rst:197 msgid "" ">>> windll.kernel32.GetModuleHandleA(32)\n" "Traceback (most recent call last):\n" @@ -358,7 +378,7 @@ msgstr "" "OSError: exception: access violation reading 0x00000020\n" ">>>" -#: ../../library/ctypes.rst:195 +#: ../../library/ctypes.rst:203 msgid "" "There are, however, enough ways to crash Python with :mod:`!ctypes`, so you " "should be careful anyway. The :mod:`faulthandler` module can be helpful in " @@ -366,7 +386,7 @@ msgid "" "library calls)." msgstr "" -#: ../../library/ctypes.rst:200 +#: ../../library/ctypes.rst:208 msgid "" "``None``, integers, bytes objects and (unicode) strings are the only native " "Python objects that can directly be used as parameters in these function " @@ -377,74 +397,72 @@ msgid "" "the C type." msgstr "" -#: ../../library/ctypes.rst:207 +#: ../../library/ctypes.rst:215 msgid "" "Before we move on calling functions with other parameter types, we have to " "learn more about :mod:`!ctypes` data types." msgstr "" -#: ../../library/ctypes.rst:214 ../../library/ctypes.rst:2433 +#: ../../library/ctypes.rst:222 ../../library/ctypes.rst:2449 msgid "Fundamental data types" msgstr "" -#: ../../library/ctypes.rst:216 +#: ../../library/ctypes.rst:224 msgid ":mod:`!ctypes` defines a number of primitive C compatible data types:" msgstr "" -#: ../../library/ctypes.rst:219 ../../library/ctypes.rst:291 +#: ../../library/ctypes.rst:227 ../../library/ctypes.rst:299 msgid "ctypes type" msgstr "ctypes 型別" -#: ../../library/ctypes.rst:219 ../../library/ctypes.rst:291 +#: ../../library/ctypes.rst:227 ../../library/ctypes.rst:299 msgid "C type" msgstr "C 型別" -#: ../../library/ctypes.rst:219 ../../library/ctypes.rst:291 +#: ../../library/ctypes.rst:227 ../../library/ctypes.rst:299 msgid "Python type" msgstr "Python 型別" -#: ../../library/ctypes.rst:221 +#: ../../library/ctypes.rst:229 msgid ":class:`c_bool`" msgstr ":class:`c_bool`" -#: ../../library/ctypes.rst:221 +#: ../../library/ctypes.rst:229 msgid ":c:expr:`_Bool`" msgstr ":c:expr:`_Bool`" -#: ../../library/ctypes.rst:221 +#: ../../library/ctypes.rst:229 msgid "bool (1)" msgstr "bool (1)" -#: ../../library/ctypes.rst:223 +#: ../../library/ctypes.rst:231 msgid ":class:`c_char`" msgstr ":class:`c_char`" -#: ../../library/ctypes.rst:223 ../../library/ctypes.rst:227 +#: ../../library/ctypes.rst:231 ../../library/ctypes.rst:235 msgid ":c:expr:`char`" msgstr ":c:expr:`char`" -#: ../../library/ctypes.rst:223 +#: ../../library/ctypes.rst:231 msgid "1-character bytes object" msgstr "" -#: ../../library/ctypes.rst:225 +#: ../../library/ctypes.rst:233 msgid ":class:`c_wchar`" msgstr ":class:`c_wchar`" -#: ../../library/ctypes.rst:225 +#: ../../library/ctypes.rst:233 msgid ":c:type:`wchar_t`" msgstr ":c:type:`wchar_t`" -#: ../../library/ctypes.rst:225 +#: ../../library/ctypes.rst:233 msgid "1-character string" msgstr "" -#: ../../library/ctypes.rst:227 +#: ../../library/ctypes.rst:235 msgid ":class:`c_byte`" msgstr ":class:`c_byte`" -#: ../../library/ctypes.rst:227 ../../library/ctypes.rst:229 -#: ../../library/ctypes.rst:231 ../../library/ctypes.rst:233 #: ../../library/ctypes.rst:235 ../../library/ctypes.rst:237 #: ../../library/ctypes.rst:239 ../../library/ctypes.rst:241 #: ../../library/ctypes.rst:243 ../../library/ctypes.rst:245 @@ -452,283 +470,285 @@ msgstr ":class:`c_byte`" #: ../../library/ctypes.rst:251 ../../library/ctypes.rst:253 #: ../../library/ctypes.rst:255 ../../library/ctypes.rst:257 #: ../../library/ctypes.rst:259 ../../library/ctypes.rst:261 -#: ../../library/ctypes.rst:264 ../../library/ctypes.rst:266 -#: ../../library/ctypes.rst:269 +#: ../../library/ctypes.rst:263 ../../library/ctypes.rst:265 +#: ../../library/ctypes.rst:267 ../../library/ctypes.rst:269 +#: ../../library/ctypes.rst:272 ../../library/ctypes.rst:274 +#: ../../library/ctypes.rst:277 msgid "int" msgstr "int" -#: ../../library/ctypes.rst:229 +#: ../../library/ctypes.rst:237 msgid ":class:`c_ubyte`" msgstr ":class:`c_ubyte`" -#: ../../library/ctypes.rst:229 +#: ../../library/ctypes.rst:237 msgid ":c:expr:`unsigned char`" msgstr ":c:expr:`unsigned char`" -#: ../../library/ctypes.rst:231 +#: ../../library/ctypes.rst:239 msgid ":class:`c_short`" msgstr ":class:`c_short`" -#: ../../library/ctypes.rst:231 +#: ../../library/ctypes.rst:239 msgid ":c:expr:`short`" msgstr ":c:expr:`short`" -#: ../../library/ctypes.rst:233 +#: ../../library/ctypes.rst:241 msgid ":class:`c_ushort`" msgstr ":class:`c_ushort`" -#: ../../library/ctypes.rst:233 +#: ../../library/ctypes.rst:241 msgid ":c:expr:`unsigned short`" msgstr ":c:expr:`unsigned short`" -#: ../../library/ctypes.rst:235 +#: ../../library/ctypes.rst:243 msgid ":class:`c_int`" msgstr ":class:`c_int`" -#: ../../library/ctypes.rst:235 +#: ../../library/ctypes.rst:243 msgid ":c:expr:`int`" msgstr ":c:expr:`int`" -#: ../../library/ctypes.rst:237 +#: ../../library/ctypes.rst:245 msgid ":class:`c_int8`" msgstr ":class:`c_int8`" -#: ../../library/ctypes.rst:237 +#: ../../library/ctypes.rst:245 msgid ":c:type:`int8_t`" msgstr ":c:type:`int8_t`" -#: ../../library/ctypes.rst:239 +#: ../../library/ctypes.rst:247 msgid ":class:`c_int16`" msgstr ":class:`c_int16`" -#: ../../library/ctypes.rst:239 +#: ../../library/ctypes.rst:247 msgid ":c:type:`int16_t`" msgstr ":c:type:`int16_t`" -#: ../../library/ctypes.rst:241 +#: ../../library/ctypes.rst:249 msgid ":class:`c_int32`" msgstr ":class:`c_int32`" -#: ../../library/ctypes.rst:241 +#: ../../library/ctypes.rst:249 msgid ":c:type:`int32_t`" msgstr ":c:type:`int32_t`" -#: ../../library/ctypes.rst:243 +#: ../../library/ctypes.rst:251 msgid ":class:`c_int64`" msgstr ":class:`c_int64`" -#: ../../library/ctypes.rst:243 +#: ../../library/ctypes.rst:251 msgid ":c:type:`int64_t`" msgstr ":c:type:`int64_t`" -#: ../../library/ctypes.rst:245 +#: ../../library/ctypes.rst:253 msgid ":class:`c_uint`" msgstr ":class:`c_uint`" -#: ../../library/ctypes.rst:245 +#: ../../library/ctypes.rst:253 msgid ":c:expr:`unsigned int`" msgstr ":c:expr:`unsigned int`" -#: ../../library/ctypes.rst:247 +#: ../../library/ctypes.rst:255 msgid ":class:`c_uint8`" msgstr ":class:`c_uint8`" -#: ../../library/ctypes.rst:247 +#: ../../library/ctypes.rst:255 msgid ":c:type:`uint8_t`" msgstr ":c:type:`uint8_t`" -#: ../../library/ctypes.rst:249 +#: ../../library/ctypes.rst:257 msgid ":class:`c_uint16`" msgstr ":class:`c_uint16`" -#: ../../library/ctypes.rst:249 +#: ../../library/ctypes.rst:257 msgid ":c:type:`uint16_t`" msgstr ":c:type:`uint16_t`" -#: ../../library/ctypes.rst:251 +#: ../../library/ctypes.rst:259 msgid ":class:`c_uint32`" msgstr ":class:`c_uint32`" -#: ../../library/ctypes.rst:251 +#: ../../library/ctypes.rst:259 msgid ":c:type:`uint32_t`" msgstr ":c:type:`uint32_t`" -#: ../../library/ctypes.rst:253 +#: ../../library/ctypes.rst:261 msgid ":class:`c_uint64`" msgstr ":class:`c_uint64`" -#: ../../library/ctypes.rst:253 +#: ../../library/ctypes.rst:261 msgid ":c:type:`uint64_t`" msgstr ":c:type:`uint64_t`" -#: ../../library/ctypes.rst:255 +#: ../../library/ctypes.rst:263 msgid ":class:`c_long`" msgstr ":class:`c_long`" -#: ../../library/ctypes.rst:255 +#: ../../library/ctypes.rst:263 msgid ":c:expr:`long`" msgstr ":c:expr:`long`" -#: ../../library/ctypes.rst:257 +#: ../../library/ctypes.rst:265 msgid ":class:`c_ulong`" msgstr ":class:`c_ulong`" -#: ../../library/ctypes.rst:257 +#: ../../library/ctypes.rst:265 msgid ":c:expr:`unsigned long`" msgstr ":c:expr:`unsigned long`" -#: ../../library/ctypes.rst:259 +#: ../../library/ctypes.rst:267 msgid ":class:`c_longlong`" msgstr ":class:`c_longlong`" -#: ../../library/ctypes.rst:259 +#: ../../library/ctypes.rst:267 msgid ":c:expr:`__int64` or :c:expr:`long long`" msgstr ":c:expr:`__int64` 或 :c:expr:`long long`" -#: ../../library/ctypes.rst:261 +#: ../../library/ctypes.rst:269 msgid ":class:`c_ulonglong`" msgstr ":class:`c_ulonglong`" -#: ../../library/ctypes.rst:261 +#: ../../library/ctypes.rst:269 msgid ":c:expr:`unsigned __int64` or :c:expr:`unsigned long long`" msgstr ":c:expr:`unsigned __int64` 或 :c:expr:`unsigned long long`" -#: ../../library/ctypes.rst:264 +#: ../../library/ctypes.rst:272 msgid ":class:`c_size_t`" msgstr ":class:`c_size_t`" -#: ../../library/ctypes.rst:264 +#: ../../library/ctypes.rst:272 msgid ":c:type:`size_t`" msgstr ":c:type:`size_t`" -#: ../../library/ctypes.rst:266 +#: ../../library/ctypes.rst:274 msgid ":class:`c_ssize_t`" msgstr ":class:`c_ssize_t`" -#: ../../library/ctypes.rst:266 +#: ../../library/ctypes.rst:274 msgid ":c:type:`ssize_t` or :c:expr:`Py_ssize_t`" msgstr ":c:type:`ssize_t` 或 :c:expr:`Py_ssize_t`" -#: ../../library/ctypes.rst:269 +#: ../../library/ctypes.rst:277 msgid ":class:`c_time_t`" msgstr ":class:`c_time_t`" -#: ../../library/ctypes.rst:269 +#: ../../library/ctypes.rst:277 msgid ":c:type:`time_t`" msgstr ":c:type:`time_t`" -#: ../../library/ctypes.rst:271 +#: ../../library/ctypes.rst:279 msgid ":class:`c_float`" msgstr ":class:`c_float`" -#: ../../library/ctypes.rst:271 +#: ../../library/ctypes.rst:279 msgid ":c:expr:`float`" msgstr ":c:expr:`float`" -#: ../../library/ctypes.rst:271 ../../library/ctypes.rst:273 -#: ../../library/ctypes.rst:275 +#: ../../library/ctypes.rst:279 ../../library/ctypes.rst:281 +#: ../../library/ctypes.rst:283 msgid "float" msgstr "float" -#: ../../library/ctypes.rst:273 +#: ../../library/ctypes.rst:281 msgid ":class:`c_double`" msgstr ":class:`c_double`" -#: ../../library/ctypes.rst:273 +#: ../../library/ctypes.rst:281 msgid ":c:expr:`double`" msgstr ":c:expr:`double`" -#: ../../library/ctypes.rst:275 +#: ../../library/ctypes.rst:283 msgid ":class:`c_longdouble`" msgstr ":class:`c_longdouble`" -#: ../../library/ctypes.rst:275 +#: ../../library/ctypes.rst:283 msgid ":c:expr:`long double`" msgstr ":c:expr:`long double`" -#: ../../library/ctypes.rst:277 +#: ../../library/ctypes.rst:285 msgid ":class:`c_char_p`" msgstr ":class:`c_char_p`" -#: ../../library/ctypes.rst:277 +#: ../../library/ctypes.rst:285 msgid ":c:expr:`char *` (NUL terminated)" msgstr "" -#: ../../library/ctypes.rst:277 +#: ../../library/ctypes.rst:285 msgid "bytes object or ``None``" msgstr "位元組物件或 ``None``" -#: ../../library/ctypes.rst:279 +#: ../../library/ctypes.rst:287 msgid ":class:`c_wchar_p`" msgstr ":class:`c_wchar_p`" -#: ../../library/ctypes.rst:279 +#: ../../library/ctypes.rst:287 msgid ":c:expr:`wchar_t *` (NUL terminated)" msgstr "" -#: ../../library/ctypes.rst:279 +#: ../../library/ctypes.rst:287 msgid "string or ``None``" msgstr "字串或 ``None``" -#: ../../library/ctypes.rst:281 +#: ../../library/ctypes.rst:289 msgid ":class:`c_void_p`" msgstr ":class:`c_void_p`" -#: ../../library/ctypes.rst:281 +#: ../../library/ctypes.rst:289 msgid ":c:expr:`void *`" msgstr ":c:expr:`void *`" -#: ../../library/ctypes.rst:281 +#: ../../library/ctypes.rst:289 msgid "int or ``None``" msgstr "" -#: ../../library/ctypes.rst:285 +#: ../../library/ctypes.rst:293 msgid "The constructor accepts any object with a truth value." msgstr "" -#: ../../library/ctypes.rst:287 +#: ../../library/ctypes.rst:295 msgid "" "Additionally, if IEC 60559 compatible complex arithmetic (Annex G) is " "supported in both C and ``libffi``, the following complex types are " "available:" msgstr "" -#: ../../library/ctypes.rst:293 +#: ../../library/ctypes.rst:301 msgid ":class:`c_float_complex`" msgstr ":class:`c_float_complex`" -#: ../../library/ctypes.rst:293 +#: ../../library/ctypes.rst:301 msgid ":c:expr:`float complex`" msgstr ":c:expr:`float complex`" -#: ../../library/ctypes.rst:293 ../../library/ctypes.rst:295 -#: ../../library/ctypes.rst:297 +#: ../../library/ctypes.rst:301 ../../library/ctypes.rst:303 +#: ../../library/ctypes.rst:305 msgid "complex" msgstr "" -#: ../../library/ctypes.rst:295 +#: ../../library/ctypes.rst:303 msgid ":class:`c_double_complex`" msgstr ":class:`c_double_complex`" -#: ../../library/ctypes.rst:295 +#: ../../library/ctypes.rst:303 msgid ":c:expr:`double complex`" msgstr ":c:expr:`double complex`" -#: ../../library/ctypes.rst:297 +#: ../../library/ctypes.rst:305 msgid ":class:`c_longdouble_complex`" msgstr ":class:`c_longdouble_complex`" -#: ../../library/ctypes.rst:297 +#: ../../library/ctypes.rst:305 msgid ":c:expr:`long double complex`" msgstr ":c:expr:`long double complex`" -#: ../../library/ctypes.rst:301 +#: ../../library/ctypes.rst:309 msgid "" "All these types can be created by calling them with an optional initializer " "of the correct type and value::" msgstr "" -#: ../../library/ctypes.rst:304 +#: ../../library/ctypes.rst:312 msgid "" ">>> c_int()\n" "c_long(0)\n" @@ -746,12 +766,12 @@ msgstr "" "c_ushort(65533)\n" ">>>" -#: ../../library/ctypes.rst:312 +#: ../../library/ctypes.rst:320 msgid "" "Since these types are mutable, their value can also be changed afterwards::" msgstr "" -#: ../../library/ctypes.rst:314 +#: ../../library/ctypes.rst:322 msgid "" ">>> i = c_int(42)\n" ">>> print(i)\n" @@ -773,7 +793,7 @@ msgstr "" "-99\n" ">>>" -#: ../../library/ctypes.rst:324 +#: ../../library/ctypes.rst:332 msgid "" "Assigning a new value to instances of the pointer types :class:`c_char_p`, :" "class:`c_wchar_p`, and :class:`c_void_p` changes the *memory location* they " @@ -781,7 +801,7 @@ msgid "" "Python string objects are immutable)::" msgstr "" -#: ../../library/ctypes.rst:329 +#: ../../library/ctypes.rst:337 msgid "" ">>> s = \"Hello, World\"\n" ">>> c_s = c_wchar_p(s)\n" @@ -813,7 +833,7 @@ msgstr "" "Hello, World\n" ">>>" -#: ../../library/ctypes.rst:344 +#: ../../library/ctypes.rst:352 msgid "" "You should be careful, however, not to pass them to functions expecting " "pointers to mutable memory. If you need mutable memory blocks, ctypes has a :" @@ -823,7 +843,7 @@ msgid "" "``value`` property::" msgstr "" -#: ../../library/ctypes.rst:351 +#: ../../library/ctypes.rst:359 msgid "" ">>> from ctypes import *\n" ">>> p = create_string_buffer(3) # create a 3 byte buffer, " @@ -845,7 +865,7 @@ msgid "" ">>>" msgstr "" -#: ../../library/ctypes.rst:368 +#: ../../library/ctypes.rst:376 msgid "" "The :func:`create_string_buffer` function replaces the old :func:`!c_buffer` " "function (which is still available as an alias). To create a mutable memory " @@ -853,18 +873,18 @@ msgid "" "the :func:`create_unicode_buffer` function." msgstr "" -#: ../../library/ctypes.rst:377 +#: ../../library/ctypes.rst:385 msgid "Calling functions, continued" msgstr "" -#: ../../library/ctypes.rst:379 +#: ../../library/ctypes.rst:387 msgid "" "Note that printf prints to the real standard output channel, *not* to :data:" "`sys.stdout`, so these examples will only work at the console prompt, not " "from within *IDLE* or *PythonWin*::" msgstr "" -#: ../../library/ctypes.rst:383 +#: ../../library/ctypes.rst:391 msgid "" ">>> printf = libc.printf\n" ">>> printf(b\"Hello, %s\\n\", b\"World!\")\n" @@ -900,14 +920,14 @@ msgstr "" "parameter 2\n" ">>>" -#: ../../library/ctypes.rst:399 +#: ../../library/ctypes.rst:407 msgid "" "As has been mentioned before, all Python types except integers, strings, and " "bytes objects have to be wrapped in their corresponding :mod:`!ctypes` type, " "so that they can be converted to the required C data type::" msgstr "" -#: ../../library/ctypes.rst:403 +#: ../../library/ctypes.rst:411 msgid "" ">>> printf(b\"An int %d, a double %f\\n\", 1234, c_double(3.14))\n" "An int 1234, a double 3.140000\n" @@ -919,11 +939,11 @@ msgstr "" "31\n" ">>>" -#: ../../library/ctypes.rst:411 +#: ../../library/ctypes.rst:419 msgid "Calling variadic functions" msgstr "" -#: ../../library/ctypes.rst:413 +#: ../../library/ctypes.rst:421 msgid "" "On a lot of platforms calling variadic functions through ctypes is exactly " "the same as calling functions with a fixed number of parameters. On some " @@ -932,27 +952,27 @@ msgid "" "functions." msgstr "" -#: ../../library/ctypes.rst:418 +#: ../../library/ctypes.rst:426 msgid "" "On those platforms it is required to specify the :attr:`~_CFuncPtr.argtypes` " "attribute for the regular, non-variadic, function arguments:" msgstr "" -#: ../../library/ctypes.rst:421 +#: ../../library/ctypes.rst:429 msgid "libc.printf.argtypes = [ctypes.c_char_p]" msgstr "libc.printf.argtypes = [ctypes.c_char_p]" -#: ../../library/ctypes.rst:425 +#: ../../library/ctypes.rst:433 msgid "" "Because specifying the attribute does not inhibit portability it is advised " "to always specify :attr:`~_CFuncPtr.argtypes` for all variadic functions." msgstr "" -#: ../../library/ctypes.rst:432 +#: ../../library/ctypes.rst:440 msgid "Calling functions with your own custom data types" msgstr "" -#: ../../library/ctypes.rst:434 +#: ../../library/ctypes.rst:442 msgid "" "You can also customize :mod:`!ctypes` argument conversion to allow instances " "of your own classes be used as function arguments. :mod:`!ctypes` looks for " @@ -961,7 +981,7 @@ msgid "" "or an object with an :attr:`!_as_parameter_` attribute::" msgstr "" -#: ../../library/ctypes.rst:440 +#: ../../library/ctypes.rst:448 msgid "" ">>> class Bottles:\n" "... def __init__(self, number):\n" @@ -983,24 +1003,24 @@ msgstr "" "19\n" ">>>" -#: ../../library/ctypes.rst:450 +#: ../../library/ctypes.rst:458 msgid "" "If you don't want to store the instance's data in the :attr:`!" "_as_parameter_` instance variable, you could define a :class:`property` " "which makes the attribute available on request." msgstr "" -#: ../../library/ctypes.rst:458 +#: ../../library/ctypes.rst:466 msgid "Specifying the required argument types (function prototypes)" msgstr "" -#: ../../library/ctypes.rst:460 +#: ../../library/ctypes.rst:468 msgid "" "It is possible to specify the required argument types of functions exported " "from DLLs by setting the :attr:`~_CFuncPtr.argtypes` attribute." msgstr "" -#: ../../library/ctypes.rst:463 +#: ../../library/ctypes.rst:471 msgid "" ":attr:`~_CFuncPtr.argtypes` must be a sequence of C data types (the :func:`!" "printf` function is probably not a good example here, because it takes a " @@ -1009,7 +1029,7 @@ msgid "" "feature)::" msgstr "" -#: ../../library/ctypes.rst:468 +#: ../../library/ctypes.rst:476 msgid "" ">>> printf.argtypes = [c_char_p, c_char_p, c_int, c_double]\n" ">>> printf(b\"String '%s', Int %d, Double %f\\n\", b\"Hi\", 10, 2.2)\n" @@ -1023,14 +1043,14 @@ msgstr "" "37\n" ">>>" -#: ../../library/ctypes.rst:474 +#: ../../library/ctypes.rst:482 msgid "" "Specifying a format protects against incompatible argument types (just as a " "prototype for a C function), and tries to convert the arguments to valid " "types::" msgstr "" -#: ../../library/ctypes.rst:477 +#: ../../library/ctypes.rst:485 msgid "" ">>> printf(b\"%d %d %d\", 1, 2, 3)\n" "Traceback (most recent call last):\n" @@ -1052,7 +1072,7 @@ msgstr "" "13\n" ">>>" -#: ../../library/ctypes.rst:486 +#: ../../library/ctypes.rst:494 msgid "" "If you have defined your own classes which you pass to function calls, you " "have to implement a :meth:`~_CData.from_param` class method for them to be " @@ -1066,43 +1086,43 @@ msgid "" "_as_parameter_` attribute." msgstr "" -#: ../../library/ctypes.rst:500 +#: ../../library/ctypes.rst:508 msgid "Return types" msgstr "" -#: ../../library/ctypes.rst:510 +#: ../../library/ctypes.rst:518 msgid "" "By default functions are assumed to return the C :c:expr:`int` type. Other " "return types can be specified by setting the :attr:`~_CFuncPtr.restype` " "attribute of the function object." msgstr "" -#: ../../library/ctypes.rst:514 +#: ../../library/ctypes.rst:522 msgid "" "The C prototype of :c:func:`time` is ``time_t time(time_t *)``. Because :c:" "type:`time_t` might be of a different type than the default return type :c:" "expr:`int`, you should specify the :attr:`!restype` attribute::" msgstr "" -#: ../../library/ctypes.rst:518 +#: ../../library/ctypes.rst:526 msgid ">>> libc.time.restype = c_time_t" msgstr ">>> libc.time.restype = c_time_t" -#: ../../library/ctypes.rst:520 +#: ../../library/ctypes.rst:528 msgid "The argument types can be specified using :attr:`~_CFuncPtr.argtypes`::" msgstr "" -#: ../../library/ctypes.rst:522 +#: ../../library/ctypes.rst:530 msgid ">>> libc.time.argtypes = (POINTER(c_time_t),)" msgstr ">>> libc.time.argtypes = (POINTER(c_time_t),)" -#: ../../library/ctypes.rst:524 +#: ../../library/ctypes.rst:532 msgid "" "To call the function with a ``NULL`` pointer as first argument, use " "``None``::" msgstr "" -#: ../../library/ctypes.rst:526 +#: ../../library/ctypes.rst:534 msgid "" ">>> print(libc.time(None))\n" "1150640792" @@ -1110,13 +1130,13 @@ msgstr "" ">>> print(libc.time(None))\n" "1150640792" -#: ../../library/ctypes.rst:529 +#: ../../library/ctypes.rst:537 msgid "" "Here is a more advanced example, it uses the :func:`!strchr` function, which " "expects a string pointer and a char, and returns a pointer to a string::" msgstr "" -#: ../../library/ctypes.rst:532 +#: ../../library/ctypes.rst:540 msgid "" ">>> strchr = libc.strchr\n" ">>> strchr(b\"abcdef\", ord(\"d\"))\n" @@ -1138,14 +1158,14 @@ msgstr "" "None\n" ">>>" -#: ../../library/ctypes.rst:542 +#: ../../library/ctypes.rst:550 msgid "" "If you want to avoid the :func:`ord(\"x\") ` calls above, you can set " "the :attr:`~_CFuncPtr.argtypes` attribute, and the second argument will be " "converted from a single character Python bytes object into a C char:" msgstr "" -#: ../../library/ctypes.rst:546 +#: ../../library/ctypes.rst:554 msgid "" ">>> strchr.restype = c_char_p\n" ">>> strchr.argtypes = [c_char_p, c_char]\n" @@ -1175,7 +1195,7 @@ msgstr "" "b'def'\n" ">>>" -#: ../../library/ctypes.rst:561 +#: ../../library/ctypes.rst:569 msgid "" "You can also use a callable Python object (a function or a class for " "example) as the :attr:`~_CFuncPtr.restype` attribute, if the foreign " @@ -1185,7 +1205,7 @@ msgid "" "values and automatically raise an exception::" msgstr "" -#: ../../library/ctypes.rst:567 +#: ../../library/ctypes.rst:575 msgid "" ">>> GetModuleHandle = windll.kernel32.GetModuleHandleA\n" ">>> def ValidHandle(value):\n" @@ -1221,7 +1241,7 @@ msgstr "" "OSError: [Errno 126] The specified module could not be found.\n" ">>>" -#: ../../library/ctypes.rst:584 +#: ../../library/ctypes.rst:592 msgid "" "``WinError`` is a function which will call Windows ``FormatMessage()`` api " "to get the string representation of an error code, and *returns* an " @@ -1229,18 +1249,18 @@ msgid "" "used, it calls :func:`GetLastError` to retrieve it." msgstr "" -#: ../../library/ctypes.rst:589 +#: ../../library/ctypes.rst:597 msgid "" "Please note that a much more powerful error checking mechanism is available " "through the :attr:`~_CFuncPtr.errcheck` attribute; see the reference manual " "for details." msgstr "" -#: ../../library/ctypes.rst:597 +#: ../../library/ctypes.rst:605 msgid "Passing pointers (or: passing parameters by reference)" msgstr "" -#: ../../library/ctypes.rst:599 +#: ../../library/ctypes.rst:607 msgid "" "Sometimes a C api function expects a *pointer* to a data type as parameter, " "probably to write into the corresponding location, or if the data is too " @@ -1248,7 +1268,7 @@ msgid "" "reference*." msgstr "" -#: ../../library/ctypes.rst:603 +#: ../../library/ctypes.rst:611 msgid "" ":mod:`!ctypes` exports the :func:`byref` function which is used to pass " "parameters by reference. The same effect can be achieved with the :func:" @@ -1257,7 +1277,7 @@ msgid "" "you don't need the pointer object in Python itself::" msgstr "" -#: ../../library/ctypes.rst:609 +#: ../../library/ctypes.rst:617 msgid "" ">>> i = c_int()\n" ">>> f = c_float()\n" @@ -1283,11 +1303,11 @@ msgstr "" "1 3.1400001049 b'Hello'\n" ">>>" -#: ../../library/ctypes.rst:625 +#: ../../library/ctypes.rst:633 msgid "Structures and unions" msgstr "" -#: ../../library/ctypes.rst:627 +#: ../../library/ctypes.rst:635 msgid "" "Structures and unions must derive from the :class:`Structure` and :class:" "`Union` base classes which are defined in the :mod:`!ctypes` module. Each " @@ -1296,20 +1316,20 @@ msgid "" "*field type*." msgstr "" -#: ../../library/ctypes.rst:632 +#: ../../library/ctypes.rst:640 msgid "" "The field type must be a :mod:`!ctypes` type like :class:`c_int`, or any " "other derived :mod:`!ctypes` type: structure, union, array, pointer." msgstr "" -#: ../../library/ctypes.rst:635 +#: ../../library/ctypes.rst:643 msgid "" "Here is a simple example of a POINT structure, which contains two integers " "named *x* and *y*, and also shows how to initialize a structure in the " "constructor::" msgstr "" -#: ../../library/ctypes.rst:638 +#: ../../library/ctypes.rst:646 msgid "" ">>> from ctypes import *\n" ">>> class POINT(Structure):\n" @@ -1345,19 +1365,19 @@ msgstr "" "TypeError: too many initializers\n" ">>>" -#: ../../library/ctypes.rst:655 +#: ../../library/ctypes.rst:663 msgid "" "You can, however, build much more complicated structures. A structure can " "itself contain other structures by using a structure as a field type." msgstr "" -#: ../../library/ctypes.rst:658 +#: ../../library/ctypes.rst:666 msgid "" "Here is a RECT structure which contains two POINTs named *upperleft* and " "*lowerright*::" msgstr "" -#: ../../library/ctypes.rst:661 +#: ../../library/ctypes.rst:669 msgid "" ">>> class RECT(Structure):\n" "... _fields_ = [(\"upperleft\", POINT),\n" @@ -1381,13 +1401,13 @@ msgstr "" "0 0\n" ">>>" -#: ../../library/ctypes.rst:672 +#: ../../library/ctypes.rst:680 msgid "" "Nested structures can also be initialized in the constructor in several " "ways::" msgstr "" -#: ../../library/ctypes.rst:674 +#: ../../library/ctypes.rst:682 msgid "" ">>> r = RECT(POINT(1, 2), POINT(3, 4))\n" ">>> r = RECT((1, 2), (3, 4))" @@ -1395,14 +1415,14 @@ msgstr "" ">>> r = RECT(POINT(1, 2), POINT(3, 4))\n" ">>> r = RECT((1, 2), (3, 4))" -#: ../../library/ctypes.rst:677 +#: ../../library/ctypes.rst:685 msgid "" "Field :term:`descriptor`\\s can be retrieved from the *class*, they are " "useful for debugging because they can provide useful information. See :class:" "`CField`::" msgstr "" -#: ../../library/ctypes.rst:681 +#: ../../library/ctypes.rst:689 msgid "" ">>> POINT.x\n" "\n" @@ -1416,7 +1436,7 @@ msgstr "" "\n" ">>>" -#: ../../library/ctypes.rst:692 +#: ../../library/ctypes.rst:700 msgid "" ":mod:`!ctypes` does not support passing unions or structures with bit-fields " "to functions by value. While this may work on 32-bit x86, it's not " @@ -1424,11 +1444,11 @@ msgid "" "structures with bit-fields should always be passed to functions by pointer." msgstr "" -#: ../../library/ctypes.rst:698 +#: ../../library/ctypes.rst:706 msgid "Structure/union layout, alignment and byte order" msgstr "" -#: ../../library/ctypes.rst:700 +#: ../../library/ctypes.rst:708 msgid "" "By default, Structure and Union fields are laid out in the same way the C " "compiler does it. It is possible to override this behavior entirely by " @@ -1436,7 +1456,7 @@ msgid "" "definition; see the attribute documentation for details." msgstr "" -#: ../../library/ctypes.rst:705 +#: ../../library/ctypes.rst:713 msgid "" "It is possible to specify the maximum alignment for the fields and/or for " "the structure itself by setting the class attributes :attr:`~Structure." @@ -1444,7 +1464,7 @@ msgid "" "documentation for details." msgstr "" -#: ../../library/ctypes.rst:710 +#: ../../library/ctypes.rst:718 msgid "" ":mod:`!ctypes` uses the native byte order for Structures and Unions. To " "build structures with non-native byte order, you can use one of the :class:" @@ -1453,18 +1473,18 @@ msgid "" "classes cannot contain pointer fields." msgstr "" -#: ../../library/ctypes.rst:720 +#: ../../library/ctypes.rst:728 msgid "Bit fields in structures and unions" msgstr "" -#: ../../library/ctypes.rst:722 +#: ../../library/ctypes.rst:730 msgid "" "It is possible to create structures and unions containing bit fields. Bit " "fields are only possible for integer fields, the bit width is specified as " "the third item in the :attr:`~Structure._fields_` tuples::" msgstr "" -#: ../../library/ctypes.rst:726 +#: ../../library/ctypes.rst:734 msgid "" ">>> class Int(Structure):\n" "... _fields_ = [(\"first_16\", c_int, 16),\n" @@ -1484,7 +1504,7 @@ msgstr "" ">>> print(Int.second_16)\n" "" -#: ../../library/ctypes.rst:735 +#: ../../library/ctypes.rst:743 msgid "" "It is important to note that bit field allocation and layout in memory are " "not defined as a C standard; their implementation is compiler-specific. By " @@ -1493,33 +1513,33 @@ msgid "" "details on the default behavior and how to change it." msgstr "" -#: ../../library/ctypes.rst:746 +#: ../../library/ctypes.rst:754 msgid "Arrays" msgstr "" -#: ../../library/ctypes.rst:748 +#: ../../library/ctypes.rst:756 msgid "" "Arrays are sequences, containing a fixed number of instances of the same " "type." msgstr "" -#: ../../library/ctypes.rst:750 +#: ../../library/ctypes.rst:758 msgid "" "The recommended way to create array types is by multiplying a data type with " "a positive integer::" msgstr "" -#: ../../library/ctypes.rst:753 +#: ../../library/ctypes.rst:761 msgid "TenPointsArrayType = POINT * 10" msgstr "" -#: ../../library/ctypes.rst:755 +#: ../../library/ctypes.rst:763 msgid "" "Here is an example of a somewhat artificial data type, a structure " "containing 4 POINTs among other stuff::" msgstr "" -#: ../../library/ctypes.rst:758 +#: ../../library/ctypes.rst:766 msgid "" ">>> from ctypes import *\n" ">>> class POINT(Structure):\n" @@ -1547,11 +1567,11 @@ msgstr "" "4\n" ">>>" -#: ../../library/ctypes.rst:771 +#: ../../library/ctypes.rst:779 msgid "Instances are created in the usual way, by calling the class::" msgstr "" -#: ../../library/ctypes.rst:773 +#: ../../library/ctypes.rst:781 msgid "" "arr = TenPointsArrayType()\n" "for pt in arr:\n" @@ -1561,17 +1581,17 @@ msgstr "" "for pt in arr:\n" " print(pt.x, pt.y)" -#: ../../library/ctypes.rst:777 +#: ../../library/ctypes.rst:785 msgid "" "The above code print a series of ``0 0`` lines, because the array contents " "is initialized to zeros." msgstr "" -#: ../../library/ctypes.rst:780 +#: ../../library/ctypes.rst:788 msgid "Initializers of the correct type can also be specified::" msgstr "" -#: ../../library/ctypes.rst:782 +#: ../../library/ctypes.rst:790 msgid "" ">>> from ctypes import *\n" ">>> TenIntegers = c_int * 10\n" @@ -1593,17 +1613,17 @@ msgstr "" "1 2 3 4 5 6 7 8 9 10\n" ">>>" -#: ../../library/ctypes.rst:796 +#: ../../library/ctypes.rst:804 msgid "Pointers" msgstr "指標" -#: ../../library/ctypes.rst:798 +#: ../../library/ctypes.rst:806 msgid "" "Pointer instances are created by calling the :func:`pointer` function on a :" "mod:`!ctypes` type::" msgstr "" -#: ../../library/ctypes.rst:801 +#: ../../library/ctypes.rst:809 msgid "" ">>> from ctypes import *\n" ">>> i = c_int(42)\n" @@ -1615,13 +1635,13 @@ msgstr "" ">>> pi = pointer(i)\n" ">>>" -#: ../../library/ctypes.rst:806 +#: ../../library/ctypes.rst:814 msgid "" "Pointer instances have a :attr:`~_Pointer.contents` attribute which returns " "the object to which the pointer points, the ``i`` object above::" msgstr "" -#: ../../library/ctypes.rst:809 +#: ../../library/ctypes.rst:817 msgid "" ">>> pi.contents\n" "c_long(42)\n" @@ -1631,13 +1651,13 @@ msgstr "" "c_long(42)\n" ">>>" -#: ../../library/ctypes.rst:813 +#: ../../library/ctypes.rst:821 msgid "" "Note that :mod:`!ctypes` does not have OOR (original object return), it " "constructs a new, equivalent object each time you retrieve an attribute::" msgstr "" -#: ../../library/ctypes.rst:816 +#: ../../library/ctypes.rst:824 msgid "" ">>> pi.contents is i\n" "False\n" @@ -1651,14 +1671,14 @@ msgstr "" "False\n" ">>>" -#: ../../library/ctypes.rst:822 +#: ../../library/ctypes.rst:830 msgid "" "Assigning another :class:`c_int` instance to the pointer's contents " "attribute would cause the pointer to point to the memory location where this " "is stored::" msgstr "" -#: ../../library/ctypes.rst:825 +#: ../../library/ctypes.rst:833 msgid "" ">>> i = c_int(99)\n" ">>> pi.contents = i\n" @@ -1672,11 +1692,11 @@ msgstr "" "c_long(99)\n" ">>>" -#: ../../library/ctypes.rst:834 +#: ../../library/ctypes.rst:842 msgid "Pointer instances can also be indexed with integers::" msgstr "" -#: ../../library/ctypes.rst:836 +#: ../../library/ctypes.rst:844 msgid "" ">>> pi[0]\n" "99\n" @@ -1686,11 +1706,11 @@ msgstr "" "99\n" ">>>" -#: ../../library/ctypes.rst:840 +#: ../../library/ctypes.rst:848 msgid "Assigning to an integer index changes the pointed to value::" msgstr "" -#: ../../library/ctypes.rst:842 +#: ../../library/ctypes.rst:850 msgid "" ">>> print(i)\n" "c_long(99)\n" @@ -1706,7 +1726,7 @@ msgstr "" "c_long(22)\n" ">>>" -#: ../../library/ctypes.rst:849 +#: ../../library/ctypes.rst:857 msgid "" "It is also possible to use indexes different from 0, but you must know what " "you're doing, just as in C: You can access or change arbitrary memory " @@ -1715,7 +1735,7 @@ msgid "" "instead of a single item." msgstr "" -#: ../../library/ctypes.rst:855 +#: ../../library/ctypes.rst:863 msgid "" "Behind the scenes, the :func:`pointer` function does more than simply create " "pointer instances, it has to create pointer *types* first. This is done with " @@ -1723,7 +1743,7 @@ msgid "" "returns a new type::" msgstr "" -#: ../../library/ctypes.rst:860 +#: ../../library/ctypes.rst:868 msgid "" ">>> PI = POINTER(c_int)\n" ">>> PI\n" @@ -1747,13 +1767,13 @@ msgstr "" "\n" ">>>" -#: ../../library/ctypes.rst:871 +#: ../../library/ctypes.rst:879 msgid "" "Calling the pointer type without an argument creates a ``NULL`` pointer. " "``NULL`` pointers have a ``False`` boolean value::" msgstr "" -#: ../../library/ctypes.rst:874 +#: ../../library/ctypes.rst:882 msgid "" ">>> null_ptr = POINTER(c_int)()\n" ">>> print(bool(null_ptr))\n" @@ -1765,13 +1785,13 @@ msgstr "" "False\n" ">>>" -#: ../../library/ctypes.rst:879 +#: ../../library/ctypes.rst:887 msgid "" ":mod:`!ctypes` checks for ``NULL`` when dereferencing pointers (but " "dereferencing invalid non-\\ ``NULL`` pointers would crash Python)::" msgstr "" -#: ../../library/ctypes.rst:882 +#: ../../library/ctypes.rst:890 msgid "" ">>> null_ptr[0]\n" "Traceback (most recent call last):\n" @@ -1797,18 +1817,18 @@ msgstr "" "ValueError: NULL pointer access\n" ">>>" -#: ../../library/ctypes.rst:897 +#: ../../library/ctypes.rst:905 msgid "Thread safety without the GIL" msgstr "" -#: ../../library/ctypes.rst:899 +#: ../../library/ctypes.rst:907 msgid "" "From Python 3.13 onward, the :term:`GIL` can be disabled on the :term:`free-" "threaded build`. In ctypes, reads and writes to a single object concurrently " "is safe, but not across multiple objects:" msgstr "" -#: ../../library/ctypes.rst:902 +#: ../../library/ctypes.rst:910 msgid "" ">>> number = c_int(42)\n" ">>> pointer_a = pointer(number)\n" @@ -1818,7 +1838,7 @@ msgstr "" ">>> pointer_a = pointer(number)\n" ">>> pointer_b = pointer(number)" -#: ../../library/ctypes.rst:908 +#: ../../library/ctypes.rst:916 msgid "" "In the above, it's only safe for one object to read and write to the address " "at once if the GIL is disabled. So, ``pointer_a`` can be shared and written " @@ -1827,7 +1847,7 @@ msgid "" "Lock` to synchronize access to memory:" msgstr "" -#: ../../library/ctypes.rst:913 +#: ../../library/ctypes.rst:921 msgid "" ">>> import threading\n" ">>> lock = threading.Lock()\n" @@ -1847,11 +1867,11 @@ msgstr "" ">>> with lock:\n" "... pointer_b.contents = 42" -#: ../../library/ctypes.rst:928 +#: ../../library/ctypes.rst:936 msgid "Type conversions" msgstr "" -#: ../../library/ctypes.rst:930 +#: ../../library/ctypes.rst:938 msgid "" "Usually, ctypes does strict type checking. This means, if you have " "``POINTER(c_int)`` in the :attr:`~_CFuncPtr.argtypes` list of a function or " @@ -1862,7 +1882,7 @@ msgid "" "ctypes accepts an array of c_int::" msgstr "" -#: ../../library/ctypes.rst:937 +#: ../../library/ctypes.rst:945 msgid "" ">>> class Bar(Structure):\n" "... _fields_ = [(\"count\", c_int), (\"values\", POINTER(c_int))]\n" @@ -1892,7 +1912,7 @@ msgstr "" "3\n" ">>>" -#: ../../library/ctypes.rst:951 +#: ../../library/ctypes.rst:959 msgid "" "In addition, if a function argument is explicitly declared to be a pointer " "type (such as ``POINTER(c_int)``) in :attr:`~_CFuncPtr.argtypes`, an object " @@ -1901,11 +1921,11 @@ msgid "" "automatically." msgstr "" -#: ../../library/ctypes.rst:956 +#: ../../library/ctypes.rst:964 msgid "To set a POINTER type field to ``NULL``, you can assign ``None``::" msgstr "" -#: ../../library/ctypes.rst:958 +#: ../../library/ctypes.rst:966 msgid "" ">>> bar.values = None\n" ">>>" @@ -1913,7 +1933,7 @@ msgstr "" ">>> bar.values = None\n" ">>>" -#: ../../library/ctypes.rst:963 +#: ../../library/ctypes.rst:971 msgid "" "Sometimes you have instances of incompatible types. In C, you can cast one " "type into another type. :mod:`!ctypes` provides a :func:`cast` function " @@ -1922,7 +1942,7 @@ msgid "" "``values`` field, but not instances of other types::" msgstr "" -#: ../../library/ctypes.rst:969 +#: ../../library/ctypes.rst:977 msgid "" ">>> bar.values = (c_byte * 4)()\n" "Traceback (most recent call last):\n" @@ -1938,11 +1958,11 @@ msgstr "" "instance\n" ">>>" -#: ../../library/ctypes.rst:975 +#: ../../library/ctypes.rst:983 msgid "For these cases, the :func:`cast` function is handy." msgstr "" -#: ../../library/ctypes.rst:977 +#: ../../library/ctypes.rst:985 msgid "" "The :func:`cast` function can be used to cast a ctypes instance into a " "pointer to a different ctypes data type. :func:`cast` takes two parameters, " @@ -1951,7 +1971,7 @@ msgid "" "references the same memory block as the first argument::" msgstr "" -#: ../../library/ctypes.rst:983 +#: ../../library/ctypes.rst:991 msgid "" ">>> a = (c_byte * 4)()\n" ">>> cast(a, POINTER(c_int))\n" @@ -1963,13 +1983,13 @@ msgstr "" "\n" ">>>" -#: ../../library/ctypes.rst:988 +#: ../../library/ctypes.rst:996 msgid "" "So, :func:`cast` can be used to assign to the ``values`` field of ``Bar`` " "the structure::" msgstr "" -#: ../../library/ctypes.rst:991 +#: ../../library/ctypes.rst:999 msgid "" ">>> bar = Bar()\n" ">>> bar.values = cast((c_byte * 4)(), POINTER(c_int))\n" @@ -1983,18 +2003,18 @@ msgstr "" "0\n" ">>>" -#: ../../library/ctypes.rst:1001 +#: ../../library/ctypes.rst:1009 msgid "Incomplete Types" msgstr "" -#: ../../library/ctypes.rst:1003 +#: ../../library/ctypes.rst:1011 msgid "" "*Incomplete Types* are structures, unions or arrays whose members are not " "yet specified. In C, they are specified by forward declarations, which are " "defined later::" msgstr "" -#: ../../library/ctypes.rst:1007 +#: ../../library/ctypes.rst:1015 msgid "" "struct cell; /* forward declaration */\n" "\n" @@ -2004,13 +2024,13 @@ msgid "" "};" msgstr "" -#: ../../library/ctypes.rst:1014 +#: ../../library/ctypes.rst:1022 msgid "" "The straightforward translation into ctypes code would be this, but it does " "not work::" msgstr "" -#: ../../library/ctypes.rst:1017 +#: ../../library/ctypes.rst:1025 msgid "" ">>> class cell(Structure):\n" "... _fields_ = [(\"name\", c_char_p),\n" @@ -2032,14 +2052,14 @@ msgstr "" "NameError: name 'cell' is not defined\n" ">>>" -#: ../../library/ctypes.rst:1027 +#: ../../library/ctypes.rst:1035 msgid "" "because the new ``class cell`` is not available in the class statement " "itself. In :mod:`!ctypes`, we can define the ``cell`` class and set the :" "attr:`~Structure._fields_` attribute later, after the class statement::" msgstr "" -#: ../../library/ctypes.rst:1031 +#: ../../library/ctypes.rst:1039 msgid "" ">>> from ctypes import *\n" ">>> class cell(Structure):\n" @@ -2057,13 +2077,13 @@ msgstr "" "... (\"next\", POINTER(cell))]\n" ">>>" -#: ../../library/ctypes.rst:1039 +#: ../../library/ctypes.rst:1047 msgid "" "Let's try it. We create two instances of ``cell``, and let them point to " "each other, and finally follow the pointer chain a few times::" msgstr "" -#: ../../library/ctypes.rst:1042 +#: ../../library/ctypes.rst:1050 msgid "" ">>> c1 = cell()\n" ">>> c1.name = b\"foo\"\n" @@ -2093,24 +2113,24 @@ msgstr "" "foo bar foo bar foo bar foo bar\n" ">>>" -#: ../../library/ctypes.rst:1060 +#: ../../library/ctypes.rst:1068 msgid "Callback functions" msgstr "回呼函式" -#: ../../library/ctypes.rst:1062 +#: ../../library/ctypes.rst:1070 msgid "" ":mod:`!ctypes` allows creating C callable function pointers from Python " "callables. These are sometimes called *callback functions*." msgstr "" -#: ../../library/ctypes.rst:1065 +#: ../../library/ctypes.rst:1073 msgid "" "First, you must create a class for the callback function. The class knows " "the calling convention, the return type, and the number and types of " "arguments this function will receive." msgstr "" -#: ../../library/ctypes.rst:1069 +#: ../../library/ctypes.rst:1077 msgid "" "The :func:`CFUNCTYPE` factory function creates types for callback functions " "using the ``cdecl`` calling convention. On Windows, the :func:`WINFUNCTYPE` " @@ -2118,21 +2138,21 @@ msgid "" "calling convention." msgstr "" -#: ../../library/ctypes.rst:1074 +#: ../../library/ctypes.rst:1082 msgid "" "Both of these factory functions are called with the result type as first " "argument, and the callback functions expected argument types as the " "remaining arguments." msgstr "" -#: ../../library/ctypes.rst:1078 +#: ../../library/ctypes.rst:1086 msgid "" "I will present an example here which uses the standard C library's :c:func:`!" "qsort` function, that is used to sort items with the help of a callback " "function. :c:func:`!qsort` will be used to sort an array of integers::" msgstr "" -#: ../../library/ctypes.rst:1082 +#: ../../library/ctypes.rst:1090 msgid "" ">>> IntArray5 = c_int * 5\n" ">>> ia = IntArray5(5, 1, 7, 33, 99)\n" @@ -2146,7 +2166,7 @@ msgstr "" ">>> qsort.restype = None\n" ">>>" -#: ../../library/ctypes.rst:1088 +#: ../../library/ctypes.rst:1096 msgid "" ":func:`!qsort` must be called with a pointer to the data to sort, the number " "of items in the data array, the size of one item, and a pointer to the " @@ -2156,13 +2176,13 @@ msgid "" "otherwise." msgstr "" -#: ../../library/ctypes.rst:1094 +#: ../../library/ctypes.rst:1102 msgid "" "So our callback function receives pointers to integers, and must return an " "integer. First we create the ``type`` for the callback function::" msgstr "" -#: ../../library/ctypes.rst:1097 +#: ../../library/ctypes.rst:1105 msgid "" ">>> CMPFUNC = CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))\n" ">>>" @@ -2170,13 +2190,13 @@ msgstr "" ">>> CMPFUNC = CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))\n" ">>>" -#: ../../library/ctypes.rst:1100 +#: ../../library/ctypes.rst:1108 msgid "" "To get started, here is a simple callback that shows the values it gets " "passed::" msgstr "" -#: ../../library/ctypes.rst:1103 +#: ../../library/ctypes.rst:1111 msgid "" ">>> def py_cmp_func(a, b):\n" "... print(\"py_cmp_func\", a[0], b[0])\n" @@ -2192,11 +2212,11 @@ msgstr "" ">>> cmp_func = CMPFUNC(py_cmp_func)\n" ">>>" -#: ../../library/ctypes.rst:1110 +#: ../../library/ctypes.rst:1118 msgid "The result::" msgstr "結果為: ::" -#: ../../library/ctypes.rst:1112 +#: ../../library/ctypes.rst:1120 msgid "" ">>> qsort(ia, len(ia), sizeof(c_int), cmp_func)\n" "py_cmp_func 5 1\n" @@ -2214,11 +2234,11 @@ msgstr "" "py_cmp_func 1 7\n" ">>>" -#: ../../library/ctypes.rst:1120 +#: ../../library/ctypes.rst:1128 msgid "Now we can actually compare the two items and return a useful result::" msgstr "" -#: ../../library/ctypes.rst:1122 +#: ../../library/ctypes.rst:1130 msgid "" ">>> def py_cmp_func(a, b):\n" "... print(\"py_cmp_func\", a[0], b[0])\n" @@ -2246,11 +2266,11 @@ msgstr "" "py_cmp_func 5 7\n" ">>>" -#: ../../library/ctypes.rst:1135 +#: ../../library/ctypes.rst:1143 msgid "As we can easily check, our array is sorted now::" msgstr "" -#: ../../library/ctypes.rst:1137 +#: ../../library/ctypes.rst:1145 msgid "" ">>> for i in ia: print(i, end=\" \")\n" "...\n" @@ -2262,13 +2282,13 @@ msgstr "" "1 5 7 33 99\n" ">>>" -#: ../../library/ctypes.rst:1142 +#: ../../library/ctypes.rst:1150 msgid "" "The function factories can be used as decorator factories, so we may as well " "write::" msgstr "" -#: ../../library/ctypes.rst:1145 +#: ../../library/ctypes.rst:1153 msgid "" ">>> @CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))\n" "... def py_cmp_func(a, b):\n" @@ -2296,14 +2316,14 @@ msgstr "" "py_cmp_func 5 7\n" ">>>" -#: ../../library/ctypes.rst:1160 +#: ../../library/ctypes.rst:1168 msgid "" "Make sure you keep references to :func:`CFUNCTYPE` objects as long as they " "are used from C code. :mod:`!ctypes` doesn't, and if you don't, they may be " "garbage collected, crashing your program when a callback is made." msgstr "" -#: ../../library/ctypes.rst:1164 +#: ../../library/ctypes.rst:1172 msgid "" "Also, note that if the callback function is called in a thread created " "outside of Python's control (e.g. by the foreign code that calls the " @@ -2313,25 +2333,25 @@ msgid "" "even when those calls are made from the same C thread." msgstr "" -#: ../../library/ctypes.rst:1174 +#: ../../library/ctypes.rst:1182 msgid "Accessing values exported from dlls" msgstr "" -#: ../../library/ctypes.rst:1176 +#: ../../library/ctypes.rst:1184 msgid "" "Some shared libraries not only export functions, they also export variables. " "An example in the Python library itself is the :c:data:`Py_Version`, Python " "runtime version number encoded in a single constant integer." msgstr "" -#: ../../library/ctypes.rst:1180 +#: ../../library/ctypes.rst:1188 msgid "" ":mod:`!ctypes` can access values like this with the :meth:`~_CData.in_dll` " "class methods of the type. *pythonapi* is a predefined symbol giving access " "to the Python C api::" msgstr "" -#: ../../library/ctypes.rst:1184 +#: ../../library/ctypes.rst:1192 msgid "" ">>> version = ctypes.c_int.in_dll(ctypes.pythonapi, \"Py_Version\")\n" ">>> print(hex(version.value))\n" @@ -2341,17 +2361,17 @@ msgstr "" ">>> print(hex(version.value))\n" "0x30c00a0" -#: ../../library/ctypes.rst:1188 +#: ../../library/ctypes.rst:1196 msgid "" "An extended example which also demonstrates the use of pointers accesses " "the :c:data:`PyImport_FrozenModules` pointer exported by Python." msgstr "" -#: ../../library/ctypes.rst:1191 +#: ../../library/ctypes.rst:1199 msgid "Quoting the docs for that value:" msgstr "" -#: ../../library/ctypes.rst:1193 +#: ../../library/ctypes.rst:1201 msgid "" "This pointer is initialized to point to an array of :c:struct:`_frozen` " "records, terminated by one whose members are all ``NULL`` or zero. When a " @@ -2360,13 +2380,13 @@ msgid "" "frozen modules." msgstr "" -#: ../../library/ctypes.rst:1198 +#: ../../library/ctypes.rst:1206 msgid "" "So manipulating this pointer could even prove useful. To restrict the " "example size, we show only how this table can be read with :mod:`!ctypes`::" msgstr "" -#: ../../library/ctypes.rst:1201 +#: ../../library/ctypes.rst:1209 msgid "" ">>> from ctypes import *\n" ">>>\n" @@ -2390,13 +2410,13 @@ msgstr "" "...\n" ">>>" -#: ../../library/ctypes.rst:1212 +#: ../../library/ctypes.rst:1220 msgid "" "We have defined the :c:struct:`_frozen` data type, so we can get the pointer " "to the table::" msgstr "" -#: ../../library/ctypes.rst:1215 +#: ../../library/ctypes.rst:1223 msgid "" ">>> FrozenTable = POINTER(struct_frozen)\n" ">>> table = FrozenTable.in_dll(pythonapi, \"_PyImport_FrozenBootstrap\")\n" @@ -2406,7 +2426,7 @@ msgstr "" ">>> table = FrozenTable.in_dll(pythonapi, \"_PyImport_FrozenBootstrap\")\n" ">>>" -#: ../../library/ctypes.rst:1219 +#: ../../library/ctypes.rst:1227 msgid "" "Since ``table`` is a ``pointer`` to the array of ``struct_frozen`` records, " "we can iterate over it, but we just have to make sure that our loop " @@ -2415,7 +2435,7 @@ msgid "" "the loop when we hit the ``NULL`` entry::" msgstr "" -#: ../../library/ctypes.rst:1225 +#: ../../library/ctypes.rst:1233 msgid "" ">>> for item in table:\n" "... if item.name is None:\n" @@ -2437,28 +2457,28 @@ msgstr "" "zipimport 12345\n" ">>>" -#: ../../library/ctypes.rst:1235 +#: ../../library/ctypes.rst:1243 msgid "" "The fact that standard Python has a frozen module and a frozen package " "(indicated by the negative ``size`` member) is not well known, it is only " "used for testing. Try it out with ``import __hello__`` for example." msgstr "" -#: ../../library/ctypes.rst:1243 +#: ../../library/ctypes.rst:1251 msgid "Surprises" msgstr "" -#: ../../library/ctypes.rst:1245 +#: ../../library/ctypes.rst:1253 msgid "" "There are some edges in :mod:`!ctypes` where you might expect something " "other than what actually happens." msgstr "" -#: ../../library/ctypes.rst:1248 +#: ../../library/ctypes.rst:1256 msgid "Consider the following example::" msgstr "" -#: ../../library/ctypes.rst:1250 +#: ../../library/ctypes.rst:1258 msgid "" ">>> from ctypes import *\n" ">>> class POINT(Structure):\n" @@ -2496,13 +2516,13 @@ msgstr "" "3 4 3 4\n" ">>>" -#: ../../library/ctypes.rst:1268 +#: ../../library/ctypes.rst:1276 msgid "" "Hm. We certainly expected the last statement to print ``3 4 1 2``. What " "happened? Here are the steps of the ``rc.a, rc.b = rc.b, rc.a`` line above::" msgstr "" -#: ../../library/ctypes.rst:1271 +#: ../../library/ctypes.rst:1279 msgid "" ">>> temp0, temp1 = rc.b, rc.a\n" ">>> rc.a = temp0\n" @@ -2514,7 +2534,7 @@ msgstr "" ">>> rc.b = temp1\n" ">>>" -#: ../../library/ctypes.rst:1276 +#: ../../library/ctypes.rst:1284 msgid "" "Note that ``temp0`` and ``temp1`` are objects still using the internal " "buffer of the ``rc`` object above. So executing ``rc.a = temp0`` copies the " @@ -2523,20 +2543,20 @@ msgid "" "have the expected effect." msgstr "" -#: ../../library/ctypes.rst:1282 +#: ../../library/ctypes.rst:1290 msgid "" "Keep in mind that retrieving sub-objects from Structure, Unions, and Arrays " "doesn't *copy* the sub-object, instead it retrieves a wrapper object " "accessing the root-object's underlying buffer." msgstr "" -#: ../../library/ctypes.rst:1286 +#: ../../library/ctypes.rst:1294 msgid "" "Another example that may behave differently from what one would expect is " "this::" msgstr "" -#: ../../library/ctypes.rst:1288 +#: ../../library/ctypes.rst:1296 msgid "" ">>> s = c_char_p()\n" ">>> s.value = b\"abc def ghi\"\n" @@ -2554,13 +2574,13 @@ msgstr "" "False\n" ">>>" -#: ../../library/ctypes.rst:1298 +#: ../../library/ctypes.rst:1306 msgid "" "Objects instantiated from :class:`c_char_p` can only have their value set to " "bytes or integers." msgstr "" -#: ../../library/ctypes.rst:1301 +#: ../../library/ctypes.rst:1309 msgid "" "Why is it printing ``False``? ctypes instances are objects containing a " "memory block plus some :term:`descriptor`\\s accessing the contents of the " @@ -2569,17 +2589,17 @@ msgid "" "the contents again constructs a new Python object each time!" msgstr "" -#: ../../library/ctypes.rst:1311 +#: ../../library/ctypes.rst:1319 msgid "Variable-sized data types" msgstr "" -#: ../../library/ctypes.rst:1313 +#: ../../library/ctypes.rst:1321 msgid "" ":mod:`!ctypes` provides some support for variable-sized arrays and " "structures." msgstr "" -#: ../../library/ctypes.rst:1315 +#: ../../library/ctypes.rst:1323 msgid "" "The :func:`resize` function can be used to resize the memory buffer of an " "existing ctypes object. The function takes the object as first argument, " @@ -2588,7 +2608,7 @@ msgid "" "objects type, a :exc:`ValueError` is raised if this is tried::" msgstr "" -#: ../../library/ctypes.rst:1321 +#: ../../library/ctypes.rst:1329 msgid "" ">>> short_array = (c_short * 4)()\n" ">>> print(sizeof(short_array))\n" @@ -2618,14 +2638,14 @@ msgstr "" "8\n" ">>>" -#: ../../library/ctypes.rst:1335 +#: ../../library/ctypes.rst:1343 msgid "" "This is nice and fine, but how would one access the additional elements " "contained in this array? Since the type still only knows about 4 elements, " "we get errors accessing other elements::" msgstr "" -#: ../../library/ctypes.rst:1339 +#: ../../library/ctypes.rst:1347 msgid "" ">>> short_array[:]\n" "[0, 0, 0, 0]\n" @@ -2643,28 +2663,28 @@ msgstr "" "IndexError: invalid index\n" ">>>" -#: ../../library/ctypes.rst:1347 +#: ../../library/ctypes.rst:1355 msgid "" "Another way to use variable-sized data types with :mod:`!ctypes` is to use " "the dynamic nature of Python, and (re-)define the data type after the " "required size is already known, on a case by case basis." msgstr "" -#: ../../library/ctypes.rst:1355 +#: ../../library/ctypes.rst:1363 msgid "ctypes reference" msgstr "" -#: ../../library/ctypes.rst:1361 +#: ../../library/ctypes.rst:1369 msgid "Finding shared libraries" msgstr "" -#: ../../library/ctypes.rst:1363 +#: ../../library/ctypes.rst:1371 msgid "" "When programming in a compiled language, shared libraries are accessed when " "compiling/linking a program, and when the program is run." msgstr "" -#: ../../library/ctypes.rst:1366 +#: ../../library/ctypes.rst:1374 msgid "" "The purpose of the :func:`~ctypes.util.find_library` function is to locate a " "library in a way similar to what the compiler or runtime loader does (on " @@ -2673,13 +2693,13 @@ msgid "" "and call the runtime loader directly." msgstr "" -#: ../../library/ctypes.rst:1372 +#: ../../library/ctypes.rst:1380 msgid "" "The :mod:`!ctypes.util` module provides a function which can help to " "determine the library to load." msgstr "" -#: ../../library/ctypes.rst:1380 +#: ../../library/ctypes.rst:1388 msgid "" "Try to find a library and return a pathname. *name* is the library name " "without any prefix like *lib*, suffix like ``.so``, ``.dylib`` or version " @@ -2687,35 +2707,35 @@ msgid "" "If no library can be found, returns ``None``." msgstr "" -#: ../../library/ctypes.rst:1385 ../../library/ctypes.rst:2136 +#: ../../library/ctypes.rst:1393 ../../library/ctypes.rst:2152 msgid "The exact functionality is system dependent." msgstr "" -#: ../../library/ctypes.rst:1387 +#: ../../library/ctypes.rst:1395 msgid "" "On Linux, :func:`~ctypes.util.find_library` tries to run external programs " "(``/sbin/ldconfig``, ``gcc``, ``objdump`` and ``ld``) to find the library " "file. It returns the filename of the library file." msgstr "" -#: ../../library/ctypes.rst:1391 +#: ../../library/ctypes.rst:1399 msgid "" "Note that if the output of these programs does not correspond to the dynamic " "linker used by Python, the result of this function may be misleading." msgstr "" -#: ../../library/ctypes.rst:1394 +#: ../../library/ctypes.rst:1402 msgid "" "On Linux, the value of the environment variable ``LD_LIBRARY_PATH`` is used " "when searching for libraries, if a library cannot be found by any other " "means." msgstr "" -#: ../../library/ctypes.rst:1398 +#: ../../library/ctypes.rst:1406 msgid "Here are some examples::" msgstr "以下是一些範例: ::" -#: ../../library/ctypes.rst:1400 +#: ../../library/ctypes.rst:1408 msgid "" ">>> from ctypes.util import find_library\n" ">>> find_library(\"m\")\n" @@ -2735,14 +2755,14 @@ msgstr "" "'libbz2.so.1.0'\n" ">>>" -#: ../../library/ctypes.rst:1409 +#: ../../library/ctypes.rst:1417 msgid "" "On macOS and Android, :func:`~ctypes.util.find_library` uses the system's " "standard naming schemes and paths to locate the library, and returns a full " "pathname if successful::" msgstr "" -#: ../../library/ctypes.rst:1413 +#: ../../library/ctypes.rst:1421 msgid "" ">>> from ctypes.util import find_library\n" ">>> find_library(\"c\")\n" @@ -2766,7 +2786,7 @@ msgstr "" "'/System/Library/Frameworks/AGL.framework/AGL'\n" ">>>" -#: ../../library/ctypes.rst:1424 +#: ../../library/ctypes.rst:1432 msgid "" "On Windows, :func:`~ctypes.util.find_library` searches along the system " "search path, and returns the full pathname, but since there is no predefined " @@ -2774,7 +2794,7 @@ msgid "" "``None``." msgstr "" -#: ../../library/ctypes.rst:1428 +#: ../../library/ctypes.rst:1436 msgid "" "If wrapping a shared library with :mod:`!ctypes`, it *may* be better to " "determine the shared library name at development time, and hardcode that " @@ -2782,18 +2802,18 @@ msgid "" "to locate the library at runtime." msgstr "" -#: ../../library/ctypes.rst:1436 +#: ../../library/ctypes.rst:1444 msgid "Listing loaded shared libraries" msgstr "" -#: ../../library/ctypes.rst:1438 +#: ../../library/ctypes.rst:1446 msgid "" "When writing code that relies on code loaded from shared libraries, it can " "be useful to know which shared libraries have already been loaded into the " "current process." msgstr "" -#: ../../library/ctypes.rst:1442 +#: ../../library/ctypes.rst:1450 msgid "" "The :mod:`!ctypes.util` module provides the :func:`~ctypes.util.dllist` " "function, which calls the different APIs provided by the various platforms " @@ -2801,7 +2821,7 @@ msgid "" "current process." msgstr "" -#: ../../library/ctypes.rst:1446 +#: ../../library/ctypes.rst:1454 msgid "" "The exact output of this function will be system dependent. On most " "platforms, the first entry of this list represents the current process " @@ -2809,7 +2829,7 @@ msgid "" "return may look like::" msgstr "" -#: ../../library/ctypes.rst:1451 +#: ../../library/ctypes.rst:1459 msgid "" ">>> from ctypes.util import dllist\n" ">>> dllist()\n" @@ -2821,110 +2841,86 @@ msgstr "" "['', 'linux-vdso.so.1', '/lib/x86_64-linux-gnu/libm.so.6', '/lib/x86_64-" "linux-gnu/libc.so.6', ... ]" -#: ../../library/ctypes.rst:1458 +#: ../../library/ctypes.rst:1466 msgid "Loading shared libraries" msgstr "" -#: ../../library/ctypes.rst:1460 +#: ../../library/ctypes.rst:1468 msgid "" "There are several ways to load shared libraries into the Python process. " -"One way is to instantiate one of the following classes:" +"One way is to instantiate :py:class:`CDLL` or one of its subclasses:" msgstr "" -#: ../../library/ctypes.rst:1466 -msgid "" -"Instances of this class represent loaded shared libraries. Functions in " -"these libraries use the standard C calling convention, and are assumed to " -"return :c:expr:`int`." +#: ../../library/ctypes.rst:1474 +msgid "Represents a loaded shared library." msgstr "" -#: ../../library/ctypes.rst:1470 +#: ../../library/ctypes.rst:1476 msgid "" -"On Windows creating a :class:`CDLL` instance may fail even if the DLL name " -"exists. When a dependent DLL of the loaded DLL is not found, a :exc:" -"`OSError` error is raised with the message *\"[WinError 126] The specified " -"module could not be found\".* This error message does not contain the name " -"of the missing DLL because the Windows API does not return this information " -"making this error hard to diagnose. To resolve this error and determine " -"which DLL is not found, you need to find the list of dependent DLLs and " -"determine which one is not found using Windows debugging and tracing tools." -msgstr "" - -#: ../../library/ctypes.rst:1482 ../../library/ctypes.rst:1507 -#: ../../library/ctypes.rst:1520 ../../library/ctypes.rst:1538 -msgid "The *name* parameter can now be a :term:`path-like object`." +"Functions in this library use the standard C calling convention, and are " +"assumed to return :c:expr:`int`. The Python :term:`global interpreter lock` " +"is released before calling any function exported by these libraries, and " +"reacquired afterwards. For different function behavior, use a subclass: :py:" +"class:`~ctypes.OleDLL`, :py:class:`~ctypes.WinDLL`, or :py:class:`~ctypes." +"PyDLL`." msgstr "" -#: ../../library/ctypes.rst:1486 +#: ../../library/ctypes.rst:1483 msgid "" -"`Microsoft DUMPBIN tool `_ -- A tool to find DLL dependents." +"If you have an existing :py:attr:`handle ` to an " +"already loaded shared library, it can be passed as the *handle* argument to " +"wrap the opened library in a new :py:class:`!CDLL` object. In this case, " +"*name* is only used to set the :py:attr:`~ctypes.CDLL._name` attribute, but " +"it may be adjusted and/or validated." msgstr "" -#: ../../library/ctypes.rst:1492 +#: ../../library/ctypes.rst:1489 msgid "" -"Instances of this class represent loaded shared libraries, functions in " -"these libraries use the ``stdcall`` calling convention, and are assumed to " -"return the windows specific :class:`HRESULT` code. :class:`HRESULT` values " -"contain information specifying whether the function call failed or " -"succeeded, together with additional error code. If the return value signals " -"a failure, an :class:`OSError` is automatically raised." +"If *handle* is ``None``, the underlying platform's :manpage:`dlopen(3)` or :" +"c:func:`!LoadLibrary` function is used to load the library into the process, " +"and to get a handle to it." msgstr "" -#: ../../library/ctypes.rst:1499 ../../library/ctypes.rst:1516 -#: ../../library/ctypes.rst:1660 ../../library/ctypes.rst:1668 -#: ../../library/ctypes.rst:1840 ../../library/ctypes.rst:1892 -#: ../../library/ctypes.rst:2044 ../../library/ctypes.rst:2116 -#: ../../library/ctypes.rst:2125 ../../library/ctypes.rst:2152 -#: ../../library/ctypes.rst:2166 ../../library/ctypes.rst:2175 -#: ../../library/ctypes.rst:2184 ../../library/ctypes.rst:2199 -#: ../../library/ctypes.rst:2266 ../../library/ctypes.rst:2293 -#: ../../library/ctypes.rst:2693 ../../library/ctypes.rst:3111 -msgid "Availability" -msgstr "可用性" - -#: ../../library/ctypes.rst:1501 +#: ../../library/ctypes.rst:1493 msgid "" -":exc:`WindowsError` used to be raised, which is now an alias of :exc:" -"`OSError`." +"*name* is the pathname of the shared library to open. If *name* does not " +"contain a path separator, the library is found in a platform-specific way." msgstr "" -#: ../../library/ctypes.rst:1512 +#: ../../library/ctypes.rst:1497 msgid "" -"Instances of this class represent loaded shared libraries, functions in " -"these libraries use the ``stdcall`` calling convention, and are assumed to " -"return :c:expr:`int` by default." +"On non-Windows systems, *name* can be ``None``. In this case, :c:func:`!" +"dlopen` is called with ``NULL``, which opens the main program as a " +"\"library\". (Some systems do the same is *name* is empty; ``None``/``NULL`` " +"is more portable.)" msgstr "" -#: ../../library/ctypes.rst:1523 -msgid "" -"The Python :term:`global interpreter lock` is released before calling any " -"function exported by these libraries, and reacquired afterwards." +#: ../../library/ctypes.rst:1503 +msgid "CPython implementation detail" msgstr "" -#: ../../library/ctypes.rst:1529 +#: ../../library/ctypes.rst:1505 msgid "" -"Instances of this class behave like :class:`CDLL` instances, except that the " -"Python GIL is *not* released during the function call, and after the " -"function execution the Python error flag is checked. If the error flag is " -"set, a Python exception is raised." +"Since CPython is linked to ``libc``, a ``None`` *name* is often used to " +"access the C standard library::" msgstr "" -#: ../../library/ctypes.rst:1534 -msgid "Thus, this is only useful to call Python C api functions directly." +#: ../../library/ctypes.rst:1508 +msgid "" +">>> printf = ctypes.CDLL(None).printf\n" +">>> printf.argtypes = [ctypes.c_char_p]\n" +">>> printf(b\"hello\\n\")\n" +"hello\n" +"6" msgstr "" -#: ../../library/ctypes.rst:1540 +#: ../../library/ctypes.rst:1514 msgid "" -"All these classes can be instantiated by calling them with at least one " -"argument, the pathname of the shared library. If you have an existing " -"handle to an already loaded shared library, it can be passed as the " -"``handle`` named parameter, otherwise the underlying platform's :c:func:`!" -"dlopen` or :c:func:`!LoadLibrary` function is used to load the library into " -"the process, and to get a handle to it." +"To access the Python C API, prefer :py:data:`ctypes.pythonapi` which works " +"across platforms." msgstr "" -#: ../../library/ctypes.rst:1547 +#: ../../library/ctypes.rst:1517 msgid "" "The *mode* parameter can be used to specify how the library is loaded. For " "details, consult the :manpage:`dlopen(3)` manpage. On Windows, *mode* is " @@ -2932,7 +2928,7 @@ msgid "" "configurable." msgstr "" -#: ../../library/ctypes.rst:1552 +#: ../../library/ctypes.rst:1522 msgid "" "The *use_errno* parameter, when set to true, enables a ctypes mechanism that " "allows accessing the system :data:`errno` error number in a safe way. :mod:`!" @@ -2942,14 +2938,14 @@ msgid "" "private copy, the same happens immediately after the function call." msgstr "" -#: ../../library/ctypes.rst:1559 +#: ../../library/ctypes.rst:1529 msgid "" "The function :func:`ctypes.get_errno` returns the value of the ctypes " "private copy, and the function :func:`ctypes.set_errno` changes the ctypes " "private copy to a new value and returns the former value." msgstr "" -#: ../../library/ctypes.rst:1563 +#: ../../library/ctypes.rst:1533 msgid "" "The *use_last_error* parameter, when set to true, enables the same mechanism " "for the Windows error code which is managed by the :func:`GetLastError` and :" @@ -2958,7 +2954,7 @@ msgid "" "private copy of the windows error code." msgstr "" -#: ../../library/ctypes.rst:1569 +#: ../../library/ctypes.rst:1539 msgid "" "The *winmode* parameter is used on Windows to specify how the library is " "loaded (since *mode* is ignored). It takes any value that is valid for the " @@ -2968,38 +2964,43 @@ msgid "" "ensure the correct library and dependencies are loaded." msgstr "" -#: ../../library/ctypes.rst:1576 -msgid "Added *winmode* parameter." -msgstr "新增 *winmode* 參數。" - -#: ../../library/ctypes.rst:1583 +#: ../../library/ctypes.rst:1546 msgid "" -"Flag to use as *mode* parameter. On platforms where this flag is not " -"available, it is defined as the integer zero." +"On Windows creating a :class:`CDLL` instance may fail even if the DLL name " +"exists. When a dependent DLL of the loaded DLL is not found, a :exc:" +"`OSError` error is raised with the message *\"[WinError 126] The specified " +"module could not be found\".* This error message does not contain the name " +"of the missing DLL because the Windows API does not return this information " +"making this error hard to diagnose. To resolve this error and determine " +"which DLL is not found, you need to find the list of dependent DLLs and " +"determine which one is not found using Windows debugging and tracing tools." msgstr "" -#: ../../library/ctypes.rst:1590 +#: ../../library/ctypes.rst:1558 msgid "" -"Flag to use as *mode* parameter. On platforms where this is not available, " -"it is the same as *RTLD_GLOBAL*." +"`Microsoft DUMPBIN tool `_ -- A tool to find DLL " +"dependents." msgstr "" -#: ../../library/ctypes.rst:1597 -msgid "" -"The default mode which is used to load shared libraries. On OSX 10.3, this " -"is *RTLD_GLOBAL*, otherwise it is the same as *RTLD_LOCAL*." +#: ../../library/ctypes.rst:1561 +msgid "Added *winmode* parameter." +msgstr "新增 *winmode* 參數。" + +#: ../../library/ctypes.rst:1566 +msgid "The *name* parameter can now be a :term:`path-like object`." msgstr "" -#: ../../library/ctypes.rst:1600 +#: ../../library/ctypes.rst:1568 msgid "" -"Instances of these classes have no public methods. Functions exported by " -"the shared library can be accessed as attributes or by index. Please note " -"that accessing the function through an attribute caches the result and " -"therefore accessing it repeatedly returns the same object each time. On the " -"other hand, accessing it through an index returns a new object each time::" +"Instances of this class have no public methods. Functions exported by the " +"shared library can be accessed as attributes or by index. Please note that " +"accessing the function through an attribute caches the result and therefore " +"accessing it repeatedly returns the same object each time. On the other " +"hand, accessing it through an index returns a new object each time::" msgstr "" -#: ../../library/ctypes.rst:1606 +#: ../../library/ctypes.rst:1574 msgid "" ">>> from ctypes import CDLL\n" ">>> libc = CDLL(\"libc.so.6\") # On Linux\n" @@ -3015,21 +3016,88 @@ msgstr "" ">>> libc['time'] == libc['time']\n" "False" -#: ../../library/ctypes.rst:1613 +#: ../../library/ctypes.rst:1581 msgid "" -"The following public attributes are available, their name starts with an " +"The following public attributes are available. Their name starts with an " "underscore to not clash with exported function names:" msgstr "" -#: ../../library/ctypes.rst:1619 +#: ../../library/ctypes.rst:1586 msgid "The system handle used to access the library." msgstr "" -#: ../../library/ctypes.rst:1624 +#: ../../library/ctypes.rst:1590 msgid "The name of the library passed in the constructor." msgstr "" -#: ../../library/ctypes.rst:1626 +#: ../../library/ctypes.rst:1594 ../../library/ctypes.rst:1611 +#: ../../library/ctypes.rst:1620 +msgid "See :py:class:`~ctypes.CDLL`, the superclass, for common information." +msgstr "" + +#: ../../library/ctypes.rst:1596 +msgid "" +"Functions in this library use the ``stdcall`` calling convention, and are " +"assumed to return the windows specific :class:`HRESULT` code. :class:" +"`HRESULT` values contain information specifying whether the function call " +"failed or succeeded, together with additional error code. If the return " +"value signals a failure, an :class:`OSError` is automatically raised." +msgstr "" + +#: ../../library/ctypes.rst:1602 ../../library/ctypes.rst:1616 +#: ../../library/ctypes.rst:1679 ../../library/ctypes.rst:1686 +#: ../../library/ctypes.rst:1856 ../../library/ctypes.rst:1908 +#: ../../library/ctypes.rst:2060 ../../library/ctypes.rst:2132 +#: ../../library/ctypes.rst:2141 ../../library/ctypes.rst:2168 +#: ../../library/ctypes.rst:2182 ../../library/ctypes.rst:2191 +#: ../../library/ctypes.rst:2200 ../../library/ctypes.rst:2215 +#: ../../library/ctypes.rst:2282 ../../library/ctypes.rst:2309 +#: ../../library/ctypes.rst:2709 ../../library/ctypes.rst:3127 +msgid "Availability" +msgstr "可用性" + +#: ../../library/ctypes.rst:1604 +msgid "" +":exc:`WindowsError` used to be raised, which is now an alias of :exc:" +"`OSError`." +msgstr "" + +#: ../../library/ctypes.rst:1613 +msgid "" +"Functions in these libraries use the ``stdcall`` calling convention, and are " +"assumed to return :c:expr:`int` by default." +msgstr "" + +#: ../../library/ctypes.rst:1622 +msgid "" +"When functions in this library are called, the Python GIL is *not* released " +"during the function call, and after the function execution the Python error " +"flag is checked. If the error flag is set, a Python exception is raised." +msgstr "" + +#: ../../library/ctypes.rst:1627 +msgid "Thus, this is only useful to call Python C API functions directly." +msgstr "" + +#: ../../library/ctypes.rst:1632 +msgid "" +"Flag to use as *mode* parameter. On platforms where this flag is not " +"available, it is defined as the integer zero." +msgstr "" + +#: ../../library/ctypes.rst:1638 +msgid "" +"Flag to use as *mode* parameter. On platforms where this is not available, " +"it is the same as *RTLD_GLOBAL*." +msgstr "" + +#: ../../library/ctypes.rst:1644 +msgid "" +"The default mode which is used to load shared libraries. On OSX 10.3, this " +"is *RTLD_GLOBAL*, otherwise it is the same as *RTLD_LOCAL*." +msgstr "" + +#: ../../library/ctypes.rst:1648 msgid "" "Shared libraries can also be loaded by using one of the prefabricated " "objects, which are instances of the :class:`LibraryLoader` class, either by " @@ -3037,13 +3105,13 @@ msgid "" "library as attribute of the loader instance." msgstr "" -#: ../../library/ctypes.rst:1634 +#: ../../library/ctypes.rst:1655 msgid "" "Class which loads shared libraries. *dlltype* should be one of the :class:" "`CDLL`, :class:`PyDLL`, :class:`WinDLL`, or :class:`OleDLL` types." msgstr "" -#: ../../library/ctypes.rst:1637 +#: ../../library/ctypes.rst:1658 msgid "" ":meth:`!__getattr__` has special behavior: It allows loading a shared " "library by accessing it as attribute of a library loader instance. The " @@ -3051,39 +3119,39 @@ msgid "" "each time." msgstr "" -#: ../../library/ctypes.rst:1643 +#: ../../library/ctypes.rst:1664 msgid "" "Load a shared library into the process and return it. This method always " "returns a new instance of the library." msgstr "" -#: ../../library/ctypes.rst:1647 +#: ../../library/ctypes.rst:1668 msgid "These prefabricated library loaders are available:" msgstr "" -#: ../../library/ctypes.rst:1652 +#: ../../library/ctypes.rst:1672 msgid "Creates :class:`CDLL` instances." msgstr "" -#: ../../library/ctypes.rst:1658 +#: ../../library/ctypes.rst:1677 msgid "Creates :class:`WinDLL` instances." msgstr "" -#: ../../library/ctypes.rst:1666 +#: ../../library/ctypes.rst:1684 msgid "Creates :class:`OleDLL` instances." msgstr "" -#: ../../library/ctypes.rst:1674 +#: ../../library/ctypes.rst:1691 msgid "Creates :class:`PyDLL` instances." msgstr "" -#: ../../library/ctypes.rst:1677 +#: ../../library/ctypes.rst:1694 msgid "" "For accessing the C Python api directly, a ready-to-use Python shared " "library object is available:" msgstr "" -#: ../../library/ctypes.rst:1683 +#: ../../library/ctypes.rst:1699 msgid "" "An instance of :class:`PyDLL` that exposes Python C API functions as " "attributes. Note that all these functions are assumed to return C :c:expr:" @@ -3091,32 +3159,32 @@ msgid "" "correct :attr:`!restype` attribute to use these functions." msgstr "" -#: ../../library/ctypes.rst:1688 ../../library/ctypes.rst:1690 +#: ../../library/ctypes.rst:1704 ../../library/ctypes.rst:1706 msgid "" "Loading a library through any of these objects raises an :ref:`auditing " "event ` ``ctypes.dlopen`` with string argument ``name``, the name " "used to load the library." msgstr "" -#: ../../library/ctypes.rst:1694 ../../library/ctypes.rst:1696 +#: ../../library/ctypes.rst:1710 ../../library/ctypes.rst:1712 msgid "" "Accessing a function on a loaded library raises an auditing event ``ctypes." "dlsym`` with arguments ``library`` (the library object) and ``name`` (the " "symbol's name as a string or integer)." msgstr "" -#: ../../library/ctypes.rst:1700 ../../library/ctypes.rst:1702 +#: ../../library/ctypes.rst:1716 ../../library/ctypes.rst:1718 msgid "" "In cases when only the library handle is available rather than the object, " "accessing a function raises an auditing event ``ctypes.dlsym/handle`` with " "arguments ``handle`` (the raw library handle) and ``name``." msgstr "" -#: ../../library/ctypes.rst:1709 +#: ../../library/ctypes.rst:1725 msgid "Foreign functions" msgstr "" -#: ../../library/ctypes.rst:1711 +#: ../../library/ctypes.rst:1727 msgid "" "As explained in the previous section, foreign functions can be accessed as " "attributes of loaded shared libraries. The function objects created in this " @@ -3125,13 +3193,13 @@ msgid "" "library loader." msgstr "" -#: ../../library/ctypes.rst:1716 +#: ../../library/ctypes.rst:1732 msgid "" "They are instances of a private local class :class:`!_FuncPtr` (not exposed " "in :mod:`!ctypes`) which inherits from the private :class:`_CFuncPtr` class:" msgstr "" -#: ../../library/ctypes.rst:1719 +#: ../../library/ctypes.rst:1735 msgid "" ">>> import ctypes\n" ">>> lib = ctypes.CDLL(None)\n" @@ -3147,29 +3215,29 @@ msgstr "" ">>> lib._FuncPtr is ctypes._CFuncPtr\n" "False" -#: ../../library/ctypes.rst:1730 +#: ../../library/ctypes.rst:1746 msgid "Base class for C callable foreign functions." msgstr "" -#: ../../library/ctypes.rst:1732 +#: ../../library/ctypes.rst:1748 msgid "" "Instances of foreign functions are also C compatible data types; they " "represent C function pointers." msgstr "" -#: ../../library/ctypes.rst:1735 +#: ../../library/ctypes.rst:1751 msgid "" "This behavior can be customized by assigning to special attributes of the " "foreign function object." msgstr "" -#: ../../library/ctypes.rst:1740 +#: ../../library/ctypes.rst:1756 msgid "" "Assign a ctypes type to specify the result type of the foreign function. Use " "``None`` for :c:expr:`void`, a function not returning anything." msgstr "" -#: ../../library/ctypes.rst:1743 +#: ../../library/ctypes.rst:1759 msgid "" "It is possible to assign a callable Python object that is not a ctypes type, " "in this case the function is assumed to return a C :c:expr:`int`, and the " @@ -3179,7 +3247,7 @@ msgid "" "callable to the :attr:`errcheck` attribute." msgstr "" -#: ../../library/ctypes.rst:1752 +#: ../../library/ctypes.rst:1768 msgid "" "Assign a tuple of ctypes types to specify the argument types that the " "function accepts. Functions using the ``stdcall`` calling convention can " @@ -3188,7 +3256,7 @@ msgid "" "unspecified arguments as well." msgstr "" -#: ../../library/ctypes.rst:1758 +#: ../../library/ctypes.rst:1774 msgid "" "When a foreign function is called, each actual argument is passed to the :" "meth:`~_CData.from_param` class method of the items in the :attr:`argtypes` " @@ -3198,7 +3266,7 @@ msgid "" "object using ctypes conversion rules." msgstr "" -#: ../../library/ctypes.rst:1765 +#: ../../library/ctypes.rst:1781 msgid "" "New: It is now possible to put items in argtypes which are not ctypes types, " "but each item must have a :meth:`~_CData.from_param` method which returns a " @@ -3206,38 +3274,38 @@ msgid "" "defining adapters that can adapt custom objects as function parameters." msgstr "" -#: ../../library/ctypes.rst:1772 +#: ../../library/ctypes.rst:1788 msgid "" "Assign a Python function or another callable to this attribute. The callable " "will be called with three or more arguments:" msgstr "" -#: ../../library/ctypes.rst:1779 +#: ../../library/ctypes.rst:1795 msgid "" "*result* is what the foreign function returns, as specified by the :attr:`!" "restype` attribute." msgstr "" -#: ../../library/ctypes.rst:1782 +#: ../../library/ctypes.rst:1798 msgid "" "*func* is the foreign function object itself, this allows reusing the same " "callable object to check or post process the results of several functions." msgstr "" -#: ../../library/ctypes.rst:1786 +#: ../../library/ctypes.rst:1802 msgid "" "*arguments* is a tuple containing the parameters originally passed to the " "function call, this allows specializing the behavior on the arguments used." msgstr "" -#: ../../library/ctypes.rst:1790 +#: ../../library/ctypes.rst:1806 msgid "" "The object that this function returns will be returned from the foreign " "function call, but it can also check the result value and raise an exception " "if the foreign function call failed." msgstr "" -#: ../../library/ctypes.rst:1795 ../../library/ctypes.rst:1797 +#: ../../library/ctypes.rst:1811 ../../library/ctypes.rst:1813 msgid "" "On Windows, when a foreign function call raises a system exception (for " "example, due to an access violation), it will be captured and replaced with " @@ -3246,18 +3314,18 @@ msgid "" "hook to replace the exception with its own." msgstr "" -#: ../../library/ctypes.rst:1803 ../../library/ctypes.rst:1805 +#: ../../library/ctypes.rst:1819 ../../library/ctypes.rst:1821 msgid "" "Some ways to invoke foreign function calls as well as some of the functions " "in this module may raise an auditing event ``ctypes.call_function`` with " "arguments ``function pointer`` and ``arguments``." msgstr "" -#: ../../library/ctypes.rst:1812 +#: ../../library/ctypes.rst:1828 msgid "Function prototypes" msgstr "" -#: ../../library/ctypes.rst:1814 +#: ../../library/ctypes.rst:1830 msgid "" "Foreign functions can also be created by instantiating function prototypes. " "Function prototypes are similar to function prototypes in C; they describe a " @@ -3268,7 +3336,7 @@ msgid "" "``@wrapper`` syntax. See :ref:`ctypes-callback-functions` for examples." msgstr "" -#: ../../library/ctypes.rst:1825 +#: ../../library/ctypes.rst:1841 msgid "" "The returned function prototype creates functions that use the standard C " "calling convention. The function will release the GIL during the call. If " @@ -3277,37 +3345,37 @@ msgid "" "after the call; *use_last_error* does the same for the Windows error code." msgstr "" -#: ../../library/ctypes.rst:1835 +#: ../../library/ctypes.rst:1851 msgid "" "The returned function prototype creates functions that use the ``stdcall`` " "calling convention. The function will release the GIL during the call. " "*use_errno* and *use_last_error* have the same meaning as above." msgstr "" -#: ../../library/ctypes.rst:1845 +#: ../../library/ctypes.rst:1861 msgid "" "The returned function prototype creates functions that use the Python " "calling convention. The function will *not* release the GIL during the call." msgstr "" -#: ../../library/ctypes.rst:1848 +#: ../../library/ctypes.rst:1864 msgid "" "Function prototypes created by these factory functions can be instantiated " "in different ways, depending on the type and number of the parameters in the " "call:" msgstr "" -#: ../../library/ctypes.rst:1855 +#: ../../library/ctypes.rst:1871 msgid "" "Returns a foreign function at the specified address which must be an integer." msgstr "" -#: ../../library/ctypes.rst:1862 +#: ../../library/ctypes.rst:1878 msgid "" "Create a C callable function (a callback function) from a Python *callable*." msgstr "" -#: ../../library/ctypes.rst:1869 +#: ../../library/ctypes.rst:1885 msgid "" "Returns a foreign function exported by a shared library. *func_spec* must be " "a 2-tuple ``(name_or_ordinal, library)``. The first item is the name of the " @@ -3315,7 +3383,7 @@ msgid "" "small integer. The second item is the shared library instance." msgstr "" -#: ../../library/ctypes.rst:1879 +#: ../../library/ctypes.rst:1895 msgid "" "Returns a foreign function that will call a COM method. *vtbl_index* is the " "index into the virtual function table, a small non-negative integer. *name* " @@ -3323,86 +3391,86 @@ msgid "" "identifier which is used in extended error reporting." msgstr "" -#: ../../library/ctypes.rst:1884 +#: ../../library/ctypes.rst:1900 msgid "" "If *iid* is not specified, an :exc:`OSError` is raised if the COM method " "call fails. If *iid* is specified, a :exc:`~ctypes.COMError` is raised " "instead." msgstr "" -#: ../../library/ctypes.rst:1888 +#: ../../library/ctypes.rst:1904 msgid "" "COM methods use a special calling convention: They require a pointer to the " "COM interface as first argument, in addition to those parameters that are " "specified in the :attr:`!argtypes` tuple." msgstr "" -#: ../../library/ctypes.rst:1895 +#: ../../library/ctypes.rst:1911 msgid "" "The optional *paramflags* parameter creates foreign function wrappers with " "much more functionality than the features described above." msgstr "" -#: ../../library/ctypes.rst:1898 +#: ../../library/ctypes.rst:1914 msgid "" "*paramflags* must be a tuple of the same length as :attr:`~_CFuncPtr." "argtypes`." msgstr "" -#: ../../library/ctypes.rst:1900 +#: ../../library/ctypes.rst:1916 msgid "" "Each item in this tuple contains further information about a parameter, it " "must be a tuple containing one, two, or three items." msgstr "" -#: ../../library/ctypes.rst:1903 +#: ../../library/ctypes.rst:1919 msgid "" "The first item is an integer containing a combination of direction flags for " "the parameter:" msgstr "" -#: ../../library/ctypes.rst:1906 +#: ../../library/ctypes.rst:1922 msgid "1" msgstr "1" -#: ../../library/ctypes.rst:1907 +#: ../../library/ctypes.rst:1923 msgid "Specifies an input parameter to the function." msgstr "" -#: ../../library/ctypes.rst:1909 +#: ../../library/ctypes.rst:1925 msgid "2" msgstr "2" -#: ../../library/ctypes.rst:1910 +#: ../../library/ctypes.rst:1926 msgid "Output parameter. The foreign function fills in a value." msgstr "" -#: ../../library/ctypes.rst:1912 +#: ../../library/ctypes.rst:1928 msgid "4" msgstr "4" -#: ../../library/ctypes.rst:1913 +#: ../../library/ctypes.rst:1929 msgid "Input parameter which defaults to the integer zero." msgstr "" -#: ../../library/ctypes.rst:1915 +#: ../../library/ctypes.rst:1931 msgid "" "The optional second item is the parameter name as string. If this is " "specified, the foreign function can be called with named parameters." msgstr "" -#: ../../library/ctypes.rst:1918 +#: ../../library/ctypes.rst:1934 msgid "The optional third item is the default value for this parameter." msgstr "" -#: ../../library/ctypes.rst:1921 +#: ../../library/ctypes.rst:1937 msgid "" "The following example demonstrates how to wrap the Windows ``MessageBoxW`` " "function so that it supports default parameters and named arguments. The C " "declaration from the windows header file is this::" msgstr "" -#: ../../library/ctypes.rst:1925 +#: ../../library/ctypes.rst:1941 msgid "" "WINUSERAPI int WINAPI\n" "MessageBoxW(\n" @@ -3418,11 +3486,11 @@ msgstr "" " LPCWSTR lpCaption,\n" " UINT uType);" -#: ../../library/ctypes.rst:1932 ../../library/ctypes.rst:1955 +#: ../../library/ctypes.rst:1948 ../../library/ctypes.rst:1971 msgid "Here is the wrapping with :mod:`!ctypes`::" msgstr "" -#: ../../library/ctypes.rst:1934 +#: ../../library/ctypes.rst:1950 msgid "" ">>> from ctypes import c_int, WINFUNCTYPE, windll\n" ">>> from ctypes.wintypes import HWND, LPCWSTR, UINT\n" @@ -3438,11 +3506,11 @@ msgstr "" "\"Hello from ctypes\"), (1, \"flags\", 0)\n" ">>> MessageBox = prototype((\"MessageBoxW\", windll.user32), paramflags)" -#: ../../library/ctypes.rst:1940 +#: ../../library/ctypes.rst:1956 msgid "The ``MessageBox`` foreign function can now be called in these ways::" msgstr "" -#: ../../library/ctypes.rst:1942 +#: ../../library/ctypes.rst:1958 msgid "" ">>> MessageBox()\n" ">>> MessageBox(text=\"Spam, spam, spam\")\n" @@ -3452,7 +3520,7 @@ msgstr "" ">>> MessageBox(text=\"Spam, spam, spam\")\n" ">>> MessageBox(flags=2, text=\"foo bar\")" -#: ../../library/ctypes.rst:1946 +#: ../../library/ctypes.rst:1962 msgid "" "A second example demonstrates output parameters. The win32 " "``GetWindowRect`` function retrieves the dimensions of a specified window by " @@ -3460,7 +3528,7 @@ msgid "" "the C declaration::" msgstr "" -#: ../../library/ctypes.rst:1950 +#: ../../library/ctypes.rst:1966 msgid "" "WINUSERAPI BOOL WINAPI\n" "GetWindowRect(\n" @@ -3472,7 +3540,7 @@ msgstr "" " HWND hWnd,\n" " LPRECT lpRect);" -#: ../../library/ctypes.rst:1957 +#: ../../library/ctypes.rst:1973 msgid "" ">>> from ctypes import POINTER, WINFUNCTYPE, windll, WinError\n" ">>> from ctypes.wintypes import BOOL, HWND, RECT\n" @@ -3490,7 +3558,7 @@ msgstr "" "paramflags)\n" ">>>" -#: ../../library/ctypes.rst:1964 +#: ../../library/ctypes.rst:1980 msgid "" "Functions with output parameters will automatically return the output " "parameter value if there is a single one, or a tuple containing the output " @@ -3498,7 +3566,7 @@ msgid "" "now returns a RECT instance, when called." msgstr "" -#: ../../library/ctypes.rst:1969 +#: ../../library/ctypes.rst:1985 msgid "" "Output parameters can be combined with the :attr:`~_CFuncPtr.errcheck` " "protocol to do further output processing and error checking. The win32 " @@ -3507,7 +3575,7 @@ msgid "" "exception when the api call failed::" msgstr "" -#: ../../library/ctypes.rst:1974 +#: ../../library/ctypes.rst:1990 msgid "" ">>> def errcheck(result, func, args):\n" "... if not result:\n" @@ -3525,7 +3593,7 @@ msgstr "" ">>> GetWindowRect.errcheck = errcheck\n" ">>>" -#: ../../library/ctypes.rst:1982 +#: ../../library/ctypes.rst:1998 msgid "" "If the :attr:`~_CFuncPtr.errcheck` function returns the argument tuple it " "receives unchanged, :mod:`!ctypes` continues the normal processing it does " @@ -3535,7 +3603,7 @@ msgid "" "take place::" msgstr "" -#: ../../library/ctypes.rst:1988 +#: ../../library/ctypes.rst:2004 msgid "" ">>> def errcheck(result, func, args):\n" "... if not result:\n" @@ -3555,17 +3623,17 @@ msgstr "" ">>> GetWindowRect.errcheck = errcheck\n" ">>>" -#: ../../library/ctypes.rst:2001 +#: ../../library/ctypes.rst:2017 msgid "Utility functions" msgstr "" -#: ../../library/ctypes.rst:2005 +#: ../../library/ctypes.rst:2021 msgid "" "Returns the address of the memory buffer as integer. *obj* must be an " "instance of a ctypes type." msgstr "" -#: ../../library/ctypes.rst:2008 +#: ../../library/ctypes.rst:2024 msgid "" "Raises an :ref:`auditing event ` ``ctypes.addressof`` with " "argument ``obj``." @@ -3573,46 +3641,46 @@ msgstr "" "引發一個附帶引數 ``obj`` 的\\ :ref:`稽核事件 ` ``ctypes." "addressof``。" -#: ../../library/ctypes.rst:2013 +#: ../../library/ctypes.rst:2029 msgid "" "Returns the alignment requirements of a ctypes type. *obj_or_type* must be a " "ctypes type or instance." msgstr "" -#: ../../library/ctypes.rst:2019 +#: ../../library/ctypes.rst:2035 msgid "" "Returns a light-weight pointer to *obj*, which must be an instance of a " "ctypes type. *offset* defaults to zero, and must be an integer that will be " "added to the internal pointer value." msgstr "" -#: ../../library/ctypes.rst:2023 +#: ../../library/ctypes.rst:2039 msgid "``byref(obj, offset)`` corresponds to this C code::" msgstr "" -#: ../../library/ctypes.rst:2025 +#: ../../library/ctypes.rst:2041 msgid "(((char *)&obj) + offset)" msgstr "(((char *)&obj) + offset)" -#: ../../library/ctypes.rst:2027 +#: ../../library/ctypes.rst:2043 msgid "" "The returned object can only be used as a foreign function call parameter. " "It behaves similar to ``pointer(obj)``, but the construction is a lot faster." msgstr "" -#: ../../library/ctypes.rst:2033 +#: ../../library/ctypes.rst:2049 msgid "" "Copies a COM pointer from *src* to *dst* and returns the Windows specific :c:" "type:`!HRESULT` value." msgstr "" -#: ../../library/ctypes.rst:2036 +#: ../../library/ctypes.rst:2052 msgid "" "If *src* is not ``NULL``, its ``AddRef`` method is called, incrementing the " "reference count." msgstr "" -#: ../../library/ctypes.rst:2039 +#: ../../library/ctypes.rst:2055 msgid "" "In contrast, the reference count of *dst* will not be decremented before " "assigning the new value. Unless *dst* is ``NULL``, the caller is responsible " @@ -3620,7 +3688,7 @@ msgid "" "necessary." msgstr "" -#: ../../library/ctypes.rst:2051 +#: ../../library/ctypes.rst:2067 msgid "" "This function is similar to the cast operator in C. It returns a new " "instance of *type* which points to the same memory block as *obj*. *type* " @@ -3628,47 +3696,47 @@ msgid "" "as a pointer." msgstr "" -#: ../../library/ctypes.rst:2060 +#: ../../library/ctypes.rst:2076 msgid "" "This function creates a mutable character buffer. The returned object is a " "ctypes array of :class:`c_char`." msgstr "" -#: ../../library/ctypes.rst:2063 +#: ../../library/ctypes.rst:2079 msgid "" "If *size* is given (and not ``None``), it must be an :class:`int`. It " "specifies the size of the returned array." msgstr "" -#: ../../library/ctypes.rst:2066 +#: ../../library/ctypes.rst:2082 msgid "" "If the *init* argument is given, it must be :class:`bytes`. It is used to " "initialize the array items. Bytes not initialized this way are set to zero " "(NUL)." msgstr "" -#: ../../library/ctypes.rst:2070 +#: ../../library/ctypes.rst:2086 msgid "" "If *size* is not given (or if it is ``None``), the buffer is made one " "element larger than *init*, effectively adding a NUL terminator." msgstr "" -#: ../../library/ctypes.rst:2073 +#: ../../library/ctypes.rst:2089 msgid "" "If both arguments are given, *size* must not be less than ``len(init)``." msgstr "如果兩個引數皆有提供,*size* 不得小於 ``len(init)``。" -#: ../../library/ctypes.rst:2077 +#: ../../library/ctypes.rst:2093 msgid "" "If *size* is equal to ``len(init)``, a NUL terminator is not added. Do not " "treat such a buffer as a C string." msgstr "" -#: ../../library/ctypes.rst:2080 +#: ../../library/ctypes.rst:2096 msgid "For example::" msgstr "舉例來說: ::" -#: ../../library/ctypes.rst:2082 +#: ../../library/ctypes.rst:2098 msgid "" ">>> bytes(create_string_buffer(2))\n" "b'\\x00\\x00'\n" @@ -3696,7 +3764,7 @@ msgstr "" " ...\n" "ValueError: byte string too long" -#: ../../library/ctypes.rst:2095 +#: ../../library/ctypes.rst:2111 msgid "" "Raises an :ref:`auditing event ` ``ctypes.create_string_buffer`` " "with arguments ``init``, ``size``." @@ -3704,19 +3772,19 @@ msgstr "" "引發一個附帶引數 ``init`` 與 ``size`` 的\\ :ref:`稽核事件 ` " "``ctypes.create_string_buffer``。" -#: ../../library/ctypes.rst:2101 +#: ../../library/ctypes.rst:2117 msgid "" "This function creates a mutable unicode character buffer. The returned " "object is a ctypes array of :class:`c_wchar`." msgstr "" -#: ../../library/ctypes.rst:2104 +#: ../../library/ctypes.rst:2120 msgid "" "The function takes the same arguments as :func:`~create_string_buffer` " "except *init* must be a string and *size* counts :class:`c_wchar`." msgstr "" -#: ../../library/ctypes.rst:2107 +#: ../../library/ctypes.rst:2123 msgid "" "Raises an :ref:`auditing event ` ``ctypes.create_unicode_buffer`` " "with arguments ``init``, ``size``." @@ -3724,21 +3792,21 @@ msgstr "" "引發一個附帶引數 ``init`` 與 ``size`` 的\\ :ref:`稽核事件 ` " "``ctypes.create_unicode_buffer``。" -#: ../../library/ctypes.rst:2112 +#: ../../library/ctypes.rst:2128 msgid "" "This function is a hook which allows implementing in-process COM servers " "with ctypes. It is called from the DllCanUnloadNow function that the " "_ctypes extension dll exports." msgstr "" -#: ../../library/ctypes.rst:2121 +#: ../../library/ctypes.rst:2137 msgid "" "This function is a hook which allows implementing in-process COM servers " "with ctypes. It is called from the DllGetClassObject function that the " "``_ctypes`` extension dll exports." msgstr "" -#: ../../library/ctypes.rst:2131 +#: ../../library/ctypes.rst:2147 msgid "" "Try to find a library and return a pathname. *name* is the library name " "without any prefix like ``lib``, suffix like ``.so``, ``.dylib`` or version " @@ -3746,25 +3814,25 @@ msgid "" "If no library can be found, returns ``None``." msgstr "" -#: ../../library/ctypes.rst:2138 +#: ../../library/ctypes.rst:2154 msgid "See :ref:`ctypes-finding-shared-libraries` for complete documentation." msgstr "" -#: ../../library/ctypes.rst:2144 +#: ../../library/ctypes.rst:2160 msgid "" "Returns the filename of the VC runtime library used by Python, and by the " "extension modules. If the name of the library cannot be determined, " "``None`` is returned." msgstr "" -#: ../../library/ctypes.rst:2148 +#: ../../library/ctypes.rst:2164 msgid "" "If you need to free memory, for example, allocated by an extension module " "with a call to the ``free(void *)``, it is important that you use the " "function in the same library that allocated the memory." msgstr "" -#: ../../library/ctypes.rst:2158 +#: ../../library/ctypes.rst:2174 msgid "" "Try to provide a list of paths of the shared libraries loaded into the " "current process. These paths are not normalized or processed in any way. " @@ -3772,74 +3840,74 @@ msgid "" "The exact functionality is system dependent." msgstr "" -#: ../../library/ctypes.rst:2163 +#: ../../library/ctypes.rst:2179 msgid "" "On most platforms, the first element of the list represents the current " "executable file. It may be an empty string." msgstr "" -#: ../../library/ctypes.rst:2171 +#: ../../library/ctypes.rst:2187 msgid "" "Returns a textual description of the error code *code*. If no error code is " "specified, the last error code is used by calling the Windows API function :" "func:`GetLastError`." msgstr "" -#: ../../library/ctypes.rst:2180 +#: ../../library/ctypes.rst:2196 msgid "" "Returns the last error code set by Windows in the calling thread. This " "function calls the Windows ``GetLastError()`` function directly, it does not " "return the ctypes-private copy of the error code." msgstr "" -#: ../../library/ctypes.rst:2189 +#: ../../library/ctypes.rst:2205 msgid "" "Returns the current value of the ctypes-private copy of the system :data:" "`errno` variable in the calling thread." msgstr "" -#: ../../library/ctypes.rst:2192 +#: ../../library/ctypes.rst:2208 msgid "" "Raises an :ref:`auditing event ` ``ctypes.get_errno`` with no " "arguments." msgstr "" "引發一個不附帶引數的\\ :ref:`稽核事件 ` ``ctypes.get_errno``。" -#: ../../library/ctypes.rst:2196 +#: ../../library/ctypes.rst:2212 msgid "" "Returns the current value of the ctypes-private copy of the system :data:`!" "LastError` variable in the calling thread." msgstr "" -#: ../../library/ctypes.rst:2201 +#: ../../library/ctypes.rst:2217 msgid "" "Raises an :ref:`auditing event ` ``ctypes.get_last_error`` with no " "arguments." msgstr "" "引發一個不附帶引數的\\ :ref:`稽核事件 ` ``ctypes.get_last_error``。" -#: ../../library/ctypes.rst:2206 +#: ../../library/ctypes.rst:2222 msgid "" "Same as the standard C memmove library function: copies *count* bytes from " "*src* to *dst*. *dst* and *src* must be integers or ctypes instances that " "can be converted to pointers." msgstr "" -#: ../../library/ctypes.rst:2213 +#: ../../library/ctypes.rst:2229 msgid "" "Same as the standard C memset library function: fills the memory block at " "address *dst* with *count* bytes of value *c*. *dst* must be an integer " "specifying an address, or a ctypes instance." msgstr "" -#: ../../library/ctypes.rst:2220 +#: ../../library/ctypes.rst:2236 msgid "" "Create or return a ctypes pointer type. Pointer types are cached and reused " "internally, so calling this function repeatedly is cheap. *type* must be a " "ctypes type." msgstr "" -#: ../../library/ctypes.rst:2226 +#: ../../library/ctypes.rst:2242 msgid "" "The resulting pointer type is cached in the ``__pointer_type__`` attribute " "of *type*. It is possible to set this attribute before the first call to " @@ -3848,19 +3916,19 @@ msgid "" "relying on implementation details that may change in future Python versions." msgstr "" -#: ../../library/ctypes.rst:2237 +#: ../../library/ctypes.rst:2253 msgid "" "Create a new pointer instance, pointing to *obj*. The returned object is of " "the type ``POINTER(type(obj))``." msgstr "" -#: ../../library/ctypes.rst:2240 +#: ../../library/ctypes.rst:2256 msgid "" "Note: If you just want to pass a pointer to an object to a foreign function " "call, you should use ``byref(obj)`` which is much faster." msgstr "" -#: ../../library/ctypes.rst:2246 +#: ../../library/ctypes.rst:2262 msgid "" "This function resizes the internal memory buffer of *obj*, which must be an " "instance of a ctypes type. It is not possible to make the buffer smaller " @@ -3868,13 +3936,13 @@ msgid "" "but it is possible to enlarge the buffer." msgstr "" -#: ../../library/ctypes.rst:2254 +#: ../../library/ctypes.rst:2270 msgid "" "Set the current value of the ctypes-private copy of the system :data:`errno` " "variable in the calling thread to *value* and return the previous value." msgstr "" -#: ../../library/ctypes.rst:2257 +#: ../../library/ctypes.rst:2273 msgid "" "Raises an :ref:`auditing event ` ``ctypes.set_errno`` with " "argument ``errno``." @@ -3882,14 +3950,14 @@ msgstr "" "引發一個附帶引數 ``errno`` 的\\ :ref:`稽核事件 ` ``ctypes." "set_errno``。" -#: ../../library/ctypes.rst:2262 +#: ../../library/ctypes.rst:2278 msgid "" "Sets the current value of the ctypes-private copy of the system :data:`!" "LastError` variable in the calling thread to *value* and return the previous " "value." msgstr "" -#: ../../library/ctypes.rst:2268 +#: ../../library/ctypes.rst:2284 msgid "" "Raises an :ref:`auditing event ` ``ctypes.set_last_error`` with " "argument ``error``." @@ -3897,19 +3965,19 @@ msgstr "" "引發一個附帶引數 ``error`` 的\\ :ref:`稽核事件 ` ``ctypes." "set_last_error``。" -#: ../../library/ctypes.rst:2273 +#: ../../library/ctypes.rst:2289 msgid "" "Returns the size in bytes of a ctypes type or instance memory buffer. Does " "the same as the C ``sizeof`` operator." msgstr "" -#: ../../library/ctypes.rst:2279 +#: ../../library/ctypes.rst:2295 msgid "" "Return the byte string at *void \\*ptr*. If *size* is specified, it is used " "as size, otherwise the string is assumed to be zero-terminated." msgstr "" -#: ../../library/ctypes.rst:2283 +#: ../../library/ctypes.rst:2299 msgid "" "Raises an :ref:`auditing event ` ``ctypes.string_at`` with " "arguments ``ptr``, ``size``." @@ -3917,7 +3985,7 @@ msgstr "" "引發一個附帶引數 ``ptr``、``size`` 的\\ :ref:`稽核事件 ` ``ctypes." "string_at``。" -#: ../../library/ctypes.rst:2288 +#: ../../library/ctypes.rst:2304 msgid "" "Creates an instance of :exc:`OSError`. If *code* is not specified, :func:" "`GetLastError` is called to determine the error code. If *descr* is not " @@ -3925,20 +3993,20 @@ msgid "" "error." msgstr "" -#: ../../library/ctypes.rst:2295 +#: ../../library/ctypes.rst:2311 msgid "" "An instance of :exc:`WindowsError` used to be created, which is now an alias " "of :exc:`OSError`." msgstr "" -#: ../../library/ctypes.rst:2302 +#: ../../library/ctypes.rst:2318 msgid "" "Return the wide-character string at *void \\*ptr*. If *size* is specified, " "it is used as the number of characters of the string, otherwise the string " "is assumed to be zero-terminated." msgstr "" -#: ../../library/ctypes.rst:2307 +#: ../../library/ctypes.rst:2323 msgid "" "Raises an :ref:`auditing event ` ``ctypes.wstring_at`` with " "arguments ``ptr``, ``size``." @@ -3946,20 +4014,20 @@ msgstr "" "引發一個附帶引數 ``ptr``、``size`` 的\\ :ref:`稽核事件 ` ``ctypes." "wstring_at``。" -#: ../../library/ctypes.rst:2312 +#: ../../library/ctypes.rst:2328 msgid "" "Return a :class:`memoryview` object of length *size* that references memory " "starting at *void \\*ptr*." msgstr "" -#: ../../library/ctypes.rst:2315 +#: ../../library/ctypes.rst:2331 msgid "" "If *readonly* is true, the returned :class:`!memoryview` object can not be " "used to modify the underlying memory. (Changes made by other means will " "still be reflected in the returned object.)" msgstr "" -#: ../../library/ctypes.rst:2320 +#: ../../library/ctypes.rst:2336 msgid "" "This function is similar to :func:`string_at` with the key difference of not " "making a copy of the specified memory. It is a semantically equivalent (but " @@ -3969,7 +4037,7 @@ msgid "" "`~ctypes.byref` object.)" msgstr "" -#: ../../library/ctypes.rst:2327 +#: ../../library/ctypes.rst:2343 msgid "" "Raises an :ref:`auditing event ` ``ctypes.memoryview_at`` with " "arguments ``address``, ``size``, ``readonly``." @@ -3977,11 +4045,11 @@ msgstr "" "引發一個附帶引數 ``address``、``size`` 與 ``readonly`` 的\\ :ref:`稽核事件 " "` ``ctypes.memoryview_at``。" -#: ../../library/ctypes.rst:2335 +#: ../../library/ctypes.rst:2351 msgid "Data types" msgstr "" -#: ../../library/ctypes.rst:2340 +#: ../../library/ctypes.rst:2356 msgid "" "This non-public class is the common base class of all ctypes data types. " "Among other things, all ctypes type instances contain a memory block that " @@ -3991,13 +4059,13 @@ msgid "" "alive in case the memory block contains pointers." msgstr "" -#: ../../library/ctypes.rst:2347 +#: ../../library/ctypes.rst:2363 msgid "" "Common methods of ctypes data types, these are all class methods (to be " "exact, they are methods of the :term:`metaclass`):" msgstr "" -#: ../../library/ctypes.rst:2352 +#: ../../library/ctypes.rst:2368 msgid "" "This method returns a ctypes instance that shares the buffer of the *source* " "object. The *source* object must support the writeable buffer interface. " @@ -4006,7 +4074,7 @@ msgid "" "exc:`ValueError` is raised." msgstr "" -#: ../../library/ctypes.rst:2358 ../../library/ctypes.rst:2368 +#: ../../library/ctypes.rst:2374 ../../library/ctypes.rst:2384 msgid "" "Raises an :ref:`auditing event ` ``ctypes.cdata/buffer`` with " "arguments ``pointer``, ``size``, ``offset``." @@ -4014,7 +4082,7 @@ msgstr "" "引發一個附帶引數 ``pointer``、``size``、``offset`` 的\\ :ref:`稽核事件 " "` ``ctypes.cdata/buffer``。" -#: ../../library/ctypes.rst:2362 +#: ../../library/ctypes.rst:2378 msgid "" "This method creates a ctypes instance, copying the buffer from the *source* " "object buffer which must be readable. The optional *offset* parameter " @@ -4022,19 +4090,19 @@ msgid "" "If the source buffer is not large enough a :exc:`ValueError` is raised." msgstr "" -#: ../../library/ctypes.rst:2372 +#: ../../library/ctypes.rst:2388 msgid "" "This method returns a ctypes type instance using the memory specified by " "*address* which must be an integer." msgstr "" -#: ../../library/ctypes.rst:2375 ../../library/ctypes.rst:2377 +#: ../../library/ctypes.rst:2391 ../../library/ctypes.rst:2393 msgid "" "This method, and others that indirectly call this method, raises an :ref:" "`auditing event ` ``ctypes.cdata`` with argument ``address``." msgstr "" -#: ../../library/ctypes.rst:2383 +#: ../../library/ctypes.rst:2399 msgid "" "This method adapts *obj* to a ctypes type. It is called with the actual " "object used in a foreign function call when the type is present in the " @@ -4042,36 +4110,36 @@ msgid "" "object that can be used as a function call parameter." msgstr "" -#: ../../library/ctypes.rst:2388 +#: ../../library/ctypes.rst:2404 msgid "" "All ctypes data types have a default implementation of this classmethod that " "normally returns *obj* if that is an instance of the type. Some types " "accept other objects as well." msgstr "" -#: ../../library/ctypes.rst:2394 +#: ../../library/ctypes.rst:2410 msgid "" "This method returns a ctypes type instance exported by a shared library. " "*name* is the name of the symbol that exports the data, *library* is the " "loaded shared library." msgstr "" -#: ../../library/ctypes.rst:2398 +#: ../../library/ctypes.rst:2414 msgid "Common class variables of ctypes data types:" msgstr "" -#: ../../library/ctypes.rst:2402 +#: ../../library/ctypes.rst:2418 msgid "" "The pointer type that was created by calling :func:`POINTER` for " "corresponding ctypes data type. If a pointer type was not yet created, the " "attribute is missing." msgstr "" -#: ../../library/ctypes.rst:2408 +#: ../../library/ctypes.rst:2424 msgid "Common instance variables of ctypes data types:" msgstr "" -#: ../../library/ctypes.rst:2412 +#: ../../library/ctypes.rst:2428 msgid "" "Sometimes ctypes data instances do not own the memory block they contain, " "instead they share part of the memory block of a base object. The :attr:" @@ -4079,13 +4147,13 @@ msgid "" "block." msgstr "" -#: ../../library/ctypes.rst:2419 +#: ../../library/ctypes.rst:2435 msgid "" "This read-only variable is true when the ctypes data instance has allocated " "the memory block itself, false otherwise." msgstr "" -#: ../../library/ctypes.rst:2424 +#: ../../library/ctypes.rst:2440 msgid "" "This member is either ``None`` or a dictionary containing Python objects " "that need to be kept alive so that the memory block contents is kept valid. " @@ -4093,7 +4161,7 @@ msgid "" "dictionary." msgstr "" -#: ../../library/ctypes.rst:2437 +#: ../../library/ctypes.rst:2453 msgid "" "This non-public class is the base class of all fundamental ctypes data " "types. It is mentioned here because it contains the common attributes of the " @@ -4102,11 +4170,11 @@ msgid "" "types that are not and do not contain pointers can now be pickled." msgstr "" -#: ../../library/ctypes.rst:2443 +#: ../../library/ctypes.rst:2459 msgid "Instances have a single attribute:" msgstr "" -#: ../../library/ctypes.rst:2447 +#: ../../library/ctypes.rst:2463 msgid "" "This attribute contains the actual value of the instance. For integer and " "pointer types, it is an integer, for character types, it is a single " @@ -4114,7 +4182,7 @@ msgid "" "bytes object or string." msgstr "" -#: ../../library/ctypes.rst:2452 +#: ../../library/ctypes.rst:2468 msgid "" "When the ``value`` attribute is retrieved from a ctypes instance, usually a " "new object is returned each time. :mod:`!ctypes` does *not* implement " @@ -4122,7 +4190,7 @@ msgid "" "true for all other ctypes object instances." msgstr "" -#: ../../library/ctypes.rst:2458 +#: ../../library/ctypes.rst:2474 msgid "" "Fundamental data types, when returned as foreign function call results, or, " "for example, by retrieving structure field members or array items, are " @@ -4132,7 +4200,7 @@ msgid "" "instance." msgstr "" -#: ../../library/ctypes.rst:2466 +#: ../../library/ctypes.rst:2482 msgid "" "Subclasses of fundamental data types do *not* inherit this behavior. So, if " "a foreign functions :attr:`!restype` is a subclass of :class:`c_void_p`, you " @@ -4140,25 +4208,25 @@ msgid "" "you can get the value of the pointer by accessing the ``value`` attribute." msgstr "" -#: ../../library/ctypes.rst:2471 +#: ../../library/ctypes.rst:2487 msgid "These are the fundamental ctypes data types:" msgstr "" -#: ../../library/ctypes.rst:2475 +#: ../../library/ctypes.rst:2491 msgid "" "Represents the C :c:expr:`signed char` datatype, and interprets the value as " "small integer. The constructor accepts an optional integer initializer; no " "overflow checking is done." msgstr "" -#: ../../library/ctypes.rst:2482 +#: ../../library/ctypes.rst:2498 msgid "" "Represents the C :c:expr:`char` datatype, and interprets the value as a " "single character. The constructor accepts an optional string initializer, " "the length of the string must be exactly one character." msgstr "" -#: ../../library/ctypes.rst:2489 +#: ../../library/ctypes.rst:2505 msgid "" "Represents the C :c:expr:`char *` datatype when it points to a zero-" "terminated string. For a general character pointer that may also point to " @@ -4166,204 +4234,204 @@ msgid "" "integer address, or a bytes object." msgstr "" -#: ../../library/ctypes.rst:2497 +#: ../../library/ctypes.rst:2513 msgid "" "Represents the C :c:expr:`double` datatype. The constructor accepts an " "optional float initializer." msgstr "" -#: ../../library/ctypes.rst:2503 +#: ../../library/ctypes.rst:2519 msgid "" "Represents the C :c:expr:`long double` datatype. The constructor accepts an " "optional float initializer. On platforms where ``sizeof(long double) == " "sizeof(double)`` it is an alias to :class:`c_double`." msgstr "" -#: ../../library/ctypes.rst:2509 +#: ../../library/ctypes.rst:2525 msgid "" "Represents the C :c:expr:`float` datatype. The constructor accepts an " "optional float initializer." msgstr "" -#: ../../library/ctypes.rst:2515 +#: ../../library/ctypes.rst:2531 msgid "" "Represents the C :c:expr:`double complex` datatype, if available. The " "constructor accepts an optional :class:`complex` initializer." msgstr "" -#: ../../library/ctypes.rst:2523 +#: ../../library/ctypes.rst:2539 msgid "" "Represents the C :c:expr:`float complex` datatype, if available. The " "constructor accepts an optional :class:`complex` initializer." msgstr "" -#: ../../library/ctypes.rst:2531 +#: ../../library/ctypes.rst:2547 msgid "" "Represents the C :c:expr:`long double complex` datatype, if available. The " "constructor accepts an optional :class:`complex` initializer." msgstr "" -#: ../../library/ctypes.rst:2539 +#: ../../library/ctypes.rst:2555 msgid "" "Represents the C :c:expr:`signed int` datatype. The constructor accepts an " "optional integer initializer; no overflow checking is done. On platforms " "where ``sizeof(int) == sizeof(long)`` it is an alias to :class:`c_long`." msgstr "" -#: ../../library/ctypes.rst:2546 +#: ../../library/ctypes.rst:2562 msgid "" "Represents the C 8-bit :c:expr:`signed int` datatype. It is an alias for :" "class:`c_byte`." msgstr "" -#: ../../library/ctypes.rst:2552 +#: ../../library/ctypes.rst:2568 msgid "" "Represents the C 16-bit :c:expr:`signed int` datatype. Usually an alias " "for :class:`c_short`." msgstr "" -#: ../../library/ctypes.rst:2558 +#: ../../library/ctypes.rst:2574 msgid "" "Represents the C 32-bit :c:expr:`signed int` datatype. Usually an alias " "for :class:`c_int`." msgstr "" -#: ../../library/ctypes.rst:2564 +#: ../../library/ctypes.rst:2580 msgid "" "Represents the C 64-bit :c:expr:`signed int` datatype. Usually an alias " "for :class:`c_longlong`." msgstr "" -#: ../../library/ctypes.rst:2570 +#: ../../library/ctypes.rst:2586 msgid "" "Represents the C :c:expr:`signed long` datatype. The constructor accepts an " "optional integer initializer; no overflow checking is done." msgstr "" -#: ../../library/ctypes.rst:2576 +#: ../../library/ctypes.rst:2592 msgid "" "Represents the C :c:expr:`signed long long` datatype. The constructor " "accepts an optional integer initializer; no overflow checking is done." msgstr "" -#: ../../library/ctypes.rst:2582 +#: ../../library/ctypes.rst:2598 msgid "" "Represents the C :c:expr:`signed short` datatype. The constructor accepts " "an optional integer initializer; no overflow checking is done." msgstr "" -#: ../../library/ctypes.rst:2588 +#: ../../library/ctypes.rst:2604 msgid "Represents the C :c:type:`size_t` datatype." msgstr "" -#: ../../library/ctypes.rst:2593 +#: ../../library/ctypes.rst:2609 msgid "Represents the C :c:type:`ssize_t` datatype." msgstr "" -#: ../../library/ctypes.rst:2600 +#: ../../library/ctypes.rst:2616 msgid "Represents the C :c:type:`time_t` datatype." msgstr "" -#: ../../library/ctypes.rst:2607 +#: ../../library/ctypes.rst:2623 msgid "" "Represents the C :c:expr:`unsigned char` datatype, it interprets the value " "as small integer. The constructor accepts an optional integer initializer; " "no overflow checking is done." msgstr "" -#: ../../library/ctypes.rst:2614 +#: ../../library/ctypes.rst:2630 msgid "" "Represents the C :c:expr:`unsigned int` datatype. The constructor accepts " "an optional integer initializer; no overflow checking is done. On platforms " "where ``sizeof(int) == sizeof(long)`` it is an alias for :class:`c_ulong`." msgstr "" -#: ../../library/ctypes.rst:2621 +#: ../../library/ctypes.rst:2637 msgid "" "Represents the C 8-bit :c:expr:`unsigned int` datatype. It is an alias for :" "class:`c_ubyte`." msgstr "" -#: ../../library/ctypes.rst:2627 +#: ../../library/ctypes.rst:2643 msgid "" "Represents the C 16-bit :c:expr:`unsigned int` datatype. Usually an alias " "for :class:`c_ushort`." msgstr "" -#: ../../library/ctypes.rst:2633 +#: ../../library/ctypes.rst:2649 msgid "" "Represents the C 32-bit :c:expr:`unsigned int` datatype. Usually an alias " "for :class:`c_uint`." msgstr "" -#: ../../library/ctypes.rst:2639 +#: ../../library/ctypes.rst:2655 msgid "" "Represents the C 64-bit :c:expr:`unsigned int` datatype. Usually an alias " "for :class:`c_ulonglong`." msgstr "" -#: ../../library/ctypes.rst:2645 +#: ../../library/ctypes.rst:2661 msgid "" "Represents the C :c:expr:`unsigned long` datatype. The constructor accepts " "an optional integer initializer; no overflow checking is done." msgstr "" -#: ../../library/ctypes.rst:2651 +#: ../../library/ctypes.rst:2667 msgid "" "Represents the C :c:expr:`unsigned long long` datatype. The constructor " "accepts an optional integer initializer; no overflow checking is done." msgstr "" -#: ../../library/ctypes.rst:2657 +#: ../../library/ctypes.rst:2673 msgid "" "Represents the C :c:expr:`unsigned short` datatype. The constructor accepts " "an optional integer initializer; no overflow checking is done." msgstr "" -#: ../../library/ctypes.rst:2663 +#: ../../library/ctypes.rst:2679 msgid "" "Represents the C :c:expr:`void *` type. The value is represented as " "integer. The constructor accepts an optional integer initializer." msgstr "" -#: ../../library/ctypes.rst:2669 +#: ../../library/ctypes.rst:2685 msgid "" "Represents the C :c:type:`wchar_t` datatype, and interprets the value as a " "single character unicode string. The constructor accepts an optional string " "initializer, the length of the string must be exactly one character." msgstr "" -#: ../../library/ctypes.rst:2676 +#: ../../library/ctypes.rst:2692 msgid "" "Represents the C :c:expr:`wchar_t *` datatype, which must be a pointer to a " "zero-terminated wide character string. The constructor accepts an integer " "address, or a string." msgstr "" -#: ../../library/ctypes.rst:2683 +#: ../../library/ctypes.rst:2699 msgid "" "Represent the C :c:expr:`bool` datatype (more accurately, :c:expr:`_Bool` " "from C99). Its value can be ``True`` or ``False``, and the constructor " "accepts any object that has a truth value." msgstr "" -#: ../../library/ctypes.rst:2690 +#: ../../library/ctypes.rst:2706 msgid "" "Represents a :c:type:`!HRESULT` value, which contains success or error " "information for a function or method call." msgstr "" -#: ../../library/ctypes.rst:2698 +#: ../../library/ctypes.rst:2714 msgid "" "Represents the C :c:expr:`PyObject *` datatype. Calling this without an " "argument creates a ``NULL`` :c:expr:`PyObject *` pointer." msgstr "" -#: ../../library/ctypes.rst:2701 +#: ../../library/ctypes.rst:2717 msgid ":class:`!py_object` is now a :term:`generic type`." msgstr "" -#: ../../library/ctypes.rst:2704 +#: ../../library/ctypes.rst:2720 msgid "" "The :mod:`!ctypes.wintypes` module provides quite some other Windows " "specific data types, for example :c:type:`!HWND`, :c:type:`!WPARAM`, or :c:" @@ -4371,47 +4439,47 @@ msgid "" "are also defined." msgstr "" -#: ../../library/ctypes.rst:2712 +#: ../../library/ctypes.rst:2728 msgid "Structured data types" msgstr "" -#: ../../library/ctypes.rst:2717 +#: ../../library/ctypes.rst:2733 msgid "Abstract base class for unions in native byte order." msgstr "" -#: ../../library/ctypes.rst:2719 +#: ../../library/ctypes.rst:2735 msgid "" "Unions share common attributes and behavior with structures; see :class:" "`Structure` documentation for details." msgstr "" -#: ../../library/ctypes.rst:2724 +#: ../../library/ctypes.rst:2740 msgid "Abstract base class for unions in *big endian* byte order." msgstr "" -#: ../../library/ctypes.rst:2730 +#: ../../library/ctypes.rst:2746 msgid "Abstract base class for unions in *little endian* byte order." msgstr "" -#: ../../library/ctypes.rst:2736 +#: ../../library/ctypes.rst:2752 msgid "Abstract base class for structures in *big endian* byte order." msgstr "" -#: ../../library/ctypes.rst:2741 +#: ../../library/ctypes.rst:2757 msgid "Abstract base class for structures in *little endian* byte order." msgstr "" -#: ../../library/ctypes.rst:2743 +#: ../../library/ctypes.rst:2759 msgid "" "Structures and unions with non-native byte order cannot contain pointer type " "fields, or any other data types containing pointer type fields." msgstr "" -#: ../../library/ctypes.rst:2749 +#: ../../library/ctypes.rst:2765 msgid "Abstract base class for structures in *native* byte order." msgstr "" -#: ../../library/ctypes.rst:2751 +#: ../../library/ctypes.rst:2767 msgid "" "Concrete structure and union types must be created by subclassing one of " "these types, and at least define a :attr:`_fields_` class variable. :mod:`!" @@ -4419,34 +4487,34 @@ msgid "" "the fields by direct attribute accesses. These are the" msgstr "" -#: ../../library/ctypes.rst:2759 +#: ../../library/ctypes.rst:2775 msgid "" "A sequence defining the structure fields. The items must be 2-tuples or 3-" "tuples. The first item is the name of the field, the second item specifies " "the type of the field; it can be any ctypes data type." msgstr "" -#: ../../library/ctypes.rst:2763 +#: ../../library/ctypes.rst:2779 msgid "" "For integer type fields like :class:`c_int`, a third optional item can be " "given. It must be a small positive integer defining the bit width of the " "field." msgstr "" -#: ../../library/ctypes.rst:2767 +#: ../../library/ctypes.rst:2783 msgid "" "Field names must be unique within one structure or union. This is not " "checked, only one field can be accessed when names are repeated." msgstr "" -#: ../../library/ctypes.rst:2770 +#: ../../library/ctypes.rst:2786 msgid "" "It is possible to define the :attr:`_fields_` class variable *after* the " "class statement that defines the Structure subclass, this allows creating " "data types that directly or indirectly reference themselves::" msgstr "" -#: ../../library/ctypes.rst:2774 +#: ../../library/ctypes.rst:2790 msgid "" "class List(Structure):\n" " pass\n" @@ -4460,13 +4528,13 @@ msgstr "" " ...\n" " ]" -#: ../../library/ctypes.rst:2780 +#: ../../library/ctypes.rst:2796 msgid "" "The :attr:`!_fields_` class variable can only be set once. Later assignments " "will raise an :exc:`AttributeError`." msgstr "" -#: ../../library/ctypes.rst:2783 +#: ../../library/ctypes.rst:2799 msgid "" "Additionally, the :attr:`!_fields_` class variable must be defined before " "the structure or union type is first used: an instance or subclass is " @@ -4476,25 +4544,25 @@ msgid "" "fields, as if :attr:`!_fields_` was empty." msgstr "" -#: ../../library/ctypes.rst:2791 +#: ../../library/ctypes.rst:2807 msgid "" "Sub-subclasses of structure types inherit the fields of the base class plus " "the :attr:`_fields_` defined in the sub-subclass, if any." msgstr "" -#: ../../library/ctypes.rst:2797 +#: ../../library/ctypes.rst:2813 msgid "" "An optional small integer that allows overriding the alignment of structure " "fields in the instance." msgstr "" -#: ../../library/ctypes.rst:2800 +#: ../../library/ctypes.rst:2816 msgid "" "This is only implemented for the MSVC-compatible memory layout (see :attr:" "`_layout_`)." msgstr "" -#: ../../library/ctypes.rst:2803 +#: ../../library/ctypes.rst:2819 msgid "" "Setting :attr:`!_pack_` to 0 is the same as not setting it at all. " "Otherwise, the value must be a positive power of two. The effect is " @@ -4502,13 +4570,13 @@ msgid "" "larger *n* than what the compiler accepts." msgstr "" -#: ../../library/ctypes.rst:2808 +#: ../../library/ctypes.rst:2824 msgid "" ":attr:`!_pack_` must already be defined when :attr:`_fields_` is assigned, " "otherwise it will have no effect." msgstr "" -#: ../../library/ctypes.rst:2813 +#: ../../library/ctypes.rst:2829 msgid "" "For historical reasons, if :attr:`!_pack_` is non-zero, the MSVC-compatible " "layout will be used by default. On non-Windows platforms, this default is " @@ -4516,57 +4584,57 @@ msgid "" "intended, set :attr:`~Structure._layout_` to ``'ms'`` explicitly." msgstr "" -#: ../../library/ctypes.rst:2822 +#: ../../library/ctypes.rst:2838 msgid "" "An optional small integer that allows increasing the alignment of the " "structure when being packed or unpacked to/from memory." msgstr "" -#: ../../library/ctypes.rst:2825 +#: ../../library/ctypes.rst:2841 msgid "" "The value must not be negative. The effect is equivalent to " "``__attribute__((aligned(N)))`` on GCC or ``#pragma align(N)`` on MSVC, " "except :mod:`!ctypes` may allow values that the compiler would reject." msgstr "" -#: ../../library/ctypes.rst:2830 +#: ../../library/ctypes.rst:2846 msgid "" ":attr:`!_align_` can only *increase* a structure's alignment requirements. " "Setting it to 0 or 1 has no effect." msgstr "" -#: ../../library/ctypes.rst:2833 +#: ../../library/ctypes.rst:2849 msgid "" "Using values that are not powers of two is discouraged and may lead to " "surprising behavior." msgstr "" -#: ../../library/ctypes.rst:2836 +#: ../../library/ctypes.rst:2852 msgid "" ":attr:`!_align_` must already be defined when :attr:`_fields_` is assigned, " "otherwise it will have no effect." msgstr "" -#: ../../library/ctypes.rst:2843 +#: ../../library/ctypes.rst:2859 msgid "" "An optional string naming the struct/union layout. It can currently be set " "to:" msgstr "" -#: ../../library/ctypes.rst:2846 +#: ../../library/ctypes.rst:2862 msgid "" "``\"ms\"``: the layout used by the Microsoft compiler (MSVC). On GCC and " "Clang, this layout can be selected with ``__attribute__((ms_struct))``." msgstr "" -#: ../../library/ctypes.rst:2849 +#: ../../library/ctypes.rst:2865 msgid "" "``\"gcc-sysv\"``: the layout used by GCC with the System V or “SysV-like” " "data model, as used on Linux and macOS. With this layout, :attr:`~Structure." "_pack_` must be unset or zero." msgstr "" -#: ../../library/ctypes.rst:2853 +#: ../../library/ctypes.rst:2869 msgid "" "If not set explicitly, ``ctypes`` will use a default that matches the " "platform conventions. This default may change in future Python releases (for " @@ -4574,34 +4642,34 @@ msgid "" "between similar platforms is found). Currently the default will be:" msgstr "" -#: ../../library/ctypes.rst:2859 +#: ../../library/ctypes.rst:2875 msgid "On Windows: ``\"ms\"``" msgstr "" -#: ../../library/ctypes.rst:2860 +#: ../../library/ctypes.rst:2876 msgid "" "When :attr:`~Structure._pack_` is specified: ``\"ms\"``. (This is " "deprecated; see :attr:`~Structure._pack_` documentation.)" msgstr "" -#: ../../library/ctypes.rst:2862 +#: ../../library/ctypes.rst:2878 msgid "Otherwise: ``\"gcc-sysv\"``" msgstr "" -#: ../../library/ctypes.rst:2864 +#: ../../library/ctypes.rst:2880 msgid "" ":attr:`!_layout_` must already be defined when :attr:`~Structure._fields_` " "is assigned, otherwise it will have no effect." msgstr "" -#: ../../library/ctypes.rst:2871 +#: ../../library/ctypes.rst:2887 msgid "" "An optional sequence that lists the names of unnamed (anonymous) fields. :" "attr:`_anonymous_` must be already defined when :attr:`_fields_` is " "assigned, otherwise it will have no effect." msgstr "" -#: ../../library/ctypes.rst:2875 +#: ../../library/ctypes.rst:2891 msgid "" "The fields listed in this variable must be structure or union type fields. :" "mod:`!ctypes` will create descriptors in the structure type that allows " @@ -4609,11 +4677,11 @@ msgid "" "structure or union field." msgstr "" -#: ../../library/ctypes.rst:2880 +#: ../../library/ctypes.rst:2896 msgid "Here is an example type (Windows)::" msgstr "" -#: ../../library/ctypes.rst:2882 +#: ../../library/ctypes.rst:2898 msgid "" "class _U(Union):\n" " _fields_ = [(\"lptdesc\", POINTER(TYPEDESC)),\n" @@ -4635,7 +4703,7 @@ msgstr "" " _fields_ = [(\"u\", _U),\n" " (\"vt\", VARTYPE)]" -#: ../../library/ctypes.rst:2893 +#: ../../library/ctypes.rst:2909 msgid "" "The ``TYPEDESC`` structure describes a COM data type, the ``vt`` field " "specifies which one of the union fields is valid. Since the ``u`` field is " @@ -4645,7 +4713,7 @@ msgid "" "temporary union instance::" msgstr "" -#: ../../library/ctypes.rst:2900 +#: ../../library/ctypes.rst:2916 msgid "" "td = TYPEDESC()\n" "td.vt = VT_PTR\n" @@ -4657,7 +4725,7 @@ msgstr "" "td.lptdesc = POINTER(some_type)\n" "td.u.lptdesc = POINTER(some_type)" -#: ../../library/ctypes.rst:2905 +#: ../../library/ctypes.rst:2921 msgid "" "It is possible to define sub-subclasses of structures, they inherit the " "fields of the base class. If the subclass definition has a separate :attr:" @@ -4665,7 +4733,7 @@ msgid "" "of the base class." msgstr "" -#: ../../library/ctypes.rst:2910 +#: ../../library/ctypes.rst:2926 msgid "" "Structure and union constructors accept both positional and keyword " "arguments. Positional arguments are used to initialize member fields in the " @@ -4675,13 +4743,13 @@ msgid "" "names not present in :attr:`_fields_`." msgstr "" -#: ../../library/ctypes.rst:2920 +#: ../../library/ctypes.rst:2936 msgid "" "Descriptor for fields of a :class:`Structure` and :class:`Union`. For " "example::" msgstr "" -#: ../../library/ctypes.rst:2923 +#: ../../library/ctypes.rst:2939 msgid "" ">>> class Color(Structure):\n" "... _fields_ = (\n" @@ -4723,100 +4791,100 @@ msgstr "" ">>> Color.blinking.bit_offset\n" "1" -#: ../../library/ctypes.rst:2943 +#: ../../library/ctypes.rst:2959 msgid "All attributes are read-only." msgstr "" -#: ../../library/ctypes.rst:2945 +#: ../../library/ctypes.rst:2961 msgid "" ":class:`!CField` objects are created via :attr:`~Structure._fields_`; do not " "instantiate the class directly." msgstr "" -#: ../../library/ctypes.rst:2950 +#: ../../library/ctypes.rst:2966 msgid "" "Previously, descriptors only had ``offset`` and ``size`` attributes and a " "readable string representation; the :class:`!CField` class was not available " "directly." msgstr "" -#: ../../library/ctypes.rst:2956 +#: ../../library/ctypes.rst:2972 msgid "Name of the field, as a string." msgstr "" -#: ../../library/ctypes.rst:2960 +#: ../../library/ctypes.rst:2976 msgid "Type of the field, as a :ref:`ctypes class `." msgstr "" -#: ../../library/ctypes.rst:2965 +#: ../../library/ctypes.rst:2981 msgid "Offset of the field, in bytes." msgstr "" -#: ../../library/ctypes.rst:2967 +#: ../../library/ctypes.rst:2983 msgid "" "For bitfields, this is the offset of the underlying byte-aligned *storage " "unit*; see :attr:`~CField.bit_offset`." msgstr "" -#: ../../library/ctypes.rst:2972 +#: ../../library/ctypes.rst:2988 msgid "Size of the field, in bytes." msgstr "" -#: ../../library/ctypes.rst:2974 +#: ../../library/ctypes.rst:2990 msgid "" "For bitfields, this is the size of the underlying *storage unit*. Typically, " "it has the same size as the bitfield's type." msgstr "" -#: ../../library/ctypes.rst:2979 +#: ../../library/ctypes.rst:2995 msgid "For non-bitfields, equivalent to :attr:`~CField.byte_size`." msgstr "" -#: ../../library/ctypes.rst:2981 +#: ../../library/ctypes.rst:2997 msgid "" "For bitfields, this contains a backwards-compatible bit-packed value that " "combines :attr:`~CField.bit_size` and :attr:`~CField.bit_offset`. Prefer " "using the explicit attributes instead." msgstr "" -#: ../../library/ctypes.rst:2988 +#: ../../library/ctypes.rst:3004 msgid "True if this is a bitfield." msgstr "" -#: ../../library/ctypes.rst:2993 +#: ../../library/ctypes.rst:3009 msgid "" "The location of a bitfield within its *storage unit*, that is, within :attr:" "`~CField.byte_size` bytes of memory starting at :attr:`~CField.byte_offset`." msgstr "" -#: ../../library/ctypes.rst:2997 +#: ../../library/ctypes.rst:3013 msgid "" "To get the field's value, read the storage unit as an integer, :ref:`shift " "left ` by :attr:`!bit_offset` and take the :attr:`!bit_size` least " "significant bits." msgstr "" -#: ../../library/ctypes.rst:3001 +#: ../../library/ctypes.rst:3017 msgid "" "For non-bitfields, :attr:`!bit_offset` is zero and :attr:`!bit_size` is " "equal to ``byte_size * 8``." msgstr "" -#: ../../library/ctypes.rst:3006 +#: ../../library/ctypes.rst:3022 msgid "" "True if this field is anonymous, that is, it contains nested sub-fields that " "should be merged into a containing structure or union." msgstr "" -#: ../../library/ctypes.rst:3013 +#: ../../library/ctypes.rst:3029 msgid "Arrays and pointers" msgstr "" -#: ../../library/ctypes.rst:3017 +#: ../../library/ctypes.rst:3033 msgid "Abstract base class for arrays." msgstr "" -#: ../../library/ctypes.rst:3019 +#: ../../library/ctypes.rst:3035 msgid "" "The recommended way to create concrete array types is by multiplying any :" "mod:`!ctypes` data type with a non-negative integer. Alternatively, you can " @@ -4826,46 +4894,46 @@ msgid "" "an :class:`Array`." msgstr "" -#: ../../library/ctypes.rst:3029 +#: ../../library/ctypes.rst:3045 msgid "" "A positive integer specifying the number of elements in the array. Out-of-" "range subscripts result in an :exc:`IndexError`. Will be returned by :func:" "`len`." msgstr "" -#: ../../library/ctypes.rst:3036 +#: ../../library/ctypes.rst:3052 msgid "Specifies the type of each element in the array." msgstr "" -#: ../../library/ctypes.rst:3039 +#: ../../library/ctypes.rst:3055 msgid "" "Array subclass constructors accept positional arguments, used to initialize " "the elements in order." msgstr "" -#: ../../library/ctypes.rst:3044 +#: ../../library/ctypes.rst:3060 msgid "" "Create an array. Equivalent to ``type * length``, where *type* is a :mod:`!" "ctypes` data type and *length* an integer." msgstr "" -#: ../../library/ctypes.rst:3048 +#: ../../library/ctypes.rst:3064 msgid "" "This function is :term:`soft deprecated` in favor of multiplication. There " "are no plans to remove it." msgstr "" -#: ../../library/ctypes.rst:3054 +#: ../../library/ctypes.rst:3070 msgid "Private, abstract base class for pointers." msgstr "" -#: ../../library/ctypes.rst:3056 +#: ../../library/ctypes.rst:3072 msgid "" "Concrete pointer types are created by calling :func:`POINTER` with the type " "that will be pointed to; this is done automatically by :func:`pointer`." msgstr "" -#: ../../library/ctypes.rst:3060 +#: ../../library/ctypes.rst:3076 msgid "" "If a pointer points to an array, its elements can be read and written using " "standard subscript and slice accesses. Pointer objects have no size, so :" @@ -4874,43 +4942,43 @@ msgid "" "probably crash with an access violation (if you're lucky)." msgstr "" -#: ../../library/ctypes.rst:3070 +#: ../../library/ctypes.rst:3086 msgid "Specifies the type pointed to." msgstr "" -#: ../../library/ctypes.rst:3074 +#: ../../library/ctypes.rst:3090 msgid "" "Returns the object to which to pointer points. Assigning to this attribute " "changes the pointer to point to the assigned object." msgstr "" -#: ../../library/ctypes.rst:3081 +#: ../../library/ctypes.rst:3097 msgid "Exceptions" msgstr "" -#: ../../library/ctypes.rst:3085 +#: ../../library/ctypes.rst:3101 msgid "" "This exception is raised when a foreign function call cannot convert one of " "the passed arguments." msgstr "" -#: ../../library/ctypes.rst:3091 +#: ../../library/ctypes.rst:3107 msgid "This exception is raised when a COM method call failed." msgstr "" -#: ../../library/ctypes.rst:3095 +#: ../../library/ctypes.rst:3111 msgid "The integer value representing the error code." msgstr "" -#: ../../library/ctypes.rst:3099 +#: ../../library/ctypes.rst:3115 msgid "The error message." msgstr "" -#: ../../library/ctypes.rst:3103 +#: ../../library/ctypes.rst:3119 msgid "The 5-tuple ``(descr, source, helpfile, helpcontext, progid)``." msgstr "" -#: ../../library/ctypes.rst:3105 +#: ../../library/ctypes.rst:3121 msgid "" "*descr* is the textual description. *source* is the language-dependent " "``ProgID`` for the class or application that raised the error. *helpfile* " diff --git a/library/datetime.po b/library/datetime.po index 09a14f1d4f8..f7eb95cd7ad 100644 --- a/library/datetime.po +++ b/library/datetime.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-19 00:20+0000\n" +"POT-Creation-Date: 2026-03-11 00:16+0000\n" "PO-Revision-Date: 2023-08-07 10:20+0800\n" "Last-Translator: Griiid \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -120,7 +120,7 @@ msgid "" "For applications requiring aware objects, :class:`.datetime` and :class:`." "time` objects have an optional time zone information attribute, :attr:`!" "tzinfo`, that can be set to an instance of a subclass of the abstract :class:" -"`tzinfo` class. These :class:`tzinfo` objects capture information about the " +"`!tzinfo` class. These :class:`tzinfo` objects capture information about the " "offset from UTC time, the time zone name, and whether daylight saving time " "is in effect." msgstr "" @@ -363,8 +363,8 @@ msgstr "" #: ../../library/datetime.rst:237 msgid "" -">>> from datetime import timedelta\n" -">>> delta = timedelta(\n" +">>> import datetime as dt\n" +">>> delta = dt.timedelta(\n" "... days=50,\n" "... seconds=27,\n" "... microseconds=10,\n" @@ -378,7 +378,15 @@ msgid "" "datetime.timedelta(days=64, seconds=29156, microseconds=10)" msgstr "" -#: ../../library/datetime.rst:251 +#: ../../library/datetime.rst:252 +msgid "" +"``import datetime as dt`` instead of ``import datetime`` or ``from datetime " +"import datetime`` to avoid confusion between the module and the class. See " +"`How I Import Python’s datetime Module `__." +msgstr "" + +#: ../../library/datetime.rst:257 msgid "" "If any argument is a float and there are fractional microseconds, the " "fractional microseconds left over from all arguments are combined and their " @@ -387,22 +395,23 @@ msgid "" "processes are exact (no information is lost)." msgstr "" -#: ../../library/datetime.rst:258 +#: ../../library/datetime.rst:264 msgid "" "If the normalized value of days lies outside the indicated range, :exc:" "`OverflowError` is raised." msgstr "" -#: ../../library/datetime.rst:261 +#: ../../library/datetime.rst:267 msgid "" "Note that normalization of negative values may be surprising at first. For " "example::" msgstr "" -#: ../../library/datetime.rst:264 +#: ../../library/datetime.rst:270 +#, fuzzy msgid "" -">>> from datetime import timedelta\n" -">>> d = timedelta(microseconds=-1)\n" +">>> import datetime as dt\n" +">>> d = dt.timedelta(microseconds=-1)\n" ">>> (d.days, d.seconds, d.microseconds)\n" "(-1, 86399, 999999)" msgstr "" @@ -411,13 +420,13 @@ msgstr "" ">>> (d.days, d.seconds, d.microseconds)\n" "(-1, 86399, 999999)" -#: ../../library/datetime.rst:269 +#: ../../library/datetime.rst:275 msgid "" "Since the string representation of :class:`!timedelta` objects can be " "confusing, use the following recipe to produce a more readable format:" msgstr "" -#: ../../library/datetime.rst:272 +#: ../../library/datetime.rst:278 msgid "" ">>> def pretty_timedelta(td):\n" "... if td.days >= 0:\n" @@ -441,59 +450,60 @@ msgstr "" ">>> pretty_timedelta(d)\n" "'-(1:00:00)'" -#: ../../library/datetime.rst:286 ../../library/datetime.rst:624 -#: ../../library/datetime.rst:1194 ../../library/datetime.rst:1839 -#: ../../library/datetime.rst:2467 +#: ../../library/datetime.rst:292 ../../library/datetime.rst:630 +#: ../../library/datetime.rst:1200 ../../library/datetime.rst:1845 +#: ../../library/datetime.rst:2481 msgid "Class attributes:" msgstr "類別屬性:" -#: ../../library/datetime.rst:290 +#: ../../library/datetime.rst:296 msgid "The most negative :class:`timedelta` object, ``timedelta(-999999999)``." msgstr "" -#: ../../library/datetime.rst:295 +#: ../../library/datetime.rst:301 msgid "" "The most positive :class:`timedelta` object, ``timedelta(days=999999999, " "hours=23, minutes=59, seconds=59, microseconds=999999)``." msgstr "" -#: ../../library/datetime.rst:301 +#: ../../library/datetime.rst:307 msgid "" "The smallest possible difference between non-equal :class:`timedelta` " "objects, ``timedelta(microseconds=1)``." msgstr "" -#: ../../library/datetime.rst:305 +#: ../../library/datetime.rst:311 msgid "" "Note that, because of normalization, ``timedelta.max`` is greater than ``-" "timedelta.min``. ``-timedelta.max`` is not representable as a :class:" "`timedelta` object." msgstr "" -#: ../../library/datetime.rst:309 ../../library/datetime.rst:642 -#: ../../library/datetime.rst:1214 ../../library/datetime.rst:1859 +#: ../../library/datetime.rst:315 ../../library/datetime.rst:648 +#: ../../library/datetime.rst:1220 ../../library/datetime.rst:1865 msgid "Instance attributes (read-only):" msgstr "" -#: ../../library/datetime.rst:313 +#: ../../library/datetime.rst:319 msgid "Between -999,999,999 and 999,999,999 inclusive." msgstr "在 -999,999,999 到 999,999,999 (含)之間" -#: ../../library/datetime.rst:318 +#: ../../library/datetime.rst:324 msgid "Between 0 and 86,399 inclusive." msgstr "在 0 到 86,399 (含)之間" -#: ../../library/datetime.rst:322 +#: ../../library/datetime.rst:328 msgid "" "It is a somewhat common bug for code to unintentionally use this attribute " "when it is actually intended to get a :meth:`~timedelta.total_seconds` value " "instead:" msgstr "" -#: ../../library/datetime.rst:326 +#: ../../library/datetime.rst:332 +#, fuzzy msgid "" -">>> from datetime import timedelta\n" -">>> duration = timedelta(seconds=11235813)\n" +">>> import datetime as dt\n" +">>> duration = dt.timedelta(seconds=11235813)\n" ">>> duration.days, duration.seconds\n" "(130, 3813)\n" ">>> duration.total_seconds()\n" @@ -506,130 +516,130 @@ msgstr "" ">>> duration.total_seconds()\n" "11235813.0" -#: ../../library/datetime.rst:338 +#: ../../library/datetime.rst:344 msgid "Between 0 and 999,999 inclusive." msgstr "在 0 到 999,999 (含)之間" -#: ../../library/datetime.rst:341 ../../library/datetime.rst:659 -#: ../../library/datetime.rst:1268 +#: ../../library/datetime.rst:347 ../../library/datetime.rst:665 +#: ../../library/datetime.rst:1274 msgid "Supported operations:" msgstr "" -#: ../../library/datetime.rst:344 ../../library/datetime.rst:662 -#: ../../library/datetime.rst:1271 +#: ../../library/datetime.rst:350 ../../library/datetime.rst:668 +#: ../../library/datetime.rst:1277 msgid "Operation" msgstr "" -#: ../../library/datetime.rst:344 ../../library/datetime.rst:662 -#: ../../library/datetime.rst:1271 +#: ../../library/datetime.rst:350 ../../library/datetime.rst:668 +#: ../../library/datetime.rst:1277 msgid "Result" msgstr "" -#: ../../library/datetime.rst:346 +#: ../../library/datetime.rst:352 msgid "``t1 = t2 + t3``" msgstr "``t1 = t2 + t3``" -#: ../../library/datetime.rst:346 +#: ../../library/datetime.rst:352 msgid "" "Sum of ``t2`` and ``t3``. Afterwards ``t1 - t2 == t3`` and ``t1 - t3 == t2`` " "are true. (1)" msgstr "" -#: ../../library/datetime.rst:350 +#: ../../library/datetime.rst:356 msgid "``t1 = t2 - t3``" msgstr "``t1 = t2 - t3``" -#: ../../library/datetime.rst:350 +#: ../../library/datetime.rst:356 msgid "" "Difference of ``t2`` and ``t3``. Afterwards ``t1 == t2 - t3`` and ``t2 == " "t1 + t3`` are true. (1)(6)" msgstr "" -#: ../../library/datetime.rst:354 +#: ../../library/datetime.rst:360 msgid "``t1 = t2 * i or t1 = i * t2``" msgstr "``t1 = t2 * i or t1 = i * t2``" -#: ../../library/datetime.rst:354 +#: ../../library/datetime.rst:360 msgid "" "Delta multiplied by an integer. Afterwards ``t1 // i == t2`` is true, " "provided ``i != 0``." msgstr "" -#: ../../library/datetime.rst:358 +#: ../../library/datetime.rst:364 msgid "In general, ``t1 * i == t1 * (i-1) + t1`` is true. (1)" msgstr "" -#: ../../library/datetime.rst:361 +#: ../../library/datetime.rst:367 msgid "``t1 = t2 * f or t1 = f * t2``" msgstr "``t1 = t2 * f or t1 = f * t2``" -#: ../../library/datetime.rst:361 +#: ../../library/datetime.rst:367 msgid "" "Delta multiplied by a float. The result is rounded to the nearest multiple " "of timedelta.resolution using round-half-to-even." msgstr "" -#: ../../library/datetime.rst:365 +#: ../../library/datetime.rst:371 msgid "``f = t2 / t3``" msgstr "``f = t2 / t3``" -#: ../../library/datetime.rst:365 +#: ../../library/datetime.rst:371 msgid "" "Division (3) of overall duration ``t2`` by interval unit ``t3``. Returns a :" "class:`float` object." msgstr "" -#: ../../library/datetime.rst:369 +#: ../../library/datetime.rst:375 msgid "``t1 = t2 / f or t1 = t2 / i``" msgstr "``t1 = t2 / f or t1 = t2 / i``" -#: ../../library/datetime.rst:369 +#: ../../library/datetime.rst:375 msgid "" "Delta divided by a float or an int. The result is rounded to the nearest " "multiple of timedelta.resolution using round-half-to-even." msgstr "" -#: ../../library/datetime.rst:373 +#: ../../library/datetime.rst:379 msgid "``t1 = t2 // i`` or ``t1 = t2 // t3``" msgstr "``t1 = t2 // i`` or ``t1 = t2 // t3``" -#: ../../library/datetime.rst:373 +#: ../../library/datetime.rst:379 msgid "" "The floor is computed and the remainder (if any) is thrown away. In the " "second case, an integer is returned. (3)" msgstr "" -#: ../../library/datetime.rst:377 +#: ../../library/datetime.rst:383 msgid "``t1 = t2 % t3``" msgstr "``t1 = t2 % t3``" -#: ../../library/datetime.rst:377 +#: ../../library/datetime.rst:383 msgid "The remainder is computed as a :class:`timedelta` object. (3)" msgstr "" -#: ../../library/datetime.rst:380 +#: ../../library/datetime.rst:386 msgid "``q, r = divmod(t1, t2)``" msgstr "``q, r = divmod(t1, t2)``" -#: ../../library/datetime.rst:380 +#: ../../library/datetime.rst:386 msgid "" "Computes the quotient and the remainder: ``q = t1 // t2`` (3) and ``r = t1 % " "t2``. ``q`` is an integer and ``r`` is a :class:`timedelta` object." msgstr "" -#: ../../library/datetime.rst:385 +#: ../../library/datetime.rst:391 msgid "``+t1``" msgstr "``+t1``" -#: ../../library/datetime.rst:385 +#: ../../library/datetime.rst:391 msgid "Returns a :class:`timedelta` object with the same value. (2)" msgstr "" -#: ../../library/datetime.rst:388 +#: ../../library/datetime.rst:394 msgid "``-t1``" msgstr "``-t1``" -#: ../../library/datetime.rst:388 +#: ../../library/datetime.rst:394 msgid "" "Equivalent to ``timedelta(-t1.days, -t1.seconds, -t1.microseconds)``, and to " "``t1 * -1``. (1)(4)" @@ -637,65 +647,65 @@ msgstr "" "等價於 ``timedelta(-t1.days, -t1.seconds, -t1.microseconds)``,也等價於 ``t1 " "* -1``。 (1)(4)" -#: ../../library/datetime.rst:392 +#: ../../library/datetime.rst:398 msgid "``abs(t)``" msgstr "``abs(t)``" -#: ../../library/datetime.rst:392 +#: ../../library/datetime.rst:398 msgid "" "Equivalent to ``+t`` when ``t.days >= 0``, and to ``-t`` when ``t.days < " "0``. (2)" msgstr "" -#: ../../library/datetime.rst:395 +#: ../../library/datetime.rst:401 msgid "``str(t)``" msgstr "``str(t)``" -#: ../../library/datetime.rst:395 +#: ../../library/datetime.rst:401 msgid "" "Returns a string in the form ``[D day[s], ][H]H:MM:SS[.UUUUUU]``, where D is " "negative for negative ``t``. (5)" msgstr "" -#: ../../library/datetime.rst:399 +#: ../../library/datetime.rst:405 msgid "``repr(t)``" msgstr "``repr(t)``" -#: ../../library/datetime.rst:399 +#: ../../library/datetime.rst:405 msgid "" "Returns a string representation of the :class:`timedelta` object as a " "constructor call with canonical attribute values." msgstr "" -#: ../../library/datetime.rst:404 ../../library/datetime.rst:681 -#: ../../library/datetime.rst:2735 +#: ../../library/datetime.rst:410 ../../library/datetime.rst:687 +#: ../../library/datetime.rst:2750 msgid "Notes:" msgstr "註解:" -#: ../../library/datetime.rst:407 +#: ../../library/datetime.rst:413 msgid "This is exact but may overflow." msgstr "這是精確的,但可能會溢位。" -#: ../../library/datetime.rst:410 +#: ../../library/datetime.rst:416 msgid "This is exact and cannot overflow." msgstr "這是精確的,且不會溢位。" -#: ../../library/datetime.rst:413 +#: ../../library/datetime.rst:419 msgid "Division by zero raises :exc:`ZeroDivisionError`." msgstr "" -#: ../../library/datetime.rst:416 +#: ../../library/datetime.rst:422 msgid "``-timedelta.max`` is not representable as a :class:`timedelta` object." msgstr "" -#: ../../library/datetime.rst:419 +#: ../../library/datetime.rst:425 msgid "" "String representations of :class:`timedelta` objects are normalized " "similarly to their internal representation. This leads to somewhat unusual " "results for negative timedeltas. For example::" msgstr "" -#: ../../library/datetime.rst:423 +#: ../../library/datetime.rst:429 msgid "" ">>> timedelta(hours=-5)\n" "datetime.timedelta(days=-1, seconds=68400)\n" @@ -707,85 +717,86 @@ msgstr "" ">>> print(_)\n" "-1 day, 19:00:00" -#: ../../library/datetime.rst:429 +#: ../../library/datetime.rst:435 msgid "" "The expression ``t2 - t3`` will always be equal to the expression ``t2 + (-" "t3)`` except when t3 is equal to ``timedelta.max``; in that case the former " "will produce a result while the latter will overflow." msgstr "" -#: ../../library/datetime.rst:433 +#: ../../library/datetime.rst:439 msgid "" "In addition to the operations listed above, :class:`timedelta` objects " "support certain additions and subtractions with :class:`date` and :class:`." "datetime` objects (see below)." msgstr "" -#: ../../library/datetime.rst:437 +#: ../../library/datetime.rst:443 msgid "" "Floor division and true division of a :class:`timedelta` object by another :" -"class:`timedelta` object are now supported, as are remainder operations and " -"the :func:`divmod` function. True division and multiplication of a :class:" -"`timedelta` object by a :class:`float` object are now supported." +"class:`!timedelta` object are now supported, as are remainder operations and " +"the :func:`divmod` function. True division and multiplication of a :class:`!" +"timedelta` object by a :class:`float` object are now supported." msgstr "" -#: ../../library/datetime.rst:443 +#: ../../library/datetime.rst:449 msgid ":class:`timedelta` objects support equality and order comparisons." msgstr "" -#: ../../library/datetime.rst:445 +#: ../../library/datetime.rst:451 msgid "" "In Boolean contexts, a :class:`timedelta` object is considered to be true if " "and only if it isn't equal to ``timedelta(0)``." msgstr "" -#: ../../library/datetime.rst:448 ../../library/datetime.rst:723 -#: ../../library/datetime.rst:1359 ../../library/datetime.rst:1984 +#: ../../library/datetime.rst:454 ../../library/datetime.rst:729 +#: ../../library/datetime.rst:1365 ../../library/datetime.rst:1990 msgid "Instance methods:" msgstr "實例方法:" -#: ../../library/datetime.rst:452 +#: ../../library/datetime.rst:458 msgid "" "Return the total number of seconds contained in the duration. Equivalent to " "``td / timedelta(seconds=1)``. For interval units other than seconds, use " "the division form directly (for example, ``td / timedelta(microseconds=1)``)." msgstr "" -#: ../../library/datetime.rst:456 +#: ../../library/datetime.rst:462 msgid "" "Note that for very large time intervals (greater than 270 years on most " "platforms) this method will lose microsecond accuracy." msgstr "" -#: ../../library/datetime.rst:463 +#: ../../library/datetime.rst:469 msgid "Examples of usage: :class:`!timedelta`" msgstr "用法範例::class:`!timedelta`" -#: ../../library/datetime.rst:465 +#: ../../library/datetime.rst:471 msgid "An additional example of normalization::" msgstr "" -#: ../../library/datetime.rst:467 +#: ../../library/datetime.rst:473 msgid "" ">>> # Components of another_year add up to exactly 365 days\n" -">>> from datetime import timedelta\n" -">>> year = timedelta(days=365)\n" -">>> another_year = timedelta(weeks=40, days=84, hours=23,\n" -"... minutes=50, seconds=600)\n" +">>> import datetime as dt\n" +">>> year = dt.timedelta(days=365)\n" +">>> another_year = dt.timedelta(weeks=40, days=84, hours=23,\n" +"... minutes=50, seconds=600)\n" ">>> year == another_year\n" "True\n" ">>> year.total_seconds()\n" "31536000.0" msgstr "" -#: ../../library/datetime.rst:477 +#: ../../library/datetime.rst:483 msgid "Examples of :class:`timedelta` arithmetic::" msgstr "" -#: ../../library/datetime.rst:479 +#: ../../library/datetime.rst:485 +#, fuzzy msgid "" -">>> from datetime import timedelta\n" -">>> year = timedelta(days=365)\n" +">>> import datetime as dt\n" +">>> year = dt.timedelta(days=365)\n" ">>> ten_years = 10 * year\n" ">>> ten_years\n" "datetime.timedelta(days=3650)\n" @@ -812,65 +823,65 @@ msgstr "" ">>> three_years, three_years.days // 365\n" "(datetime.timedelta(days=1095), 3)" -#: ../../library/datetime.rst:497 +#: ../../library/datetime.rst:503 msgid ":class:`!date` objects" msgstr ":class:`!date` 物件" -#: ../../library/datetime.rst:499 +#: ../../library/datetime.rst:505 msgid "" "A :class:`date` object represents a date (year, month and day) in an " "idealized calendar, the current Gregorian calendar indefinitely extended in " "both directions." msgstr "" -#: ../../library/datetime.rst:503 +#: ../../library/datetime.rst:509 msgid "" "January 1 of year 1 is called day number 1, January 2 of year 1 is called " "day number 2, and so on. [#]_" msgstr "" -#: ../../library/datetime.rst:508 +#: ../../library/datetime.rst:514 msgid "" "All arguments are required. Arguments must be integers, in the following " "ranges:" msgstr "" -#: ../../library/datetime.rst:511 +#: ../../library/datetime.rst:517 msgid "``MINYEAR <= year <= MAXYEAR``" msgstr "``MINYEAR <= year <= MAXYEAR``" -#: ../../library/datetime.rst:512 +#: ../../library/datetime.rst:518 msgid "``1 <= month <= 12``" msgstr "``1 <= month <= 12``" -#: ../../library/datetime.rst:513 +#: ../../library/datetime.rst:519 msgid "``1 <= day <= number of days in the given month and year``" msgstr "``1 <= day <= 該年該月的天數``" -#: ../../library/datetime.rst:515 ../../library/datetime.rst:944 +#: ../../library/datetime.rst:521 ../../library/datetime.rst:950 msgid "" "If an argument outside those ranges is given, :exc:`ValueError` is raised." msgstr "" -#: ../../library/datetime.rst:518 ../../library/datetime.rst:950 +#: ../../library/datetime.rst:524 ../../library/datetime.rst:956 msgid "Other constructors, all class methods:" msgstr "" -#: ../../library/datetime.rst:522 +#: ../../library/datetime.rst:528 msgid "Return the current local date." msgstr "回傳目前的本地日期。" -#: ../../library/datetime.rst:524 +#: ../../library/datetime.rst:530 msgid "This is equivalent to ``date.fromtimestamp(time.time())``." msgstr "這等同於 ``date.fromtimestamp(time.time())``。" -#: ../../library/datetime.rst:529 +#: ../../library/datetime.rst:535 msgid "" "Return the local date corresponding to the POSIX *timestamp*, such as is " "returned by :func:`time.time`." msgstr "" -#: ../../library/datetime.rst:532 +#: ../../library/datetime.rst:538 msgid "" "This may raise :exc:`OverflowError`, if the timestamp is out of the range of " "values supported by the platform C :c:func:`localtime` function, and :exc:" @@ -880,7 +891,7 @@ msgid "" "ignored by :meth:`fromtimestamp`." msgstr "" -#: ../../library/datetime.rst:539 +#: ../../library/datetime.rst:545 msgid "" "Raise :exc:`OverflowError` instead of :exc:`ValueError` if the timestamp is " "out of the range of values supported by the platform C :c:func:`localtime` " @@ -888,52 +899,53 @@ msgid "" "`localtime` failure." msgstr "" -#: ../../library/datetime.rst:548 +#: ../../library/datetime.rst:554 msgid "" "Return the date corresponding to the proleptic Gregorian *ordinal*, where " "January 1 of year 1 has ordinal 1." msgstr "" -#: ../../library/datetime.rst:551 +#: ../../library/datetime.rst:557 msgid "" ":exc:`ValueError` is raised unless ``1 <= ordinal <= date.max.toordinal()``. " "For any date ``d``, ``date.fromordinal(d.toordinal()) == d``." msgstr "" -#: ../../library/datetime.rst:558 +#: ../../library/datetime.rst:564 msgid "" "Return a :class:`date` corresponding to a *date_string* given in any valid " "ISO 8601 format, with the following exceptions:" msgstr "" -#: ../../library/datetime.rst:561 ../../library/datetime.rst:1115 +#: ../../library/datetime.rst:567 ../../library/datetime.rst:1121 msgid "" "Reduced precision dates are not currently supported (``YYYY-MM``, ``YYYY``)." msgstr "" -#: ../../library/datetime.rst:563 ../../library/datetime.rst:1117 +#: ../../library/datetime.rst:569 ../../library/datetime.rst:1123 msgid "" "Extended date representations are not currently supported (``±YYYYYY-MM-" "DD``)." msgstr "" -#: ../../library/datetime.rst:565 ../../library/datetime.rst:1119 +#: ../../library/datetime.rst:571 ../../library/datetime.rst:1125 msgid "Ordinal dates are not currently supported (``YYYY-OOO``)." msgstr "" -#: ../../library/datetime.rst:567 ../../library/datetime.rst:1121 -#: ../../library/datetime.rst:1593 +#: ../../library/datetime.rst:573 ../../library/datetime.rst:1127 +#: ../../library/datetime.rst:1599 msgid "Examples::" msgstr "範例: ::" -#: ../../library/datetime.rst:569 +#: ../../library/datetime.rst:575 +#, fuzzy msgid "" -">>> from datetime import date\n" -">>> date.fromisoformat('2019-12-04')\n" +">>> import datetime as dt\n" +">>> dt.date.fromisoformat('2019-12-04')\n" "datetime.date(2019, 12, 4)\n" -">>> date.fromisoformat('20191204')\n" +">>> dt.date.fromisoformat('20191204')\n" "datetime.date(2019, 12, 4)\n" -">>> date.fromisoformat('2021-W01-1')\n" +">>> dt.date.fromisoformat('2021-W01-1')\n" "datetime.date(2021, 1, 4)" msgstr "" ">>> from datetime import date\n" @@ -944,35 +956,35 @@ msgstr "" ">>> date.fromisoformat('2021-W01-1')\n" "datetime.date(2021, 1, 4)" -#: ../../library/datetime.rst:578 +#: ../../library/datetime.rst:584 msgid "Previously, this method only supported the format ``YYYY-MM-DD``." msgstr "" -#: ../../library/datetime.rst:584 +#: ../../library/datetime.rst:590 msgid "" "Return a :class:`date` corresponding to the ISO calendar date specified by " "*year*, *week* and *day*. This is the inverse of the function :meth:`date." "isocalendar`." msgstr "" -#: ../../library/datetime.rst:592 +#: ../../library/datetime.rst:598 msgid "" "Return a :class:`.date` corresponding to *date_string*, parsed according to " "*format*. This is equivalent to::" msgstr "" -#: ../../library/datetime.rst:595 +#: ../../library/datetime.rst:601 msgid "date(*(time.strptime(date_string, format)[0:3]))" msgstr "date(*(time.strptime(date_string, format)[0:3]))" -#: ../../library/datetime.rst:597 +#: ../../library/datetime.rst:603 msgid "" ":exc:`ValueError` is raised if the date_string and format can't be parsed " "by :func:`time.strptime` or if it returns a value which isn't a time tuple. " "See also :ref:`strftime-strptime-behavior` and :meth:`date.fromisoformat`." msgstr "" -#: ../../library/datetime.rst:604 +#: ../../library/datetime.rst:610 msgid "" "If *format* specifies a day of month without a year a :exc:" "`DeprecationWarning` is emitted. This is to avoid a quadrennial leap year " @@ -983,11 +995,12 @@ msgid "" "year, explicitly add a year that is a leap year before parsing:" msgstr "" -#: ../../library/datetime.rst:613 +#: ../../library/datetime.rst:619 +#, fuzzy msgid "" -">>> from datetime import date\n" +">>> import datetime as dt\n" ">>> date_string = \"02/29\"\n" -">>> when = date.strptime(f\"{date_string};1984\", \"%m/%d;%Y\") # Avoids " +">>> when = dt.date.strptime(f\"{date_string};1984\", \"%m/%d;%Y\") # Avoids " "leap year bug.\n" ">>> when.strftime(\"%B %d\")\n" "'February 29'" @@ -999,53 +1012,53 @@ msgstr "" ">>> when.strftime(\"%B %d\")\n" "'February 29'" -#: ../../library/datetime.rst:628 +#: ../../library/datetime.rst:634 msgid "The earliest representable date, ``date(MINYEAR, 1, 1)``." msgstr "" -#: ../../library/datetime.rst:633 +#: ../../library/datetime.rst:639 msgid "The latest representable date, ``date(MAXYEAR, 12, 31)``." msgstr "" -#: ../../library/datetime.rst:638 +#: ../../library/datetime.rst:644 msgid "" "The smallest possible difference between non-equal date objects, " "``timedelta(days=1)``." msgstr "" -#: ../../library/datetime.rst:646 ../../library/datetime.rst:1218 +#: ../../library/datetime.rst:652 ../../library/datetime.rst:1224 msgid "Between :const:`MINYEAR` and :const:`MAXYEAR` inclusive." msgstr "" -#: ../../library/datetime.rst:651 ../../library/datetime.rst:1223 +#: ../../library/datetime.rst:657 ../../library/datetime.rst:1229 msgid "Between 1 and 12 inclusive." msgstr "在 1 到 12 (含)之間。" -#: ../../library/datetime.rst:656 ../../library/datetime.rst:1228 +#: ../../library/datetime.rst:662 ../../library/datetime.rst:1234 msgid "Between 1 and the number of days in the given month of the given year." msgstr "" -#: ../../library/datetime.rst:664 +#: ../../library/datetime.rst:670 msgid "``date2 = date1 + timedelta``" msgstr "``date2 = date1 + timedelta``" -#: ../../library/datetime.rst:664 +#: ../../library/datetime.rst:670 msgid "``date2`` will be ``timedelta.days`` days after ``date1``. (1)" msgstr "" -#: ../../library/datetime.rst:667 +#: ../../library/datetime.rst:673 msgid "``date2 = date1 - timedelta``" msgstr "``date2 = date1 - timedelta``" -#: ../../library/datetime.rst:667 +#: ../../library/datetime.rst:673 msgid "Computes ``date2`` such that ``date2 + timedelta == date1``. (2)" msgstr "" -#: ../../library/datetime.rst:670 +#: ../../library/datetime.rst:676 msgid "``timedelta = date1 - date2``" msgstr "``timedelta = date1 - date2``" -#: ../../library/datetime.rst:670 ../../library/datetime.rst:1277 +#: ../../library/datetime.rst:676 ../../library/datetime.rst:1283 msgid "\\(3)" msgstr "\\(3)" @@ -1057,7 +1070,7 @@ msgstr "``date1 == date2``" msgid "``date1 != date2``" msgstr "``date1 != date2``" -#: ../../library/datetime.rst:672 ../../library/datetime.rst:1279 +#: ../../library/datetime.rst:678 ../../library/datetime.rst:1285 msgid "Equality comparison. (4)" msgstr "" @@ -1077,11 +1090,11 @@ msgstr "``date1 <= date2``" msgid "``date1 >= date2``" msgstr "``date1 >= date2``" -#: ../../library/datetime.rst:675 ../../library/datetime.rst:1282 +#: ../../library/datetime.rst:681 ../../library/datetime.rst:1288 msgid "Order comparison. (5)" msgstr "" -#: ../../library/datetime.rst:684 +#: ../../library/datetime.rst:690 msgid "" "*date2* is moved forward in time if ``timedelta.days > 0``, or backward if " "``timedelta.days < 0``. Afterward ``date2 - date1 == timedelta.days``. " @@ -1090,41 +1103,41 @@ msgid "" "`MINYEAR` or larger than :const:`MAXYEAR`." msgstr "" -#: ../../library/datetime.rst:691 +#: ../../library/datetime.rst:697 msgid "``timedelta.seconds`` and ``timedelta.microseconds`` are ignored." msgstr "``timedelta.seconds`` 和 ``timedelta.microseconds`` 被忽略。" -#: ../../library/datetime.rst:694 +#: ../../library/datetime.rst:700 msgid "" "This is exact, and cannot overflow. ``timedelta.seconds`` and ``timedelta." "microseconds`` are 0, and ``date2 + timedelta == date1`` after." msgstr "" -#: ../../library/datetime.rst:698 +#: ../../library/datetime.rst:704 msgid ":class:`date` objects are equal if they represent the same date." msgstr "" -#: ../../library/datetime.rst:700 +#: ../../library/datetime.rst:706 msgid "" ":class:`!date` objects that are not also :class:`.datetime` instances are " "never equal to :class:`!datetime` objects, even if they represent the same " "date." msgstr "" -#: ../../library/datetime.rst:705 +#: ../../library/datetime.rst:711 msgid "" "*date1* is considered less than *date2* when *date1* precedes *date2* in " "time. In other words, ``date1 < date2`` if and only if ``date1.toordinal() < " "date2.toordinal()``." msgstr "" -#: ../../library/datetime.rst:709 +#: ../../library/datetime.rst:715 msgid "" -"Order comparison between a :class:`!date` object that is not also a :class:`." +"Order comparison between a :class:`date` object that is not also a :class:`." "datetime` instance and a :class:`!datetime` object raises :exc:`TypeError`." msgstr "" -#: ../../library/datetime.rst:713 ../../library/datetime.rst:1350 +#: ../../library/datetime.rst:719 ../../library/datetime.rst:1356 msgid "" "Comparison between :class:`.datetime` object and an instance of the :class:" "`date` subclass that is not a :class:`!datetime` subclass no longer converts " @@ -1133,25 +1146,26 @@ msgid "" "in subclasses." msgstr "" -#: ../../library/datetime.rst:721 +#: ../../library/datetime.rst:727 msgid "" "In Boolean contexts, all :class:`date` objects are considered to be true." msgstr "" -#: ../../library/datetime.rst:727 +#: ../../library/datetime.rst:733 msgid "" "Return a new :class:`date` object with the same values, but with specified " "parameters updated." msgstr "" -#: ../../library/datetime.rst:730 ../../library/datetime.rst:2030 +#: ../../library/datetime.rst:736 ../../library/datetime.rst:2036 msgid "Example::" msgstr "範例: ::" -#: ../../library/datetime.rst:732 +#: ../../library/datetime.rst:738 +#, fuzzy msgid "" -">>> from datetime import date\n" -">>> d = date(2002, 12, 31)\n" +">>> import datetime as dt\n" +">>> d = dt.date(2002, 12, 31)\n" ">>> d.replace(day=26)\n" "datetime.date(2002, 12, 26)" msgstr "" @@ -1160,47 +1174,47 @@ msgstr "" ">>> d.replace(day=26)\n" "datetime.date(2002, 12, 26)" -#: ../../library/datetime.rst:737 +#: ../../library/datetime.rst:743 msgid "" "The generic function :func:`copy.replace` also supports :class:`date` " "objects." msgstr "" -#: ../../library/datetime.rst:743 ../../library/datetime.rst:1475 +#: ../../library/datetime.rst:749 ../../library/datetime.rst:1481 msgid "" "Return a :class:`time.struct_time` such as returned by :func:`time." "localtime`." msgstr "" "回傳一個 :class:`time.struct_time`,如同 :func:`time.localtime` 所回傳。" -#: ../../library/datetime.rst:745 +#: ../../library/datetime.rst:751 msgid "The hours, minutes and seconds are 0, and the DST flag is -1." msgstr "" -#: ../../library/datetime.rst:747 ../../library/datetime.rst:1477 +#: ../../library/datetime.rst:753 ../../library/datetime.rst:1483 msgid "``d.timetuple()`` is equivalent to::" msgstr "``d.timetuple()`` 等價於: ::" -#: ../../library/datetime.rst:749 +#: ../../library/datetime.rst:755 msgid "" "time.struct_time((d.year, d.month, d.day, 0, 0, 0, d.weekday(), yday, -1))" msgstr "" "time.struct_time((d.year, d.month, d.day, 0, 0, 0, d.weekday(), yday, -1))" -#: ../../library/datetime.rst:751 +#: ../../library/datetime.rst:757 msgid "" "where ``yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1`` is the " "day number within the current year starting with 1 for January 1st." msgstr "" -#: ../../library/datetime.rst:757 +#: ../../library/datetime.rst:763 msgid "" "Return the proleptic Gregorian ordinal of the date, where January 1 of year " "1 has ordinal 1. For any :class:`date` object ``d``, ``date.fromordinal(d." "toordinal()) == d``." msgstr "" -#: ../../library/datetime.rst:764 +#: ../../library/datetime.rst:770 msgid "" "Return the day of the week as an integer, where Monday is 0 and Sunday is 6. " "For example, ``date(2002, 12, 4).weekday() == 2``, a Wednesday. See also :" @@ -1209,25 +1223,25 @@ msgstr "" "回傳一個代表星期幾的整數,星期一為 0、星期日為 6。例如 ``date(2002, 12, 4)." "weekday() == 2`` 為星期三。也請參考 :meth:`isoweekday`。" -#: ../../library/datetime.rst:771 +#: ../../library/datetime.rst:777 msgid "" "Return the day of the week as an integer, where Monday is 1 and Sunday is 7. " "For example, ``date(2002, 12, 4).isoweekday() == 3``, a Wednesday. See also :" "meth:`weekday`, :meth:`isocalendar`." msgstr "" -#: ../../library/datetime.rst:778 +#: ../../library/datetime.rst:784 msgid "" "Return a :term:`named tuple` object with three components: ``year``, " "``week`` and ``weekday``." msgstr "" -#: ../../library/datetime.rst:781 +#: ../../library/datetime.rst:787 msgid "" "The ISO calendar is a widely used variant of the Gregorian calendar. [#]_" msgstr "" -#: ../../library/datetime.rst:783 +#: ../../library/datetime.rst:789 msgid "" "The ISO year consists of 52 or 53 full weeks, and where a week starts on a " "Monday and ends on a Sunday. The first week of an ISO year is the first " @@ -1236,18 +1250,19 @@ msgid "" "Gregorian year." msgstr "" -#: ../../library/datetime.rst:788 +#: ../../library/datetime.rst:794 msgid "" "For example, 2004 begins on a Thursday, so the first week of ISO year 2004 " "begins on Monday, 29 Dec 2003 and ends on Sunday, 4 Jan 2004::" msgstr "" -#: ../../library/datetime.rst:791 +#: ../../library/datetime.rst:797 +#, fuzzy msgid "" -">>> from datetime import date\n" -">>> date(2003, 12, 29).isocalendar()\n" +">>> import datetime as dt\n" +">>> dt.date(2003, 12, 29).isocalendar()\n" "datetime.IsoCalendarDate(year=2004, week=1, weekday=1)\n" -">>> date(2004, 1, 4).isocalendar()\n" +">>> dt.date(2004, 1, 4).isocalendar()\n" "datetime.IsoCalendarDate(year=2004, week=1, weekday=7)" msgstr "" ">>> from datetime import date\n" @@ -1256,59 +1271,61 @@ msgstr "" ">>> date(2004, 1, 4).isocalendar()\n" "datetime.IsoCalendarDate(year=2004, week=1, weekday=7)" -#: ../../library/datetime.rst:797 +#: ../../library/datetime.rst:803 msgid "Result changed from a tuple to a :term:`named tuple`." msgstr "" -#: ../../library/datetime.rst:803 +#: ../../library/datetime.rst:809 msgid "" "Return a string representing the date in ISO 8601 format, ``YYYY-MM-DD``::" msgstr "回傳一以 ISO 8601 格式 ``YYYY-MM-DD`` 表示的日期字串: ::" -#: ../../library/datetime.rst:805 +#: ../../library/datetime.rst:811 +#, fuzzy msgid "" -">>> from datetime import date\n" -">>> date(2002, 12, 4).isoformat()\n" +">>> import datetime as dt\n" +">>> dt.date(2002, 12, 4).isoformat()\n" "'2002-12-04'" msgstr "" ">>> from datetime import date\n" ">>> date(2002, 12, 4).isoformat()\n" "'2002-12-04'" -#: ../../library/datetime.rst:812 +#: ../../library/datetime.rst:818 msgid "For a date ``d``, ``str(d)`` is equivalent to ``d.isoformat()``." msgstr "" -#: ../../library/datetime.rst:817 +#: ../../library/datetime.rst:823 msgid "Return a string representing the date::" msgstr "" -#: ../../library/datetime.rst:819 +#: ../../library/datetime.rst:825 +#, fuzzy msgid "" -">>> from datetime import date\n" -">>> date(2002, 12, 4).ctime()\n" +">>> import datetime as dt\n" +">>> dt.date(2002, 12, 4).ctime()\n" "'Wed Dec 4 00:00:00 2002'" msgstr "" ">>> from datetime import date\n" ">>> date(2002, 12, 4).ctime()\n" "'Wed Dec 4 00:00:00 2002'" -#: ../../library/datetime.rst:823 ../../library/datetime.rst:1664 +#: ../../library/datetime.rst:829 ../../library/datetime.rst:1670 msgid "``d.ctime()`` is equivalent to::" msgstr "``d.ctime()`` 等價於: ::" -#: ../../library/datetime.rst:825 ../../library/datetime.rst:1666 +#: ../../library/datetime.rst:831 ../../library/datetime.rst:1672 msgid "time.ctime(time.mktime(d.timetuple()))" msgstr "time.ctime(time.mktime(d.timetuple()))" -#: ../../library/datetime.rst:827 +#: ../../library/datetime.rst:833 msgid "" "on platforms where the native C :c:func:`ctime` function (which :func:`time." "ctime` invokes, but which :meth:`date.ctime` does not invoke) conforms to " "the C standard." msgstr "" -#: ../../library/datetime.rst:834 +#: ../../library/datetime.rst:840 msgid "" "Return a string representing the date, controlled by an explicit format " "string. Format codes referring to hours, minutes or seconds will see 0 " @@ -1316,7 +1333,7 @@ msgid "" "isoformat`." msgstr "" -#: ../../library/datetime.rst:841 +#: ../../library/datetime.rst:847 msgid "" "Same as :meth:`.date.strftime`. This makes it possible to specify a format " "string for a :class:`.date` object in :ref:`formatted string literals >> import time\n" -">>> from datetime import date\n" -">>> today = date.today()\n" +">>> import datetime as dt\n" +">>> today = dt.date.today()\n" ">>> today\n" "datetime.date(2007, 12, 5)\n" -">>> today == date.fromtimestamp(time.time())\n" +">>> today == dt.date.fromtimestamp(time.time())\n" "True\n" -">>> my_birthday = date(today.year, 6, 24)\n" +">>> my_birthday = dt.date(today.year, 6, 24)\n" ">>> if my_birthday < today:\n" "... my_birthday = my_birthday.replace(year=today.year + 1)\n" "...\n" @@ -1368,14 +1386,14 @@ msgstr "" ">>> time_to_birthday.days\n" "202" -#: ../../library/datetime.rst:869 +#: ../../library/datetime.rst:875 msgid "More examples of working with :class:`date`:" msgstr "更多 :class:`date` 的用法範例:" -#: ../../library/datetime.rst:871 +#: ../../library/datetime.rst:877 msgid "" -">>> from datetime import date\n" -">>> d = date.fromordinal(730920) # 730920th day after 1. 1. 0001\n" +">>> import datetime as dt\n" +">>> d = dt.date.fromordinal(730920) # 730920th day after 1. 1. 0001\n" ">>> d\n" "datetime.date(2002, 3, 11)\n" "\n" @@ -1416,99 +1434,99 @@ msgid "" "datetime.date(2005, 3, 11)" msgstr "" -#: ../../library/datetime.rst:918 +#: ../../library/datetime.rst:924 msgid ":class:`!datetime` objects" msgstr ":class:`!datetime` 物件" -#: ../../library/datetime.rst:920 +#: ../../library/datetime.rst:926 msgid "" "A :class:`.datetime` object is a single object containing all the " "information from a :class:`date` object and a :class:`.time` object." msgstr "" -#: ../../library/datetime.rst:923 +#: ../../library/datetime.rst:929 msgid "" "Like a :class:`date` object, :class:`.datetime` assumes the current " "Gregorian calendar extended in both directions; like a :class:`.time` " -"object, :class:`.datetime` assumes there are exactly 3600\\*24 seconds in " +"object, :class:`!datetime` assumes there are exactly 3600\\*24 seconds in " "every day." msgstr "" -#: ../../library/datetime.rst:927 +#: ../../library/datetime.rst:933 msgid "Constructor:" msgstr "建構函式:" -#: ../../library/datetime.rst:931 +#: ../../library/datetime.rst:937 msgid "" "The *year*, *month* and *day* arguments are required. *tzinfo* may be " "``None``, or an instance of a :class:`tzinfo` subclass. The remaining " "arguments must be integers in the following ranges:" msgstr "" -#: ../../library/datetime.rst:935 +#: ../../library/datetime.rst:941 msgid "``MINYEAR <= year <= MAXYEAR``," msgstr "``MINYEAR <= year <= MAXYEAR``," -#: ../../library/datetime.rst:936 +#: ../../library/datetime.rst:942 msgid "``1 <= month <= 12``," msgstr "``1 <= month <= 12``," -#: ../../library/datetime.rst:937 +#: ../../library/datetime.rst:943 msgid "``1 <= day <= number of days in the given month and year``," msgstr "" -#: ../../library/datetime.rst:938 ../../library/datetime.rst:1829 +#: ../../library/datetime.rst:944 ../../library/datetime.rst:1835 msgid "``0 <= hour < 24``," msgstr "``0 <= hour < 24``," -#: ../../library/datetime.rst:939 ../../library/datetime.rst:1830 +#: ../../library/datetime.rst:945 ../../library/datetime.rst:1836 msgid "``0 <= minute < 60``," msgstr "``0 <= minute < 60``," -#: ../../library/datetime.rst:940 ../../library/datetime.rst:1831 +#: ../../library/datetime.rst:946 ../../library/datetime.rst:1837 msgid "``0 <= second < 60``," msgstr "``0 <= second < 60``," -#: ../../library/datetime.rst:941 ../../library/datetime.rst:1832 +#: ../../library/datetime.rst:947 ../../library/datetime.rst:1838 msgid "``0 <= microsecond < 1000000``," msgstr "``0 <= microsecond < 1000000``," -#: ../../library/datetime.rst:942 ../../library/datetime.rst:1833 +#: ../../library/datetime.rst:948 ../../library/datetime.rst:1839 msgid "``fold in [0, 1]``." msgstr "``fold in [0, 1]``。" -#: ../../library/datetime.rst:946 ../../library/datetime.rst:1396 -#: ../../library/datetime.rst:1997 +#: ../../library/datetime.rst:952 ../../library/datetime.rst:1402 +#: ../../library/datetime.rst:2003 msgid "Added the *fold* parameter." msgstr "新增 *fold* 參數。" -#: ../../library/datetime.rst:954 +#: ../../library/datetime.rst:960 msgid "Return the current local date and time, with :attr:`.tzinfo` ``None``." msgstr "回傳目前的本地日期與時間,且 :attr:`.tzinfo` 為 ``None``。" -#: ../../library/datetime.rst:956 +#: ../../library/datetime.rst:962 msgid "Equivalent to::" msgstr "等價於: ::" -#: ../../library/datetime.rst:958 +#: ../../library/datetime.rst:964 msgid "datetime.fromtimestamp(time.time())" msgstr "datetime.fromtimestamp(time.time())" -#: ../../library/datetime.rst:960 +#: ../../library/datetime.rst:966 msgid "See also :meth:`now`, :meth:`fromtimestamp`." msgstr "也請見 :meth:`now`、:meth:`fromtimestamp`。" -#: ../../library/datetime.rst:962 +#: ../../library/datetime.rst:968 msgid "" "This method is functionally equivalent to :meth:`now`, but without a ``tz`` " "parameter." msgstr "" -#: ../../library/datetime.rst:968 +#: ../../library/datetime.rst:974 msgid "Return the current local date and time." msgstr "" -#: ../../library/datetime.rst:970 +#: ../../library/datetime.rst:976 msgid "" "If optional argument *tz* is ``None`` or not specified, this is like :meth:" "`today`, but, if possible, supplies more precision than can be gotten from " @@ -1519,34 +1537,34 @@ msgstr "" "供比透過 :func:`time.time` 取得的時間戳記更多位數的資訊(例如,這在有提供 C :" "c:func:`gettimeofday` 函式的平台上可能可行)。" -#: ../../library/datetime.rst:976 +#: ../../library/datetime.rst:982 msgid "" "If *tz* is not ``None``, it must be an instance of a :class:`tzinfo` " "subclass, and the current date and time are converted to *tz*’s time zone." msgstr "" -#: ../../library/datetime.rst:979 +#: ../../library/datetime.rst:985 msgid "This function is preferred over :meth:`today` and :meth:`utcnow`." msgstr "" -#: ../../library/datetime.rst:983 +#: ../../library/datetime.rst:989 msgid "" "Subsequent calls to :meth:`!datetime.now` may return the same instant " "depending on the precision of the underlying clock." msgstr "" -#: ../../library/datetime.rst:989 +#: ../../library/datetime.rst:995 msgid "Return the current UTC date and time, with :attr:`.tzinfo` ``None``." msgstr "" -#: ../../library/datetime.rst:991 +#: ../../library/datetime.rst:997 msgid "" "This is like :meth:`now`, but returns the current UTC date and time, as a " "naive :class:`.datetime` object. An aware current UTC datetime can be " "obtained by calling ``datetime.now(timezone.utc)``. See also :meth:`now`." msgstr "" -#: ../../library/datetime.rst:997 +#: ../../library/datetime.rst:1003 msgid "" "Because naive ``datetime`` objects are treated by many ``datetime`` methods " "as local times, it is preferred to use aware datetimes to represent times in " @@ -1554,11 +1572,11 @@ msgid "" "current time in UTC is by calling ``datetime.now(timezone.utc)``." msgstr "" -#: ../../library/datetime.rst:1004 +#: ../../library/datetime.rst:1010 msgid "Use :meth:`datetime.now` with :const:`UTC` instead." msgstr "" -#: ../../library/datetime.rst:1009 +#: ../../library/datetime.rst:1015 msgid "" "Return the local date and time corresponding to the POSIX timestamp, such as " "is returned by :func:`time.time`. If optional argument *tz* is ``None`` or " @@ -1566,13 +1584,13 @@ msgid "" "time, and the returned :class:`.datetime` object is naive." msgstr "" -#: ../../library/datetime.rst:1014 +#: ../../library/datetime.rst:1020 msgid "" "If *tz* is not ``None``, it must be an instance of a :class:`tzinfo` " "subclass, and the timestamp is converted to *tz*’s time zone." msgstr "" -#: ../../library/datetime.rst:1017 +#: ../../library/datetime.rst:1023 msgid "" ":meth:`fromtimestamp` may raise :exc:`OverflowError`, if the timestamp is " "out of the range of values supported by the platform C :c:func:`localtime` " @@ -1585,7 +1603,7 @@ msgid "" "preferred over :meth:`utcfromtimestamp`." msgstr "" -#: ../../library/datetime.rst:1028 +#: ../../library/datetime.rst:1034 msgid "" "Raise :exc:`OverflowError` instead of :exc:`ValueError` if the timestamp is " "out of the range of values supported by the platform C :c:func:`localtime` " @@ -1593,17 +1611,17 @@ msgid "" "`ValueError` on :c:func:`localtime` or :c:func:`gmtime` failure." msgstr "" -#: ../../library/datetime.rst:1035 +#: ../../library/datetime.rst:1041 msgid ":meth:`fromtimestamp` may return instances with :attr:`.fold` set to 1." msgstr "" -#: ../../library/datetime.rst:1040 +#: ../../library/datetime.rst:1046 msgid "" "Return the UTC :class:`.datetime` corresponding to the POSIX timestamp, " "with :attr:`.tzinfo` ``None``. (The resulting object is naive.)" msgstr "" -#: ../../library/datetime.rst:1043 +#: ../../library/datetime.rst:1049 msgid "" "This may raise :exc:`OverflowError`, if the timestamp is out of the range of " "values supported by the platform C :c:func:`gmtime` function, and :exc:" @@ -1611,33 +1629,33 @@ msgid "" "to years in 1970 through 2038." msgstr "" -#: ../../library/datetime.rst:1048 +#: ../../library/datetime.rst:1054 msgid "To get an aware :class:`.datetime` object, call :meth:`fromtimestamp`::" msgstr "" -#: ../../library/datetime.rst:1050 +#: ../../library/datetime.rst:1056 msgid "datetime.fromtimestamp(timestamp, timezone.utc)" msgstr "datetime.fromtimestamp(timestamp, timezone.utc)" -#: ../../library/datetime.rst:1052 +#: ../../library/datetime.rst:1058 msgid "" "On the POSIX compliant platforms, it is equivalent to the following " "expression::" msgstr "" -#: ../../library/datetime.rst:1055 +#: ../../library/datetime.rst:1061 msgid "" "datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(seconds=timestamp)" msgstr "" "datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(seconds=timestamp)" -#: ../../library/datetime.rst:1057 +#: ../../library/datetime.rst:1063 msgid "" "except the latter formula always supports the full years range: between :" "const:`MINYEAR` and :const:`MAXYEAR` inclusive." msgstr "" -#: ../../library/datetime.rst:1062 +#: ../../library/datetime.rst:1068 msgid "" "Because naive ``datetime`` objects are treated by many ``datetime`` methods " "as local times, it is preferred to use aware datetimes to represent times in " @@ -1646,7 +1664,7 @@ msgid "" "tz=timezone.utc)``." msgstr "" -#: ../../library/datetime.rst:1068 +#: ../../library/datetime.rst:1074 msgid "" "Raise :exc:`OverflowError` instead of :exc:`ValueError` if the timestamp is " "out of the range of values supported by the platform C :c:func:`gmtime` " @@ -1654,15 +1672,15 @@ msgid "" "`gmtime` failure." msgstr "" -#: ../../library/datetime.rst:1074 +#: ../../library/datetime.rst:1080 msgid "Accepts any real number as *timestamp*, not only integer or float." msgstr "" -#: ../../library/datetime.rst:1079 +#: ../../library/datetime.rst:1085 msgid "Use :meth:`datetime.fromtimestamp` with :const:`UTC` instead." msgstr "" -#: ../../library/datetime.rst:1084 +#: ../../library/datetime.rst:1090 msgid "" "Return the :class:`.datetime` corresponding to the proleptic Gregorian " "ordinal, where January 1 of year 1 has ordinal 1. :exc:`ValueError` is " @@ -1671,66 +1689,67 @@ msgid "" "is ``None``." msgstr "" -#: ../../library/datetime.rst:1092 +#: ../../library/datetime.rst:1098 msgid "" "Return a new :class:`.datetime` object whose date components are equal to " "the given :class:`date` object's, and whose time components are equal to the " "given :class:`.time` object's. If the *tzinfo* argument is provided, its " "value is used to set the :attr:`.tzinfo` attribute of the result, otherwise " "the :attr:`~.time.tzinfo` attribute of the *time* argument is used. If the " -"*date* argument is a :class:`.datetime` object, its time components and :" +"*date* argument is a :class:`!datetime` object, its time components and :" "attr:`.tzinfo` attributes are ignored." msgstr "" -#: ../../library/datetime.rst:1100 +#: ../../library/datetime.rst:1106 msgid "" "For any :class:`.datetime` object ``d``, ``d == datetime.combine(d.date(), d." "time(), d.tzinfo)``." msgstr "" -#: ../../library/datetime.rst:1103 +#: ../../library/datetime.rst:1109 msgid "Added the *tzinfo* argument." msgstr "新增 *tzinfo* 引數。" -#: ../../library/datetime.rst:1109 +#: ../../library/datetime.rst:1115 msgid "" "Return a :class:`.datetime` corresponding to a *date_string* in any valid " "ISO 8601 format, with the following exceptions:" msgstr "" -#: ../../library/datetime.rst:1112 ../../library/datetime.rst:1931 +#: ../../library/datetime.rst:1118 ../../library/datetime.rst:1937 msgid "Time zone offsets may have fractional seconds." msgstr "" -#: ../../library/datetime.rst:1113 +#: ../../library/datetime.rst:1119 msgid "The ``T`` separator may be replaced by any single unicode character." msgstr "" -#: ../../library/datetime.rst:1114 ../../library/datetime.rst:1936 +#: ../../library/datetime.rst:1120 ../../library/datetime.rst:1942 msgid "Fractional hours and minutes are not supported." msgstr "" -#: ../../library/datetime.rst:1123 +#: ../../library/datetime.rst:1129 +#, fuzzy msgid "" -">>> from datetime import datetime\n" -">>> datetime.fromisoformat('2011-11-04')\n" +">>> import datetime as dt\n" +">>> dt.datetime.fromisoformat('2011-11-04')\n" "datetime.datetime(2011, 11, 4, 0, 0)\n" -">>> datetime.fromisoformat('20111104')\n" +">>> dt.datetime.fromisoformat('20111104')\n" "datetime.datetime(2011, 11, 4, 0, 0)\n" -">>> datetime.fromisoformat('2011-11-04T00:05:23')\n" +">>> dt.datetime.fromisoformat('2011-11-04T00:05:23')\n" "datetime.datetime(2011, 11, 4, 0, 5, 23)\n" -">>> datetime.fromisoformat('2011-11-04T00:05:23Z')\n" +">>> dt.datetime.fromisoformat('2011-11-04T00:05:23Z')\n" "datetime.datetime(2011, 11, 4, 0, 5, 23, tzinfo=datetime.timezone.utc)\n" -">>> datetime.fromisoformat('20111104T000523')\n" +">>> dt.datetime.fromisoformat('20111104T000523')\n" "datetime.datetime(2011, 11, 4, 0, 5, 23)\n" -">>> datetime.fromisoformat('2011-W01-2T00:05:23.283')\n" +">>> dt.datetime.fromisoformat('2011-W01-2T00:05:23.283')\n" "datetime.datetime(2011, 1, 4, 0, 5, 23, 283000)\n" -">>> datetime.fromisoformat('2011-11-04 00:05:23.283')\n" +">>> dt.datetime.fromisoformat('2011-11-04 00:05:23.283')\n" "datetime.datetime(2011, 11, 4, 0, 5, 23, 283000)\n" -">>> datetime.fromisoformat('2011-11-04 00:05:23.283+00:00')\n" +">>> dt.datetime.fromisoformat('2011-11-04 00:05:23.283+00:00')\n" "datetime.datetime(2011, 11, 4, 0, 5, 23, 283000, tzinfo=datetime.timezone." "utc)\n" -">>> datetime.fromisoformat('2011-11-04T00:05:23+04:00')\n" +">>> dt.datetime.fromisoformat('2011-11-04T00:05:23+04:00')\n" "datetime.datetime(2011, 11, 4, 0, 5, 23,\n" " tzinfo=datetime.timezone(datetime.timedelta(seconds=14400)))" msgstr "" @@ -1756,13 +1775,13 @@ msgstr "" "datetime.datetime(2011, 11, 4, 0, 5, 23,\n" " tzinfo=datetime.timezone(datetime.timedelta(seconds=14400)))" -#: ../../library/datetime.rst:1145 +#: ../../library/datetime.rst:1151 msgid "" "Previously, this method only supported formats that could be emitted by :" "meth:`date.isoformat` or :meth:`datetime.isoformat`." msgstr "" -#: ../../library/datetime.rst:1152 +#: ../../library/datetime.rst:1158 msgid "" "Return a :class:`.datetime` corresponding to the ISO calendar date specified " "by *year*, *week* and *day*. The non-date components of the datetime are " @@ -1770,23 +1789,23 @@ msgid "" "function :meth:`datetime.isocalendar`." msgstr "" -#: ../../library/datetime.rst:1162 +#: ../../library/datetime.rst:1168 msgid "" "Return a :class:`.datetime` corresponding to *date_string*, parsed according " "to *format*." msgstr "" -#: ../../library/datetime.rst:1165 +#: ../../library/datetime.rst:1171 msgid "" "If *format* does not contain microseconds or time zone information, this is " "equivalent to::" msgstr "" -#: ../../library/datetime.rst:1167 ../../library/datetime.rst:2715 +#: ../../library/datetime.rst:1173 ../../library/datetime.rst:2730 msgid "datetime(*(time.strptime(date_string, format)[0:6]))" msgstr "datetime(*(time.strptime(date_string, format)[0:6]))" -#: ../../library/datetime.rst:1169 +#: ../../library/datetime.rst:1175 msgid "" ":exc:`ValueError` is raised if the date_string and format can't be parsed " "by :func:`time.strptime` or if it returns a value which isn't a time tuple. " @@ -1794,7 +1813,7 @@ msgid "" "fromisoformat`." msgstr "" -#: ../../library/datetime.rst:1176 +#: ../../library/datetime.rst:1182 msgid "" "If *format* specifies a day of month without a year a :exc:" "`DeprecationWarning` is now emitted. This is to avoid a quadrennial leap " @@ -1805,11 +1824,12 @@ msgid "" "not have a year, explicitly add a year that is a leap year before parsing:" msgstr "" -#: ../../library/datetime.rst:1185 +#: ../../library/datetime.rst:1191 +#, fuzzy msgid "" -">>> from datetime import datetime\n" +">>> import datetime as dt\n" ">>> date_string = \"02/29\"\n" -">>> when = datetime.strptime(f\"{date_string};1984\", \"%m/%d;%Y\") # " +">>> when = dt.datetime.strptime(f\"{date_string};1984\", \"%m/%d;%Y\") # " "Avoids leap year bug.\n" ">>> when.strftime(\"%B %d\")\n" "'February 29'" @@ -1821,44 +1841,44 @@ msgstr "" ">>> when.strftime(\"%B %d\")\n" "'February 29'" -#: ../../library/datetime.rst:1198 +#: ../../library/datetime.rst:1204 msgid "" "The earliest representable :class:`.datetime`, ``datetime(MINYEAR, 1, 1, " "tzinfo=None)``." msgstr "" -#: ../../library/datetime.rst:1204 +#: ../../library/datetime.rst:1210 msgid "" "The latest representable :class:`.datetime`, ``datetime(MAXYEAR, 12, 31, 23, " "59, 59, 999999, tzinfo=None)``." msgstr "" -#: ../../library/datetime.rst:1210 +#: ../../library/datetime.rst:1216 msgid "" "The smallest possible difference between non-equal :class:`.datetime` " "objects, ``timedelta(microseconds=1)``." msgstr "" -#: ../../library/datetime.rst:1233 ../../library/datetime.rst:1863 +#: ../../library/datetime.rst:1239 ../../library/datetime.rst:1869 msgid "In ``range(24)``." msgstr "" -#: ../../library/datetime.rst:1238 ../../library/datetime.rst:1243 -#: ../../library/datetime.rst:1868 ../../library/datetime.rst:1873 +#: ../../library/datetime.rst:1244 ../../library/datetime.rst:1249 +#: ../../library/datetime.rst:1874 ../../library/datetime.rst:1879 msgid "In ``range(60)``." msgstr "" -#: ../../library/datetime.rst:1248 ../../library/datetime.rst:1878 +#: ../../library/datetime.rst:1254 ../../library/datetime.rst:1884 msgid "In ``range(1000000)``." msgstr "" -#: ../../library/datetime.rst:1253 +#: ../../library/datetime.rst:1259 msgid "" "The object passed as the *tzinfo* argument to the :class:`.datetime` " "constructor, or ``None`` if none was passed." msgstr "" -#: ../../library/datetime.rst:1259 ../../library/datetime.rst:1889 +#: ../../library/datetime.rst:1265 ../../library/datetime.rst:1895 msgid "" "In ``[0, 1]``. Used to disambiguate wall times during a repeated interval. " "(A repeated interval occurs when clocks are rolled back at the end of " @@ -1868,26 +1888,26 @@ msgid "" "time representation." msgstr "" -#: ../../library/datetime.rst:1273 +#: ../../library/datetime.rst:1279 msgid "``datetime2 = datetime1 + timedelta``" msgstr "``datetime2 = datetime1 + timedelta``" -#: ../../library/datetime.rst:1273 ../../library/datetime.rst:2523 -#: ../../library/datetime.rst:2528 ../../library/datetime.rst:2540 -#: ../../library/datetime.rst:2545 ../../library/datetime.rst:2605 -#: ../../library/datetime.rst:2610 ../../library/datetime.rst:2614 +#: ../../library/datetime.rst:1279 ../../library/datetime.rst:2538 +#: ../../library/datetime.rst:2543 ../../library/datetime.rst:2555 +#: ../../library/datetime.rst:2560 ../../library/datetime.rst:2620 +#: ../../library/datetime.rst:2625 ../../library/datetime.rst:2629 msgid "\\(1)" msgstr "\\(1)" -#: ../../library/datetime.rst:1275 +#: ../../library/datetime.rst:1281 msgid "``datetime2 = datetime1 - timedelta``" msgstr "``datetime2 = datetime1 - timedelta``" -#: ../../library/datetime.rst:1275 ../../library/datetime.rst:2556 +#: ../../library/datetime.rst:1281 ../../library/datetime.rst:2571 msgid "\\(2)" msgstr "\\(2)" -#: ../../library/datetime.rst:1277 +#: ../../library/datetime.rst:1283 msgid "``timedelta = datetime1 - datetime2``" msgstr "``timedelta = datetime1 - datetime2``" @@ -1915,7 +1935,7 @@ msgstr "``datetime1 <= datetime2``" msgid "``datetime1 >= datetime2``" msgstr "``datetime1 >= datetime2``" -#: ../../library/datetime.rst:1289 +#: ../../library/datetime.rst:1295 msgid "" "``datetime2`` is a duration of ``timedelta`` removed from ``datetime1``, " "moving forward in time if ``timedelta.days > 0``, or backward if ``timedelta." @@ -1926,7 +1946,7 @@ msgid "" "adjustments are done even if the input is an aware object." msgstr "" -#: ../../library/datetime.rst:1298 +#: ../../library/datetime.rst:1304 msgid "" "Computes the ``datetime2`` such that ``datetime2 + timedelta == datetime1``. " "As for addition, the result has the same :attr:`~.datetime.tzinfo` attribute " @@ -1934,14 +1954,14 @@ msgid "" "input is aware." msgstr "" -#: ../../library/datetime.rst:1303 +#: ../../library/datetime.rst:1309 msgid "" -"Subtraction of a :class:`.datetime` from a :class:`.datetime` is defined " +"Subtraction of a :class:`.datetime` from a :class:`!datetime` is defined " "only if both operands are naive, or if both are aware. If one is aware and " "the other is naive, :exc:`TypeError` is raised." msgstr "" -#: ../../library/datetime.rst:1307 +#: ../../library/datetime.rst:1313 msgid "" "If both are naive, or both are aware and have the same :attr:`~.datetime." "tzinfo` attribute, the :attr:`~.datetime.tzinfo` attributes are ignored, and " @@ -1949,7 +1969,7 @@ msgid "" "datetime1``. No time zone adjustments are done in this case." msgstr "" -#: ../../library/datetime.rst:1312 +#: ../../library/datetime.rst:1318 msgid "" "If both are aware and have different :attr:`~.datetime.tzinfo` attributes, " "``a-b`` acts as if ``a`` and ``b`` were first converted to naive UTC " @@ -1958,40 +1978,40 @@ msgid "" "overflows." msgstr "" -#: ../../library/datetime.rst:1318 +#: ../../library/datetime.rst:1324 msgid "" ":class:`.datetime` objects are equal if they represent the same date and " "time, taking into account the time zone." msgstr "" -#: ../../library/datetime.rst:1321 -msgid "Naive and aware :class:`!datetime` objects are never equal." +#: ../../library/datetime.rst:1327 +msgid "Naive and aware :class:`.datetime` objects are never equal." msgstr "" -#: ../../library/datetime.rst:1323 +#: ../../library/datetime.rst:1329 msgid "" "If both comparands are aware, and have the same :attr:`!tzinfo` attribute, " "the :attr:`!tzinfo` and :attr:`~.datetime.fold` attributes are ignored and " "the base datetimes are compared. If both comparands are aware and have " "different :attr:`~.datetime.tzinfo` attributes, the comparison acts as " "comparands were first converted to UTC datetimes except that the " -"implementation never overflows. :class:`!datetime` instances in a repeated " +"implementation never overflows. :class:`.datetime` instances in a repeated " "interval are never equal to :class:`!datetime` instances in other time zone." msgstr "" -#: ../../library/datetime.rst:1333 +#: ../../library/datetime.rst:1339 msgid "" "*datetime1* is considered less than *datetime2* when *datetime1* precedes " "*datetime2* in time, taking into account the time zone." msgstr "" -#: ../../library/datetime.rst:1336 +#: ../../library/datetime.rst:1342 msgid "" "Order comparison between naive and aware :class:`.datetime` objects raises :" "exc:`TypeError`." msgstr "" -#: ../../library/datetime.rst:1339 +#: ../../library/datetime.rst:1345 msgid "" "If both comparands are aware, and have the same :attr:`!tzinfo` attribute, " "the :attr:`!tzinfo` and :attr:`~.datetime.fold` attributes are ignored and " @@ -2001,33 +2021,33 @@ msgid "" "implementation never overflows." msgstr "" -#: ../../library/datetime.rst:1346 +#: ../../library/datetime.rst:1352 msgid "" "Equality comparisons between aware and naive :class:`.datetime` instances " "don't raise :exc:`TypeError`." msgstr "" -#: ../../library/datetime.rst:1363 +#: ../../library/datetime.rst:1369 msgid "Return :class:`date` object with same year, month and day." msgstr "" -#: ../../library/datetime.rst:1368 +#: ../../library/datetime.rst:1374 msgid "" "Return :class:`.time` object with same hour, minute, second, microsecond and " "fold. :attr:`.tzinfo` is ``None``. See also method :meth:`timetz`." msgstr "" -#: ../../library/datetime.rst:1371 ../../library/datetime.rst:1380 +#: ../../library/datetime.rst:1377 ../../library/datetime.rst:1386 msgid "The fold value is copied to the returned :class:`.time` object." msgstr "" -#: ../../library/datetime.rst:1377 +#: ../../library/datetime.rst:1383 msgid "" "Return :class:`.time` object with same hour, minute, second, microsecond, " "fold, and tzinfo attributes. See also method :meth:`time`." msgstr "" -#: ../../library/datetime.rst:1388 +#: ../../library/datetime.rst:1394 msgid "" "Return a new :class:`datetime` object with the same attributes, but with " "specified parameters updated. Note that ``tzinfo=None`` can be specified to " @@ -2035,27 +2055,27 @@ msgid "" "and time data." msgstr "" -#: ../../library/datetime.rst:1393 +#: ../../library/datetime.rst:1399 msgid "" ":class:`.datetime` objects are also supported by generic function :func:" "`copy.replace`." msgstr "" -#: ../../library/datetime.rst:1402 +#: ../../library/datetime.rst:1408 msgid "" "Return a :class:`.datetime` object with new :attr:`.tzinfo` attribute *tz*, " "adjusting the date and time data so the result is the same UTC time as " "*self*, but in *tz*'s local time." msgstr "" -#: ../../library/datetime.rst:1406 +#: ../../library/datetime.rst:1412 msgid "" "If provided, *tz* must be an instance of a :class:`tzinfo` subclass, and " "its :meth:`utcoffset` and :meth:`dst` methods must not return ``None``. If " "*self* is naive, it is presumed to represent time in the system time zone." msgstr "" -#: ../../library/datetime.rst:1410 +#: ../../library/datetime.rst:1416 msgid "" "If called without arguments (or with ``tz=None``) the system local time zone " "is assumed for the target time zone. The ``.tzinfo`` attribute of the " @@ -2063,7 +2083,7 @@ msgid "" "with the zone name and offset obtained from the OS." msgstr "" -#: ../../library/datetime.rst:1415 +#: ../../library/datetime.rst:1421 msgid "" "If ``self.tzinfo`` is *tz*, ``self.astimezone(tz)`` is equal to *self*: no " "adjustment of date or time data is performed. Else the result is local time " @@ -2072,7 +2092,7 @@ msgid "" "date and time data as ``dt - dt.utcoffset()``." msgstr "" -#: ../../library/datetime.rst:1421 +#: ../../library/datetime.rst:1427 msgid "" "If you merely want to attach a :class:`timezone` object *tz* to a datetime " "*dt* without adjustment of date and time data, use ``dt." @@ -2081,14 +2101,14 @@ msgid "" "use ``dt.replace(tzinfo=None)``." msgstr "" -#: ../../library/datetime.rst:1426 +#: ../../library/datetime.rst:1432 msgid "" "Note that the default :meth:`tzinfo.fromutc` method can be overridden in a :" "class:`tzinfo` subclass to affect the result returned by :meth:`astimezone`. " "Ignoring error cases, :meth:`astimezone` acts like::" msgstr "" -#: ../../library/datetime.rst:1430 +#: ../../library/datetime.rst:1436 msgid "" "def astimezone(self, tz):\n" " if self.tzinfo is tz:\n" @@ -2099,49 +2119,49 @@ msgid "" " return tz.fromutc(utc)" msgstr "" -#: ../../library/datetime.rst:1438 +#: ../../library/datetime.rst:1444 msgid "*tz* now can be omitted." msgstr "" -#: ../../library/datetime.rst:1441 +#: ../../library/datetime.rst:1447 msgid "" "The :meth:`astimezone` method can now be called on naive instances that are " "presumed to represent system local time." msgstr "" -#: ../../library/datetime.rst:1448 +#: ../../library/datetime.rst:1454 msgid "" "If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo." "utcoffset(self)``, and raises an exception if the latter doesn't return " "``None`` or a :class:`timedelta` object with magnitude less than one day." msgstr "" -#: ../../library/datetime.rst:1452 ../../library/datetime.rst:2070 -#: ../../library/datetime.rst:2179 ../../library/datetime.rst:2424 -#: ../../library/datetime.rst:2436 ../../library/datetime.rst:2788 +#: ../../library/datetime.rst:1458 ../../library/datetime.rst:2076 +#: ../../library/datetime.rst:2185 ../../library/datetime.rst:2438 +#: ../../library/datetime.rst:2450 ../../library/datetime.rst:2803 msgid "The UTC offset is not restricted to a whole number of minutes." msgstr "" -#: ../../library/datetime.rst:1458 +#: ../../library/datetime.rst:1464 msgid "" "If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo." "dst(self)``, and raises an exception if the latter doesn't return ``None`` " "or a :class:`timedelta` object with magnitude less than one day." msgstr "" -#: ../../library/datetime.rst:1462 ../../library/datetime.rst:2080 -#: ../../library/datetime.rst:2233 +#: ../../library/datetime.rst:1468 ../../library/datetime.rst:2086 +#: ../../library/datetime.rst:2243 msgid "The DST offset is not restricted to a whole number of minutes." msgstr "" -#: ../../library/datetime.rst:1468 +#: ../../library/datetime.rst:1474 msgid "" "If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo." "tzname(self)``, raises an exception if the latter doesn't return ``None`` or " "a string object," msgstr "" -#: ../../library/datetime.rst:1479 +#: ../../library/datetime.rst:1485 msgid "" "time.struct_time((d.year, d.month, d.day,\n" " d.hour, d.minute, d.second,\n" @@ -2151,7 +2171,7 @@ msgstr "" " d.hour, d.minute, d.second,\n" " d.weekday(), yday, dst))" -#: ../../library/datetime.rst:1483 +#: ../../library/datetime.rst:1489 msgid "" "where ``yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1`` is the " "day number within the current year starting with 1 for January 1st. The :" @@ -2162,7 +2182,7 @@ msgid "" "to 0." msgstr "" -#: ../../library/datetime.rst:1494 +#: ../../library/datetime.rst:1500 msgid "" "If :class:`.datetime` instance ``d`` is naive, this is the same as ``d." "timetuple()`` except that :attr:`~.time.struct_time.tm_isdst` is forced to 0 " @@ -2170,7 +2190,7 @@ msgid "" "time." msgstr "" -#: ../../library/datetime.rst:1498 +#: ../../library/datetime.rst:1504 msgid "" "If ``d`` is aware, ``d`` is normalized to UTC time, by subtracting ``d." "utcoffset()``, and a :class:`time.struct_time` for the normalized time is " @@ -2179,7 +2199,7 @@ msgid "" "and UTC adjustment spills over a year boundary." msgstr "" -#: ../../library/datetime.rst:1507 +#: ../../library/datetime.rst:1513 msgid "" "Because naive ``datetime`` objects are treated by many ``datetime`` methods " "as local times, it is preferred to use aware datetimes to represent times in " @@ -2189,39 +2209,39 @@ msgid "" "meth:`.datetime.timetuple`." msgstr "" -#: ../../library/datetime.rst:1517 +#: ../../library/datetime.rst:1523 msgid "" "Return the proleptic Gregorian ordinal of the date. The same as ``self." "date().toordinal()``." msgstr "" -#: ../../library/datetime.rst:1523 +#: ../../library/datetime.rst:1529 msgid "" "Return POSIX timestamp corresponding to the :class:`.datetime` instance. The " "return value is a :class:`float` similar to that returned by :func:`time." "time`." msgstr "" -#: ../../library/datetime.rst:1527 +#: ../../library/datetime.rst:1533 msgid "" "Naive :class:`.datetime` instances are assumed to represent local time and " "this method relies on the platform C :c:func:`mktime` function to perform " -"the conversion. Since :class:`.datetime` supports wider range of values " +"the conversion. Since :class:`!datetime` supports wider range of values " "than :c:func:`mktime` on many platforms, this method may raise :exc:" "`OverflowError` or :exc:`OSError` for times far in the past or far in the " "future." msgstr "" -#: ../../library/datetime.rst:1534 +#: ../../library/datetime.rst:1540 msgid "" "For aware :class:`.datetime` instances, the return value is computed as::" msgstr "" -#: ../../library/datetime.rst:1537 +#: ../../library/datetime.rst:1543 msgid "(dt - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds()" msgstr "(dt - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds()" -#: ../../library/datetime.rst:1541 +#: ../../library/datetime.rst:1547 msgid "" "There is no method to obtain the POSIX timestamp directly from a naive :" "class:`.datetime` instance representing UTC time. If your application uses " @@ -2229,63 +2249,63 @@ msgid "" "the POSIX timestamp by supplying ``tzinfo=timezone.utc``::" msgstr "" -#: ../../library/datetime.rst:1547 +#: ../../library/datetime.rst:1553 msgid "timestamp = dt.replace(tzinfo=timezone.utc).timestamp()" msgstr "timestamp = dt.replace(tzinfo=timezone.utc).timestamp()" -#: ../../library/datetime.rst:1549 +#: ../../library/datetime.rst:1555 msgid "or by calculating the timestamp directly::" msgstr "" -#: ../../library/datetime.rst:1551 +#: ../../library/datetime.rst:1557 msgid "timestamp = (dt - datetime(1970, 1, 1)) / timedelta(seconds=1)" msgstr "timestamp = (dt - datetime(1970, 1, 1)) / timedelta(seconds=1)" -#: ../../library/datetime.rst:1555 +#: ../../library/datetime.rst:1561 msgid "" "The :meth:`timestamp` method uses the :attr:`.fold` attribute to " "disambiguate the times during a repeated interval." msgstr "" -#: ../../library/datetime.rst:1562 +#: ../../library/datetime.rst:1568 msgid "" "Return the day of the week as an integer, where Monday is 0 and Sunday is 6. " "The same as ``self.date().weekday()``. See also :meth:`isoweekday`." msgstr "" -#: ../../library/datetime.rst:1568 +#: ../../library/datetime.rst:1574 msgid "" "Return the day of the week as an integer, where Monday is 1 and Sunday is 7. " "The same as ``self.date().isoweekday()``. See also :meth:`weekday`, :meth:" "`isocalendar`." msgstr "" -#: ../../library/datetime.rst:1575 +#: ../../library/datetime.rst:1581 msgid "" "Return a :term:`named tuple` with three components: ``year``, ``week`` and " "``weekday``. The same as ``self.date().isocalendar()``." msgstr "" -#: ../../library/datetime.rst:1581 +#: ../../library/datetime.rst:1587 msgid "Return a string representing the date and time in ISO 8601 format:" msgstr "" -#: ../../library/datetime.rst:1583 +#: ../../library/datetime.rst:1589 msgid "``YYYY-MM-DDTHH:MM:SS.ffffff``, if :attr:`microsecond` is not 0" msgstr "``YYYY-MM-DDTHH:MM:SS.ffffff``,如果 :attr:`microsecond` 不是 0" -#: ../../library/datetime.rst:1584 +#: ../../library/datetime.rst:1590 msgid "``YYYY-MM-DDTHH:MM:SS``, if :attr:`microsecond` is 0" msgstr "``YYYY-MM-DDTHH:MM:SS``,如果 :attr:`microsecond` 是 0" -#: ../../library/datetime.rst:1586 +#: ../../library/datetime.rst:1592 msgid "" "If :meth:`utcoffset` does not return ``None``, a string is appended, giving " "the UTC offset:" msgstr "" "如果 :meth:`utcoffset` 没有回傳 ``None``,則會附加一个字串,給出 UTC 偏移:" -#: ../../library/datetime.rst:1589 +#: ../../library/datetime.rst:1595 msgid "" "``YYYY-MM-DDTHH:MM:SS.ffffff+HH:MM[:SS[.ffffff]]``, if :attr:`microsecond` " "is not 0" @@ -2293,18 +2313,19 @@ msgstr "" "``YYYY-MM-DDTHH:MM:SS.ffffff+HH:MM[:SS[.ffffff]]``,如果 :attr:`microsecond` " "不是 0" -#: ../../library/datetime.rst:1591 +#: ../../library/datetime.rst:1597 msgid "" "``YYYY-MM-DDTHH:MM:SS+HH:MM[:SS[.ffffff]]``, if :attr:`microsecond` is 0" msgstr "" "``YYYY-MM-DDTHH:MM:SS+HH:MM[:SS[.ffffff]]``,如果 :attr:`microsecond` 是 0" -#: ../../library/datetime.rst:1595 +#: ../../library/datetime.rst:1601 +#, fuzzy msgid "" -">>> from datetime import datetime, timezone\n" -">>> datetime(2019, 5, 18, 15, 17, 8, 132263).isoformat()\n" +">>> import datetime as dt\n" +">>> dt.datetime(2019, 5, 18, 15, 17, 8, 132263).isoformat()\n" "'2019-05-18T15:17:08.132263'\n" -">>> datetime(2019, 5, 18, 15, 17, tzinfo=timezone.utc).isoformat()\n" +">>> dt.datetime(2019, 5, 18, 15, 17, tzinfo=dt.timezone.utc).isoformat()\n" "'2019-05-18T15:17:00+00:00'" msgstr "" ">>> from datetime import datetime, timezone\n" @@ -2313,23 +2334,24 @@ msgstr "" ">>> datetime(2019, 5, 18, 15, 17, tzinfo=timezone.utc).isoformat()\n" "'2019-05-18T15:17:00+00:00'" -#: ../../library/datetime.rst:1601 +#: ../../library/datetime.rst:1607 msgid "" "The optional argument *sep* (default ``'T'``) is a one-character separator, " "placed between the date and time portions of the result. For example::" msgstr "" -#: ../../library/datetime.rst:1604 +#: ../../library/datetime.rst:1610 +#, fuzzy msgid "" -">>> from datetime import tzinfo, timedelta, datetime\n" -">>> class TZ(tzinfo):\n" +">>> import datetime as dt\n" +">>> class TZ(dt.tzinfo):\n" "... \"\"\"A time zone with an arbitrary, constant -06:39 offset.\"\"\"\n" -"... def utcoffset(self, dt):\n" -"... return timedelta(hours=-6, minutes=-39)\n" +"... def utcoffset(self, when):\n" +"... return dt.timedelta(hours=-6, minutes=-39)\n" "...\n" -">>> datetime(2002, 12, 25, tzinfo=TZ()).isoformat(' ')\n" +">>> dt.datetime(2002, 12, 25, tzinfo=TZ()).isoformat(' ')\n" "'2002-12-25 00:00:00-06:39'\n" -">>> datetime(2009, 11, 27, microsecond=100, tzinfo=TZ()).isoformat()\n" +">>> dt.datetime(2009, 11, 27, microsecond=100, tzinfo=TZ()).isoformat()\n" "'2009-11-27T00:00:00.000100-06:39'" msgstr "" ">>> from datetime import tzinfo, timedelta, datetime\n" @@ -2343,59 +2365,60 @@ msgstr "" ">>> datetime(2009, 11, 27, microsecond=100, tzinfo=TZ()).isoformat()\n" "'2009-11-27T00:00:00.000100-06:39'" -#: ../../library/datetime.rst:1615 ../../library/datetime.rst:2010 +#: ../../library/datetime.rst:1621 ../../library/datetime.rst:2016 msgid "" "The optional argument *timespec* specifies the number of additional " "components of the time to include (the default is ``'auto'``). It can be one " "of the following:" msgstr "" -#: ../../library/datetime.rst:1619 ../../library/datetime.rst:2014 +#: ../../library/datetime.rst:1625 ../../library/datetime.rst:2020 msgid "" "``'auto'``: Same as ``'seconds'`` if :attr:`microsecond` is 0, same as " "``'microseconds'`` otherwise." msgstr "" -#: ../../library/datetime.rst:1621 ../../library/datetime.rst:2016 +#: ../../library/datetime.rst:1627 ../../library/datetime.rst:2022 msgid "``'hours'``: Include the :attr:`hour` in the two-digit ``HH`` format." msgstr "" -#: ../../library/datetime.rst:1622 ../../library/datetime.rst:2017 +#: ../../library/datetime.rst:1628 ../../library/datetime.rst:2023 msgid "" "``'minutes'``: Include :attr:`hour` and :attr:`minute` in ``HH:MM`` format." msgstr "" -#: ../../library/datetime.rst:1623 ../../library/datetime.rst:2018 +#: ../../library/datetime.rst:1629 ../../library/datetime.rst:2024 msgid "" "``'seconds'``: Include :attr:`hour`, :attr:`minute`, and :attr:`second` in " "``HH:MM:SS`` format." msgstr "" -#: ../../library/datetime.rst:1625 ../../library/datetime.rst:2020 +#: ../../library/datetime.rst:1631 ../../library/datetime.rst:2026 msgid "" "``'milliseconds'``: Include full time, but truncate fractional second part " "to milliseconds. ``HH:MM:SS.sss`` format." msgstr "" -#: ../../library/datetime.rst:1627 ../../library/datetime.rst:2022 +#: ../../library/datetime.rst:1633 ../../library/datetime.rst:2028 msgid "``'microseconds'``: Include full time in ``HH:MM:SS.ffffff`` format." msgstr "" -#: ../../library/datetime.rst:1631 ../../library/datetime.rst:2026 +#: ../../library/datetime.rst:1637 ../../library/datetime.rst:2032 msgid "Excluded time components are truncated, not rounded." msgstr "" -#: ../../library/datetime.rst:1633 +#: ../../library/datetime.rst:1639 msgid ":exc:`ValueError` will be raised on an invalid *timespec* argument::" msgstr "" -#: ../../library/datetime.rst:1636 +#: ../../library/datetime.rst:1642 +#, fuzzy msgid "" -">>> from datetime import datetime\n" -">>> datetime.now().isoformat(timespec='minutes')\n" +">>> import datetime as dt\n" +">>> dt.datetime.now().isoformat(timespec='minutes')\n" "'2002-12-25T00:00'\n" -">>> dt = datetime(2015, 1, 1, 12, 30, 59, 0)\n" -">>> dt.isoformat(timespec='microseconds')\n" +">>> my_datetime = dt.datetime(2015, 1, 1, 12, 30, 59, 0)\n" +">>> my_datetime.isoformat(timespec='microseconds')\n" "'2015-01-01T12:30:59.000000'" msgstr "" ">>> from datetime import datetime\n" @@ -2405,51 +2428,52 @@ msgstr "" ">>> dt.isoformat(timespec='microseconds')\n" "'2015-01-01T12:30:59.000000'" -#: ../../library/datetime.rst:1643 ../../library/datetime.rst:2041 +#: ../../library/datetime.rst:1649 ../../library/datetime.rst:2047 msgid "Added the *timespec* parameter." msgstr "新增 *timespec* 參數。" -#: ../../library/datetime.rst:1649 +#: ../../library/datetime.rst:1655 msgid "" "For a :class:`.datetime` instance ``d``, ``str(d)`` is equivalent to ``d." "isoformat(' ')``." msgstr "" -#: ../../library/datetime.rst:1655 +#: ../../library/datetime.rst:1661 msgid "Return a string representing the date and time::" msgstr "" -#: ../../library/datetime.rst:1657 +#: ../../library/datetime.rst:1663 +#, fuzzy msgid "" -">>> from datetime import datetime\n" -">>> datetime(2002, 12, 4, 20, 30, 40).ctime()\n" +">>> import datetime as dt\n" +">>> dt.datetime(2002, 12, 4, 20, 30, 40).ctime()\n" "'Wed Dec 4 20:30:40 2002'" msgstr "" ">>> from datetime import datetime\n" ">>> datetime(2002, 12, 4, 20, 30, 40).ctime()\n" "'Wed Dec 4 20:30:40 2002'" -#: ../../library/datetime.rst:1661 +#: ../../library/datetime.rst:1667 msgid "" "The output string will *not* include time zone information, regardless of " "whether the input is aware or naive." msgstr "" -#: ../../library/datetime.rst:1668 +#: ../../library/datetime.rst:1674 msgid "" "on platforms where the native C :c:func:`ctime` function (which :func:`time." "ctime` invokes, but which :meth:`datetime.ctime` does not invoke) conforms " "to the C standard." msgstr "" -#: ../../library/datetime.rst:1675 +#: ../../library/datetime.rst:1681 msgid "" "Return a string representing the date and time, controlled by an explicit " "format string. See also :ref:`strftime-strptime-behavior` and :meth:" "`datetime.isoformat`." msgstr "" -#: ../../library/datetime.rst:1682 +#: ../../library/datetime.rst:1688 msgid "" "Same as :meth:`.datetime.strftime`. This makes it possible to specify a " "format string for a :class:`.datetime` object in :ref:`formatted string " @@ -2457,38 +2481,39 @@ msgid "" "`strftime-strptime-behavior` and :meth:`datetime.isoformat`." msgstr "" -#: ../../library/datetime.rst:1689 +#: ../../library/datetime.rst:1695 msgid "Examples of usage: :class:`!datetime`" msgstr "用法範例::class:`!datetime`" -#: ../../library/datetime.rst:1691 +#: ../../library/datetime.rst:1697 msgid "Examples of working with :class:`.datetime` objects:" msgstr "更多 :class:`.datetime` 的用法範例:" -#: ../../library/datetime.rst:1693 +#: ../../library/datetime.rst:1699 msgid "" -">>> from datetime import datetime, date, time, timezone\n" +">>> import datetime as dt\n" "\n" ">>> # Using datetime.combine()\n" -">>> d = date(2005, 7, 14)\n" -">>> t = time(12, 30)\n" -">>> datetime.combine(d, t)\n" +">>> d = dt.date(2005, 7, 14)\n" +">>> t = dt.time(12, 30)\n" +">>> dt.datetime.combine(d, t)\n" "datetime.datetime(2005, 7, 14, 12, 30)\n" "\n" ">>> # Using datetime.now()\n" -">>> datetime.now()\n" +">>> dt.datetime.now()\n" "datetime.datetime(2007, 12, 6, 16, 29, 43, 79043) # GMT +1\n" -">>> datetime.now(timezone.utc)\n" +">>> dt.datetime.now(dt.timezone.utc)\n" "datetime.datetime(2007, 12, 6, 15, 29, 43, 79060, tzinfo=datetime.timezone." "utc)\n" "\n" ">>> # Using datetime.strptime()\n" -">>> dt = datetime.strptime(\"21/11/06 16:30\", \"%d/%m/%y %H:%M\")\n" -">>> dt\n" +">>> my_datetime = dt.datetime.strptime(\"21/11/06 16:30\", \"%d/%m/%y %H:" +"%M\")\n" +">>> my_datetime\n" "datetime.datetime(2006, 11, 21, 16, 30)\n" "\n" ">>> # Using datetime.timetuple() to get tuple of all attributes\n" -">>> tt = dt.timetuple()\n" +">>> tt = my_datetime.timetuple()\n" ">>> for it in tt:\n" "... print(it)\n" "...\n" @@ -2503,7 +2528,7 @@ msgid "" "-1 # dst - method tzinfo.dst() returned None\n" "\n" ">>> # Date in ISO format\n" -">>> ic = dt.isocalendar()\n" +">>> ic = my_datetime.isocalendar()\n" ">>> for it in ic:\n" "... print(it)\n" "...\n" @@ -2512,87 +2537,87 @@ msgid "" "2 # ISO weekday\n" "\n" ">>> # Formatting a datetime\n" -">>> dt.strftime(\"%A, %d. %B %Y %I:%M%p\")\n" +">>> my_datetime.strftime(\"%A, %d. %B %Y %I:%M%p\")\n" "'Tuesday, 21. November 2006 04:30PM'\n" ">>> 'The {1} is {0:%d}, the {2} is {0:%B}, the {3} is {0:%I:%M%p}.'." -"format(dt, \"day\", \"month\", \"time\")\n" +"format(my_datetime, \"day\", \"month\", \"time\")\n" "'The day is 21, the month is November, the time is 04:30PM.'" msgstr "" -#: ../../library/datetime.rst:1744 +#: ../../library/datetime.rst:1750 msgid "" "The example below defines a :class:`tzinfo` subclass capturing time zone " "information for Kabul, Afghanistan, which used +4 UTC until 1945 and then " "+4:30 UTC thereafter::" msgstr "" -#: ../../library/datetime.rst:1748 +#: ../../library/datetime.rst:1754 msgid "" -"from datetime import timedelta, datetime, tzinfo, timezone\n" +"import datetime as dt\n" "\n" -"class KabulTz(tzinfo):\n" +"class KabulTz(dt.tzinfo):\n" " # Kabul used +4 until 1945, when they moved to +4:30\n" -" UTC_MOVE_DATE = datetime(1944, 12, 31, 20, tzinfo=timezone.utc)\n" +" UTC_MOVE_DATE = dt.datetime(1944, 12, 31, 20, tzinfo=dt.timezone.utc)\n" "\n" -" def utcoffset(self, dt):\n" -" if dt.year < 1945:\n" -" return timedelta(hours=4)\n" -" elif (1945, 1, 1, 0, 0) <= dt.timetuple()[:5] < (1945, 1, 1, 0, " +" def utcoffset(self, when):\n" +" if when.year < 1945:\n" +" return dt.timedelta(hours=4)\n" +" elif (1945, 1, 1, 0, 0) <= when.timetuple()[:5] < (1945, 1, 1, 0, " "30):\n" " # An ambiguous (\"imaginary\") half-hour range representing\n" " # a 'fold' in time due to the shift from +4 to +4:30.\n" -" # If dt falls in the imaginary range, use fold to decide how\n" -" # to resolve. See PEP495.\n" -" return timedelta(hours=4, minutes=(30 if dt.fold else 0))\n" +" # If when falls in the imaginary range, use fold to decide how\n" +" # to resolve. See PEP 495.\n" +" return dt.timedelta(hours=4, minutes=(30 if when.fold else 0))\n" " else:\n" -" return timedelta(hours=4, minutes=30)\n" +" return dt.timedelta(hours=4, minutes=30)\n" "\n" -" def fromutc(self, dt):\n" +" def fromutc(self, when):\n" " # Follow same validations as in datetime.tzinfo\n" -" if not isinstance(dt, datetime):\n" +" if not isinstance(when, dt.datetime):\n" " raise TypeError(\"fromutc() requires a datetime argument\")\n" -" if dt.tzinfo is not self:\n" -" raise ValueError(\"dt.tzinfo is not self\")\n" +" if when.tzinfo is not self:\n" +" raise ValueError(\"when.tzinfo is not self\")\n" "\n" " # A custom implementation is required for fromutc as\n" " # the input to this function is a datetime with utc values\n" " # but with a tzinfo set to self.\n" " # See datetime.astimezone or fromtimestamp.\n" -" if dt.replace(tzinfo=timezone.utc) >= self.UTC_MOVE_DATE:\n" -" return dt + timedelta(hours=4, minutes=30)\n" +" if when.replace(tzinfo=dt.timezone.utc) >= self.UTC_MOVE_DATE:\n" +" return when + dt.timedelta(hours=4, minutes=30)\n" " else:\n" -" return dt + timedelta(hours=4)\n" +" return when + dt.timedelta(hours=4)\n" "\n" -" def dst(self, dt):\n" +" def dst(self, when):\n" " # Kabul does not observe daylight saving time.\n" -" return timedelta(0)\n" +" return dt.timedelta(0)\n" "\n" -" def tzname(self, dt):\n" -" if dt >= self.UTC_MOVE_DATE:\n" +" def tzname(self, when):\n" +" if when >= self.UTC_MOVE_DATE:\n" " return \"+04:30\"\n" " return \"+04\"" msgstr "" -#: ../../library/datetime.rst:1791 +#: ../../library/datetime.rst:1797 msgid "Usage of ``KabulTz`` from above::" msgstr "" -#: ../../library/datetime.rst:1793 +#: ../../library/datetime.rst:1799 msgid "" ">>> tz1 = KabulTz()\n" "\n" ">>> # Datetime before the change\n" -">>> dt1 = datetime(1900, 11, 21, 16, 30, tzinfo=tz1)\n" +">>> dt1 = dt.datetime(1900, 11, 21, 16, 30, tzinfo=tz1)\n" ">>> print(dt1.utcoffset())\n" "4:00:00\n" "\n" ">>> # Datetime after the change\n" -">>> dt2 = datetime(2006, 6, 14, 13, 0, tzinfo=tz1)\n" +">>> dt2 = dt.datetime(2006, 6, 14, 13, 0, tzinfo=tz1)\n" ">>> print(dt2.utcoffset())\n" "4:30:00\n" "\n" ">>> # Convert datetime to another time zone\n" -">>> dt3 = dt2.astimezone(timezone.utc)\n" +">>> dt3 = dt2.astimezone(dt.timezone.utc)\n" ">>> dt3\n" "datetime.datetime(2006, 6, 14, 8, 30, tzinfo=datetime.timezone.utc)\n" ">>> dt2\n" @@ -2601,63 +2626,63 @@ msgid "" "True" msgstr "" -#: ../../library/datetime.rst:1818 +#: ../../library/datetime.rst:1824 msgid ":class:`!time` objects" msgstr ":class:`!time` 物件" -#: ../../library/datetime.rst:1820 +#: ../../library/datetime.rst:1826 msgid "" "A :class:`.time` object represents a (local) time of day, independent of any " "particular day, and subject to adjustment via a :class:`tzinfo` object." msgstr "" -#: ../../library/datetime.rst:1825 +#: ../../library/datetime.rst:1831 msgid "" "All arguments are optional. *tzinfo* may be ``None``, or an instance of a :" "class:`tzinfo` subclass. The remaining arguments must be integers in the " "following ranges:" msgstr "" -#: ../../library/datetime.rst:1835 +#: ../../library/datetime.rst:1841 msgid "" "If an argument outside those ranges is given, :exc:`ValueError` is raised. " "All default to 0 except *tzinfo*, which defaults to ``None``." msgstr "" -#: ../../library/datetime.rst:1844 +#: ../../library/datetime.rst:1850 msgid "The earliest representable :class:`.time`, ``time(0, 0, 0, 0)``." msgstr "" -#: ../../library/datetime.rst:1849 +#: ../../library/datetime.rst:1855 msgid "The latest representable :class:`.time`, ``time(23, 59, 59, 999999)``." msgstr "" -#: ../../library/datetime.rst:1854 +#: ../../library/datetime.rst:1860 msgid "" "The smallest possible difference between non-equal :class:`.time` objects, " "``timedelta(microseconds=1)``, although note that arithmetic on :class:`." "time` objects is not supported." msgstr "" -#: ../../library/datetime.rst:1883 +#: ../../library/datetime.rst:1889 msgid "" "The object passed as the tzinfo argument to the :class:`.time` constructor, " "or ``None`` if none was passed." msgstr "" -#: ../../library/datetime.rst:1898 +#: ../../library/datetime.rst:1904 msgid "" ":class:`.time` objects support equality and order comparisons, where ``a`` " "is considered less than ``b`` when ``a`` precedes ``b`` in time." msgstr "" -#: ../../library/datetime.rst:1901 +#: ../../library/datetime.rst:1907 msgid "" "Naive and aware :class:`!time` objects are never equal. Order comparison " "between naive and aware :class:`!time` objects raises :exc:`TypeError`." msgstr "" -#: ../../library/datetime.rst:1905 +#: ../../library/datetime.rst:1911 msgid "" "If both comparands are aware, and have the same :attr:`~.time.tzinfo` " "attribute, the :attr:`!tzinfo` and :attr:`!fold` attributes are ignored and " @@ -2666,18 +2691,18 @@ msgid "" "subtracting their UTC offsets (obtained from ``self.utcoffset()``)." msgstr "" -#: ../../library/datetime.rst:1911 +#: ../../library/datetime.rst:1917 msgid "" "Equality comparisons between aware and naive :class:`.time` instances don't " "raise :exc:`TypeError`." msgstr "" -#: ../../library/datetime.rst:1915 +#: ../../library/datetime.rst:1921 msgid "" "In Boolean contexts, a :class:`.time` object is always considered to be true." msgstr "" -#: ../../library/datetime.rst:1917 +#: ../../library/datetime.rst:1923 msgid "" "Before Python 3.5, a :class:`.time` object was considered to be false if it " "represented midnight in UTC. This behavior was considered obscure and error-" @@ -2685,51 +2710,52 @@ msgid "" "information." msgstr "" -#: ../../library/datetime.rst:1924 +#: ../../library/datetime.rst:1930 msgid "Other constructors:" msgstr "其他建構函式:" -#: ../../library/datetime.rst:1928 +#: ../../library/datetime.rst:1934 msgid "" "Return a :class:`.time` corresponding to a *time_string* in any valid ISO " "8601 format, with the following exceptions:" msgstr "" -#: ../../library/datetime.rst:1932 +#: ../../library/datetime.rst:1938 msgid "" "The leading ``T``, normally required in cases where there may be ambiguity " "between a date and a time, is not required." msgstr "" -#: ../../library/datetime.rst:1934 +#: ../../library/datetime.rst:1940 msgid "" "Fractional seconds may have any number of digits (anything beyond 6 will be " "truncated)." msgstr "" -#: ../../library/datetime.rst:1938 +#: ../../library/datetime.rst:1944 msgid "Examples:" msgstr "範例: ::" -#: ../../library/datetime.rst:1940 +#: ../../library/datetime.rst:1946 +#, fuzzy msgid "" -">>> from datetime import time\n" -">>> time.fromisoformat('04:23:01')\n" +">>> import datetime as dt\n" +">>> dt.time.fromisoformat('04:23:01')\n" "datetime.time(4, 23, 1)\n" -">>> time.fromisoformat('T04:23:01')\n" +">>> dt.time.fromisoformat('T04:23:01')\n" "datetime.time(4, 23, 1)\n" -">>> time.fromisoformat('T042301')\n" +">>> dt.time.fromisoformat('T042301')\n" "datetime.time(4, 23, 1)\n" -">>> time.fromisoformat('04:23:01.000384')\n" +">>> dt.time.fromisoformat('04:23:01.000384')\n" "datetime.time(4, 23, 1, 384)\n" -">>> time.fromisoformat('04:23:01,000384')\n" +">>> dt.time.fromisoformat('04:23:01,000384')\n" "datetime.time(4, 23, 1, 384)\n" -">>> time.fromisoformat('04:23:01+04:00')\n" +">>> dt.time.fromisoformat('04:23:01+04:00')\n" "datetime.time(4, 23, 1, tzinfo=datetime.timezone(datetime." "timedelta(seconds=14400)))\n" -">>> time.fromisoformat('04:23:01Z')\n" +">>> dt.time.fromisoformat('04:23:01Z')\n" "datetime.time(4, 23, 1, tzinfo=datetime.timezone.utc)\n" -">>> time.fromisoformat('04:23:01+00:00')\n" +">>> dt.time.fromisoformat('04:23:01+00:00')\n" "datetime.time(4, 23, 1, tzinfo=datetime.timezone.utc)" msgstr "" ">>> from datetime import time\n" @@ -2751,29 +2777,29 @@ msgstr "" ">>> time.fromisoformat('04:23:01+00:00')\n" "datetime.time(4, 23, 1, tzinfo=datetime.timezone.utc)" -#: ../../library/datetime.rst:1962 +#: ../../library/datetime.rst:1968 msgid "" "Previously, this method only supported formats that could be emitted by :" "meth:`time.isoformat`." msgstr "" -#: ../../library/datetime.rst:1969 +#: ../../library/datetime.rst:1975 msgid "" "Return a :class:`.time` corresponding to *date_string*, parsed according to " "*format*." msgstr "" -#: ../../library/datetime.rst:1972 +#: ../../library/datetime.rst:1978 msgid "" "If *format* does not contain microseconds or timezone information, this is " "equivalent to::" msgstr "" -#: ../../library/datetime.rst:1974 +#: ../../library/datetime.rst:1980 msgid "time(*(time.strptime(date_string, format)[3:6]))" msgstr "time(*(time.strptime(date_string, format)[3:6]))" -#: ../../library/datetime.rst:1976 +#: ../../library/datetime.rst:1982 msgid "" ":exc:`ValueError` is raised if the *date_string* and *format* cannot be " "parsed by :func:`time.strptime` or if it returns a value which is not a time " @@ -2781,58 +2807,59 @@ msgid "" "fromisoformat`." msgstr "" -#: ../../library/datetime.rst:1989 +#: ../../library/datetime.rst:1995 msgid "" "Return a new :class:`.time` with the same values, but with specified " "parameters updated. Note that ``tzinfo=None`` can be specified to create a " -"naive :class:`.time` from an aware :class:`.time`, without conversion of the " +"naive :class:`!time` from an aware :class:`!time`, without conversion of the " "time data." msgstr "" -#: ../../library/datetime.rst:1994 +#: ../../library/datetime.rst:2000 msgid "" ":class:`.time` objects are also supported by generic function :func:`copy." "replace`." msgstr "" -#: ../../library/datetime.rst:2003 +#: ../../library/datetime.rst:2009 msgid "Return a string representing the time in ISO 8601 format, one of:" msgstr "" -#: ../../library/datetime.rst:2005 +#: ../../library/datetime.rst:2011 msgid "``HH:MM:SS.ffffff``, if :attr:`microsecond` is not 0" msgstr "" -#: ../../library/datetime.rst:2006 +#: ../../library/datetime.rst:2012 msgid "``HH:MM:SS``, if :attr:`microsecond` is 0" msgstr "" -#: ../../library/datetime.rst:2007 +#: ../../library/datetime.rst:2013 msgid "" "``HH:MM:SS.ffffff+HH:MM[:SS[.ffffff]]``, if :meth:`utcoffset` does not " "return ``None``" msgstr "" -#: ../../library/datetime.rst:2008 +#: ../../library/datetime.rst:2014 msgid "" "``HH:MM:SS+HH:MM[:SS[.ffffff]]``, if :attr:`microsecond` is 0 and :meth:" "`utcoffset` does not return ``None``" msgstr "" -#: ../../library/datetime.rst:2028 +#: ../../library/datetime.rst:2034 msgid ":exc:`ValueError` will be raised on an invalid *timespec* argument." msgstr "" -#: ../../library/datetime.rst:2032 +#: ../../library/datetime.rst:2038 +#, fuzzy msgid "" -">>> from datetime import time\n" -">>> time(hour=12, minute=34, second=56, microsecond=123456)." +">>> import datetime as dt\n" +">>> dt.time(hour=12, minute=34, second=56, microsecond=123456)." "isoformat(timespec='minutes')\n" "'12:34'\n" -">>> dt = time(hour=12, minute=34, second=56, microsecond=0)\n" -">>> dt.isoformat(timespec='microseconds')\n" +">>> my_time = dt.time(hour=12, minute=34, second=56, microsecond=0)\n" +">>> my_time.isoformat(timespec='microseconds')\n" "'12:34:56.000000'\n" -">>> dt.isoformat(timespec='auto')\n" +">>> my_time.isoformat(timespec='auto')\n" "'12:34:56'" msgstr "" ">>> from datetime import time\n" @@ -2845,18 +2872,18 @@ msgstr "" ">>> dt.isoformat(timespec='auto')\n" "'12:34:56'" -#: ../../library/datetime.rst:2047 +#: ../../library/datetime.rst:2053 msgid "For a time ``t``, ``str(t)`` is equivalent to ``t.isoformat()``." msgstr "" -#: ../../library/datetime.rst:2052 +#: ../../library/datetime.rst:2058 msgid "" "Return a string representing the time, controlled by an explicit format " "string. See also :ref:`strftime-strptime-behavior` and :meth:`time." "isoformat`." msgstr "" -#: ../../library/datetime.rst:2058 +#: ../../library/datetime.rst:2064 msgid "" "Same as :meth:`.time.strftime`. This makes it possible to specify a format " "string for a :class:`.time` object in :ref:`formatted string literals >> from datetime import time, tzinfo, timedelta\n" -">>> class TZ1(tzinfo):\n" -"... def utcoffset(self, dt):\n" -"... return timedelta(hours=1)\n" -"... def dst(self, dt):\n" -"... return timedelta(0)\n" -"... def tzname(self,dt):\n" +">>> import datetime as dt\n" +">>> class TZ1(dt.tzinfo):\n" +"... def utcoffset(self, when):\n" +"... return dt.timedelta(hours=1)\n" +"... def dst(self, when):\n" +"... return dt.timedelta(0)\n" +"... def tzname(self, when):\n" "... return \"+01:00\"\n" "... def __repr__(self):\n" "... return f\"{self.__class__.__name__}()\"\n" "...\n" -">>> t = time(12, 10, 30, tzinfo=TZ1())\n" +">>> t = dt.time(12, 10, 30, tzinfo=TZ1())\n" ">>> t\n" "datetime.time(12, 10, 30, tzinfo=TZ1())\n" ">>> t.isoformat()\n" @@ -2945,38 +2973,38 @@ msgstr "" ">>> 'The {} is {:%H:%M}.'.format(\"time\", t)\n" "'The time is 12:10.'" -#: ../../library/datetime.rst:2125 +#: ../../library/datetime.rst:2131 msgid ":class:`!tzinfo` objects" msgstr ":class:`!tzinfo` 物件" -#: ../../library/datetime.rst:2129 +#: ../../library/datetime.rst:2135 msgid "" "This is an :term:`abstract base class`, meaning that this class should not " "be instantiated directly. Define a subclass of :class:`tzinfo` to capture " "information about a particular time zone." msgstr "" -#: ../../library/datetime.rst:2133 +#: ../../library/datetime.rst:2139 msgid "" "An instance of (a concrete subclass of) :class:`tzinfo` can be passed to the " "constructors for :class:`.datetime` and :class:`.time` objects. The latter " -"objects view their attributes as being in local time, and the :class:" -"`tzinfo` object supports methods revealing offset of local time from UTC, " -"the name of the time zone, and DST offset, all relative to a date or time " -"object passed to them." +"objects view their attributes as being in local time, and the :class:`!" +"tzinfo` object supports methods revealing offset of local time from UTC, the " +"name of the time zone, and DST offset, all relative to a date or time object " +"passed to them." msgstr "" -#: ../../library/datetime.rst:2139 +#: ../../library/datetime.rst:2145 msgid "" "You need to derive a concrete subclass, and (at least) supply " "implementations of the standard :class:`tzinfo` methods needed by the :class:" "`.datetime` methods you use. The :mod:`!datetime` module provides :class:" -"`timezone`, a simple concrete subclass of :class:`tzinfo` which can " +"`timezone`, a simple concrete subclass of :class:`!tzinfo` which can " "represent time zones with fixed offset from UTC such as UTC itself or North " "American EST and EDT." msgstr "" -#: ../../library/datetime.rst:2146 +#: ../../library/datetime.rst:2152 msgid "" "Special requirement for pickling: A :class:`tzinfo` subclass must have an :" "meth:`~object.__init__` method that can be called with no arguments, " @@ -2984,20 +3012,20 @@ msgid "" "technical requirement that may be relaxed in the future." msgstr "" -#: ../../library/datetime.rst:2152 +#: ../../library/datetime.rst:2158 msgid "" "A concrete subclass of :class:`tzinfo` may need to implement the following " "methods. Exactly which methods are needed depends on the uses made of aware :" "mod:`!datetime` objects. If in doubt, simply implement all of them." msgstr "" -#: ../../library/datetime.rst:2159 +#: ../../library/datetime.rst:2165 msgid "" "Return offset of local time from UTC, as a :class:`timedelta` object that is " "positive east of UTC. If local time is west of UTC, this should be negative." msgstr "" -#: ../../library/datetime.rst:2162 +#: ../../library/datetime.rst:2168 msgid "" "This represents the *total* offset from UTC; for example, if a :class:" "`tzinfo` object represents both time zone and DST adjustments, :meth:" @@ -3008,31 +3036,31 @@ msgid "" "meth:`utcoffset` will probably look like one of these two::" msgstr "" -#: ../../library/datetime.rst:2170 +#: ../../library/datetime.rst:2176 msgid "" "return CONSTANT # fixed-offset class\n" "return CONSTANT + self.dst(dt) # daylight-aware class" msgstr "" -#: ../../library/datetime.rst:2173 +#: ../../library/datetime.rst:2179 msgid "" "If :meth:`utcoffset` does not return ``None``, :meth:`dst` should not return " "``None`` either." msgstr "" -#: ../../library/datetime.rst:2176 +#: ../../library/datetime.rst:2182 msgid "" "The default implementation of :meth:`utcoffset` raises :exc:" "`NotImplementedError`." msgstr "" -#: ../../library/datetime.rst:2185 +#: ../../library/datetime.rst:2191 msgid "" "Return the daylight saving time (DST) adjustment, as a :class:`timedelta` " "object or ``None`` if DST information isn't known." msgstr "" -#: ../../library/datetime.rst:2189 +#: ../../library/datetime.rst:2195 msgid "" "Return ``timedelta(0)`` if DST is not in effect. If DST is in effect, return " "the offset as a :class:`timedelta` object (see :meth:`utcoffset` for " @@ -3045,65 +3073,69 @@ msgid "" "to account for DST changes when crossing time zones." msgstr "" -#: ../../library/datetime.rst:2199 +#: ../../library/datetime.rst:2205 msgid "" "An instance *tz* of a :class:`tzinfo` subclass that models both standard and " "daylight times must be consistent in this sense:" msgstr "" -#: ../../library/datetime.rst:2202 +#: ../../library/datetime.rst:2208 msgid "``tz.utcoffset(dt) - tz.dst(dt)``" msgstr "``tz.utcoffset(dt) - tz.dst(dt)``" -#: ../../library/datetime.rst:2204 +#: ../../library/datetime.rst:2210 msgid "" "must return the same result for every :class:`.datetime` *dt* with ``dt." -"tzinfo == tz``. For sane :class:`tzinfo` subclasses, this expression yields " +"tzinfo == tz``. For sane :class:`!tzinfo` subclasses, this expression yields " "the time zone's \"standard offset\", which should not depend on the date or " "the time, but only on geographic location. The implementation of :meth:" "`datetime.astimezone` relies on this, but cannot detect violations; it's the " -"programmer's responsibility to ensure it. If a :class:`tzinfo` subclass " +"programmer's responsibility to ensure it. If a :class:`!tzinfo` subclass " "cannot guarantee this, it may be able to override the default implementation " "of :meth:`tzinfo.fromutc` to work correctly with :meth:`~.datetime." "astimezone` regardless." msgstr "" -#: ../../library/datetime.rst:2213 +#: ../../library/datetime.rst:2219 msgid "" "Most implementations of :meth:`dst` will probably look like one of these " "two::" msgstr "" -#: ../../library/datetime.rst:2215 +#: ../../library/datetime.rst:2221 msgid "" -"def dst(self, dt):\n" +"import datetime as dt\n" +"\n" +"def dst(self, when):\n" " # a fixed-offset class: doesn't account for DST\n" -" return timedelta(0)" +" return dt.timedelta(0)" msgstr "" -#: ../../library/datetime.rst:2219 +#: ../../library/datetime.rst:2227 msgid "or::" msgstr "或是: ::" -#: ../../library/datetime.rst:2221 +#: ../../library/datetime.rst:2229 msgid "" -"def dst(self, dt):\n" +"import datetime as dt\n" +"\n" +"def dst(self, when):\n" " # Code to set dston and dstoff to the time zone's DST\n" -" # transition times based on the input dt.year, and expressed\n" +" # transition times based on the input when.year, and expressed\n" " # in standard local time.\n" "\n" -" if dston <= dt.replace(tzinfo=None) < dstoff:\n" -" return timedelta(hours=1)\n" +" if dston <= when.replace(tzinfo=None) < dstoff:\n" +" return dt.timedelta(hours=1)\n" " else:\n" -" return timedelta(0)" +" return dt.timedelta(0)" msgstr "" -#: ../../library/datetime.rst:2231 +#: ../../library/datetime.rst:2241 msgid "" "The default implementation of :meth:`dst` raises :exc:`NotImplementedError`." msgstr "" -#: ../../library/datetime.rst:2239 +#: ../../library/datetime.rst:2249 msgid "" "Return the time zone name corresponding to the :class:`.datetime` object " "*dt*, as a string. Nothing about string names is defined by the :mod:`!" @@ -3113,27 +3145,27 @@ msgid "" "all valid replies. Return ``None`` if a string name isn't known. Note that " "this is a method rather than a fixed string primarily because some :class:" "`tzinfo` subclasses will wish to return different names depending on the " -"specific value of *dt* passed, especially if the :class:`tzinfo` class is " +"specific value of *dt* passed, especially if the :class:`!tzinfo` class is " "accounting for daylight time." msgstr "" -#: ../../library/datetime.rst:2249 +#: ../../library/datetime.rst:2259 msgid "" "The default implementation of :meth:`tzname` raises :exc:" "`NotImplementedError`." msgstr "" -#: ../../library/datetime.rst:2252 +#: ../../library/datetime.rst:2262 msgid "" "These methods are called by a :class:`.datetime` or :class:`.time` object, " -"in response to their methods of the same names. A :class:`.datetime` object " -"passes itself as the argument, and a :class:`.time` object passes ``None`` " +"in response to their methods of the same names. A :class:`!datetime` object " +"passes itself as the argument, and a :class:`!time` object passes ``None`` " "as the argument. A :class:`tzinfo` subclass's methods should therefore be " -"prepared to accept a *dt* argument of ``None``, or of class :class:`." +"prepared to accept a *dt* argument of ``None``, or of class :class:`!" "datetime`." msgstr "" -#: ../../library/datetime.rst:2258 +#: ../../library/datetime.rst:2268 msgid "" "When ``None`` is passed, it's up to the class designer to decide the best " "response. For example, returning ``None`` is appropriate if the class wishes " @@ -3142,23 +3174,23 @@ msgid "" "offset, as there is no other convention for discovering the standard offset." msgstr "" -#: ../../library/datetime.rst:2264 +#: ../../library/datetime.rst:2274 msgid "" -"When a :class:`.datetime` object is passed in response to a :class:`." +"When a :class:`.datetime` object is passed in response to a :class:`!" "datetime` method, ``dt.tzinfo`` is the same object as *self*. :class:" -"`tzinfo` methods can rely on this, unless user code calls :class:`tzinfo` " -"methods directly. The intent is that the :class:`tzinfo` methods interpret " +"`tzinfo` methods can rely on this, unless user code calls :class:`!tzinfo` " +"methods directly. The intent is that the :class:`!tzinfo` methods interpret " "*dt* as being in local time, and not need worry about objects in other time " "zones." msgstr "" -#: ../../library/datetime.rst:2270 +#: ../../library/datetime.rst:2280 msgid "" "There is one more :class:`tzinfo` method that a subclass may wish to " "override:" msgstr "" -#: ../../library/datetime.rst:2275 +#: ../../library/datetime.rst:2285 msgid "" "This is called from the default :meth:`datetime.astimezone` implementation. " "When called from that, ``dt.tzinfo`` is *self*, and *dt*'s date and time " @@ -3167,7 +3199,7 @@ msgid "" "datetime in *self*'s local time." msgstr "" -#: ../../library/datetime.rst:2281 +#: ../../library/datetime.rst:2291 msgid "" "Most :class:`tzinfo` subclasses should be able to inherit the default :meth:" "`fromutc` implementation without problems. It's strong enough to handle " @@ -3182,103 +3214,107 @@ msgid "" "offset changes." msgstr "" -#: ../../library/datetime.rst:2292 +#: ../../library/datetime.rst:2302 msgid "" "Skipping code for error cases, the default :meth:`fromutc` implementation " "acts like::" msgstr "" -#: ../../library/datetime.rst:2295 +#: ../../library/datetime.rst:2305 msgid "" -"def fromutc(self, dt):\n" -" # raise ValueError error if dt.tzinfo is not self\n" -" dtoff = dt.utcoffset()\n" -" dtdst = dt.dst()\n" +"import datetime as dt\n" +"\n" +"def fromutc(self, when):\n" +" # raise ValueError error if when.tzinfo is not self\n" +" dtoff = when.utcoffset()\n" +" dtdst = when.dst()\n" " # raise ValueError if dtoff is None or dtdst is None\n" " delta = dtoff - dtdst # this is self's standard offset\n" " if delta:\n" -" dt += delta # convert to standard local time\n" -" dtdst = dt.dst()\n" +" when += delta # convert to standard local time\n" +" dtdst = when.dst()\n" " # raise ValueError if dtdst is None\n" " if dtdst:\n" -" return dt + dtdst\n" +" return when + dtdst\n" " else:\n" -" return dt" +" return when" msgstr "" -#: ../../library/datetime.rst:2310 +#: ../../library/datetime.rst:2322 msgid "" "In the following :download:`tzinfo_examples.py <../includes/tzinfo_examples." "py>` file there are some examples of :class:`tzinfo` classes:" msgstr "" -#: ../../library/datetime.rst:2314 +#: ../../library/datetime.rst:2326 msgid "" -"from datetime import tzinfo, timedelta, datetime\n" -"\n" -"ZERO = timedelta(0)\n" -"HOUR = timedelta(hours=1)\n" -"SECOND = timedelta(seconds=1)\n" +"import datetime as dt\n" "\n" "# A class capturing the platform's idea of local time.\n" "# (May result in wrong values on historical times in\n" "# timezones where UTC offset and/or the DST rules had\n" "# changed in the past.)\n" -"import time as _time\n" +"import time\n" "\n" -"STDOFFSET = timedelta(seconds = -_time.timezone)\n" -"if _time.daylight:\n" -" DSTOFFSET = timedelta(seconds = -_time.altzone)\n" +"ZERO = dt.timedelta(0)\n" +"HOUR = dt.timedelta(hours=1)\n" +"SECOND = dt.timedelta(seconds=1)\n" +"\n" +"STDOFFSET = dt.timedelta(seconds=-time.timezone)\n" +"if time.daylight:\n" +" DSTOFFSET = dt.timedelta(seconds=-time.altzone)\n" "else:\n" " DSTOFFSET = STDOFFSET\n" "\n" "DSTDIFF = DSTOFFSET - STDOFFSET\n" "\n" -"class LocalTimezone(tzinfo):\n" "\n" -" def fromutc(self, dt):\n" -" assert dt.tzinfo is self\n" -" stamp = (dt - datetime(1970, 1, 1, tzinfo=self)) // SECOND\n" -" args = _time.localtime(stamp)[:6]\n" +"class LocalTimezone(dt.tzinfo):\n" +"\n" +" def fromutc(self, when):\n" +" assert when.tzinfo is self\n" +" stamp = (when - dt.datetime(1970, 1, 1, tzinfo=self)) // SECOND\n" +" args = time.localtime(stamp)[:6]\n" " dst_diff = DSTDIFF // SECOND\n" " # Detect fold\n" -" fold = (args == _time.localtime(stamp - dst_diff))\n" -" return datetime(*args, microsecond=dt.microsecond,\n" -" tzinfo=self, fold=fold)\n" +" fold = (args == time.localtime(stamp - dst_diff))\n" +" return dt.datetime(*args, microsecond=when.microsecond,\n" +" tzinfo=self, fold=fold)\n" "\n" -" def utcoffset(self, dt):\n" -" if self._isdst(dt):\n" +" def utcoffset(self, when):\n" +" if self._isdst(when):\n" " return DSTOFFSET\n" " else:\n" " return STDOFFSET\n" "\n" -" def dst(self, dt):\n" -" if self._isdst(dt):\n" +" def dst(self, when):\n" +" if self._isdst(when):\n" " return DSTDIFF\n" " else:\n" " return ZERO\n" "\n" -" def tzname(self, dt):\n" -" return _time.tzname[self._isdst(dt)]\n" +" def tzname(self, when):\n" +" return time.tzname[self._isdst(when)]\n" "\n" -" def _isdst(self, dt):\n" -" tt = (dt.year, dt.month, dt.day,\n" -" dt.hour, dt.minute, dt.second,\n" -" dt.weekday(), 0, 0)\n" -" stamp = _time.mktime(tt)\n" -" tt = _time.localtime(stamp)\n" +" def _isdst(self, when):\n" +" tt = (when.year, when.month, when.day,\n" +" when.hour, when.minute, when.second,\n" +" when.weekday(), 0, 0)\n" +" stamp = time.mktime(tt)\n" +" tt = time.localtime(stamp)\n" " return tt.tm_isdst > 0\n" "\n" +"\n" "Local = LocalTimezone()\n" "\n" "\n" "# A complete implementation of current DST rules for major US time zones.\n" "\n" -"def first_sunday_on_or_after(dt):\n" -" days_to_go = 6 - dt.weekday()\n" +"def first_sunday_on_or_after(when):\n" +" days_to_go = 6 - when.weekday()\n" " if days_to_go:\n" -" dt += timedelta(days_to_go)\n" -" return dt\n" +" when += dt.timedelta(days_to_go)\n" +" return when\n" "\n" "\n" "# US DST Rules\n" @@ -3291,22 +3327,23 @@ msgid "" "#\n" "# In the US, since 2007, DST starts at 2am (standard time) on the second\n" "# Sunday in March, which is the first Sunday on or after Mar 8.\n" -"DSTSTART_2007 = datetime(1, 3, 8, 2)\n" +"DSTSTART_2007 = dt.datetime(1, 3, 8, 2)\n" "# and ends at 2am (DST time) on the first Sunday of Nov.\n" -"DSTEND_2007 = datetime(1, 11, 1, 2)\n" +"DSTEND_2007 = dt.datetime(1, 11, 1, 2)\n" "# From 1987 to 2006, DST used to start at 2am (standard time) on the first\n" "# Sunday in April and to end at 2am (DST time) on the last\n" "# Sunday of October, which is the first Sunday on or after Oct 25.\n" -"DSTSTART_1987_2006 = datetime(1, 4, 1, 2)\n" -"DSTEND_1987_2006 = datetime(1, 10, 25, 2)\n" +"DSTSTART_1987_2006 = dt.datetime(1, 4, 1, 2)\n" +"DSTEND_1987_2006 = dt.datetime(1, 10, 25, 2)\n" "# From 1967 to 1986, DST used to start at 2am (standard time) on the last\n" "# Sunday in April (the one on or after April 24) and to end at 2am (DST " "time)\n" "# on the last Sunday of October, which is the first Sunday\n" "# on or after Oct 25.\n" -"DSTSTART_1967_1986 = datetime(1, 4, 24, 2)\n" +"DSTSTART_1967_1986 = dt.datetime(1, 4, 24, 2)\n" "DSTEND_1967_1986 = DSTEND_1987_2006\n" "\n" +"\n" "def us_dst_range(year):\n" " # Find start and end times for US DST. For years before 1967, return\n" " # start = end for no DST.\n" @@ -3317,17 +3354,17 @@ msgid "" " elif 1966 < year < 1987:\n" " dststart, dstend = DSTSTART_1967_1986, DSTEND_1967_1986\n" " else:\n" -" return (datetime(year, 1, 1), ) * 2\n" +" return (dt.datetime(year, 1, 1), ) * 2\n" "\n" " start = first_sunday_on_or_after(dststart.replace(year=year))\n" " end = first_sunday_on_or_after(dstend.replace(year=year))\n" " return start, end\n" "\n" "\n" -"class USTimeZone(tzinfo):\n" +"class USTimeZone(dt.tzinfo):\n" "\n" " def __init__(self, hours, reprname, stdname, dstname):\n" -" self.stdoffset = timedelta(hours=hours)\n" +" self.stdoffset = dt.timedelta(hours=hours)\n" " self.reprname = reprname\n" " self.stdname = stdname\n" " self.dstname = dstname\n" @@ -3335,45 +3372,45 @@ msgid "" " def __repr__(self):\n" " return self.reprname\n" "\n" -" def tzname(self, dt):\n" -" if self.dst(dt):\n" +" def tzname(self, when):\n" +" if self.dst(when):\n" " return self.dstname\n" " else:\n" " return self.stdname\n" "\n" -" def utcoffset(self, dt):\n" -" return self.stdoffset + self.dst(dt)\n" +" def utcoffset(self, when):\n" +" return self.stdoffset + self.dst(when)\n" "\n" -" def dst(self, dt):\n" -" if dt is None or dt.tzinfo is None:\n" +" def dst(self, when):\n" +" if when is None or when.tzinfo is None:\n" " # An exception may be sensible here, in one or both cases.\n" " # It depends on how you want to treat them. The default\n" " # fromutc() implementation (called by the default astimezone()\n" -" # implementation) passes a datetime with dt.tzinfo is self.\n" +" # implementation) passes a datetime with when.tzinfo is self.\n" " return ZERO\n" -" assert dt.tzinfo is self\n" -" start, end = us_dst_range(dt.year)\n" +" assert when.tzinfo is self\n" +" start, end = us_dst_range(when.year)\n" " # Can't compare naive to aware objects, so strip the timezone from\n" -" # dt first.\n" -" dt = dt.replace(tzinfo=None)\n" -" if start + HOUR <= dt < end - HOUR:\n" +" # when first.\n" +" when = when.replace(tzinfo=None)\n" +" if start + HOUR <= when < end - HOUR:\n" " # DST is in effect.\n" " return HOUR\n" -" if end - HOUR <= dt < end:\n" -" # Fold (an ambiguous hour): use dt.fold to disambiguate.\n" -" return ZERO if dt.fold else HOUR\n" -" if start <= dt < start + HOUR:\n" +" if end - HOUR <= when < end:\n" +" # Fold (an ambiguous hour): use when.fold to disambiguate.\n" +" return ZERO if when.fold else HOUR\n" +" if start <= when < start + HOUR:\n" " # Gap (a non-existent hour): reverse the fold rule.\n" -" return HOUR if dt.fold else ZERO\n" +" return HOUR if when.fold else ZERO\n" " # DST is off.\n" " return ZERO\n" "\n" -" def fromutc(self, dt):\n" -" assert dt.tzinfo is self\n" -" start, end = us_dst_range(dt.year)\n" +" def fromutc(self, when):\n" +" assert when.tzinfo is self\n" +" start, end = us_dst_range(when.year)\n" " start = start.replace(tzinfo=self)\n" " end = end.replace(tzinfo=self)\n" -" std_time = dt + self.stdoffset\n" +" std_time = when + self.stdoffset\n" " dst_time = std_time + HOUR\n" " if end <= dst_time < end + HOUR:\n" " # Repeated hour\n" @@ -3392,7 +3429,7 @@ msgid "" "Pacific = USTimeZone(-8, \"Pacific\", \"PST\", \"PDT\")\n" msgstr "" -#: ../../library/datetime.rst:2316 +#: ../../library/datetime.rst:2328 msgid "" "Note that there are unavoidable subtleties twice per year in a :class:" "`tzinfo` subclass accounting for both standard and daylight time, at the DST " @@ -3401,7 +3438,7 @@ msgid "" "ends the minute after 1:59 (EDT) on the first Sunday in November::" msgstr "" -#: ../../library/datetime.rst:2322 +#: ../../library/datetime.rst:2334 msgid "" " UTC 3:MM 4:MM 5:MM 6:MM 7:MM 8:MM\n" " EST 22:MM 23:MM 0:MM 1:MM 2:MM 3:MM\n" @@ -3419,7 +3456,7 @@ msgstr "" "\n" " end 23:MM 0:MM 1:MM 1:MM 2:MM 3:MM" -#: ../../library/datetime.rst:2330 +#: ../../library/datetime.rst:2342 msgid "" "When DST starts (the \"start\" line), the local wall clock leaps from 1:59 " "to 3:00. A wall time of the form 2:MM doesn't really make sense on that day, " @@ -3428,11 +3465,12 @@ msgid "" "get::" msgstr "" -#: ../../library/datetime.rst:2335 +#: ../../library/datetime.rst:2347 +#, fuzzy msgid "" -">>> from datetime import datetime, timezone\n" +">>> import datetime as dt\n" ">>> from tzinfo_examples import HOUR, Eastern\n" -">>> u0 = datetime(2016, 3, 13, 5, tzinfo=timezone.utc)\n" +">>> u0 = dt.datetime(2016, 3, 13, 5, tzinfo=dt.timezone.utc)\n" ">>> for i in range(4):\n" "... u = u0 + i*HOUR\n" "... t = u.astimezone(Eastern)\n" @@ -3456,7 +3494,7 @@ msgstr "" "07:00:00 UTC = 03:00:00 EDT\n" "08:00:00 UTC = 04:00:00 EDT" -#: ../../library/datetime.rst:2349 +#: ../../library/datetime.rst:2361 msgid "" "When DST ends (the \"end\" line), there's a potentially worse problem: " "there's an hour that can't be spelled unambiguously in local wall time: the " @@ -3471,9 +3509,12 @@ msgid "" "Fall back transition of 2016, we get::" msgstr "" -#: ../../library/datetime.rst:2360 +#: ../../library/datetime.rst:2372 +#, fuzzy msgid "" -">>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc)\n" +">>> import datetime as dt\n" +">>> from tzinfo_examples import HOUR, Eastern\n" +">>> u0 = dt.datetime(2016, 11, 6, 4, tzinfo=dt.timezone.utc)\n" ">>> for i in range(4):\n" "... u = u0 + i*HOUR\n" "... t = u.astimezone(Eastern)\n" @@ -3484,55 +3525,57 @@ msgid "" "06:00:00 UTC = 01:00:00 EST 1\n" "07:00:00 UTC = 02:00:00 EST 0" msgstr "" -">>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc)\n" +">>> from datetime import datetime, timezone\n" +">>> from tzinfo_examples import HOUR, Eastern\n" +">>> u0 = datetime(2016, 3, 13, 5, tzinfo=timezone.utc)\n" ">>> for i in range(4):\n" "... u = u0 + i*HOUR\n" "... t = u.astimezone(Eastern)\n" -"... print(u.time(), 'UTC =', t.time(), t.tzname(), t.fold)\n" +"... print(u.time(), 'UTC =', t.time(), t.tzname())\n" "...\n" -"04:00:00 UTC = 00:00:00 EDT 0\n" -"05:00:00 UTC = 01:00:00 EDT 0\n" -"06:00:00 UTC = 01:00:00 EST 1\n" -"07:00:00 UTC = 02:00:00 EST 0" +"05:00:00 UTC = 00:00:00 EST\n" +"06:00:00 UTC = 01:00:00 EST\n" +"07:00:00 UTC = 03:00:00 EDT\n" +"08:00:00 UTC = 04:00:00 EDT" -#: ../../library/datetime.rst:2371 +#: ../../library/datetime.rst:2385 msgid "" "Note that the :class:`.datetime` instances that differ only by the value of " "the :attr:`~.datetime.fold` attribute are considered equal in comparisons." msgstr "" -#: ../../library/datetime.rst:2374 +#: ../../library/datetime.rst:2388 msgid "" "Applications that can't bear wall-time ambiguities should explicitly check " "the value of the :attr:`~.datetime.fold` attribute or avoid using hybrid :" "class:`tzinfo` subclasses; there are no ambiguities when using :class:" -"`timezone`, or any other fixed-offset :class:`tzinfo` subclass (such as a " +"`timezone`, or any other fixed-offset :class:`!tzinfo` subclass (such as a " "class representing only EST (fixed offset -5 hours), or only EDT (fixed " "offset -4 hours))." msgstr "" -#: ../../library/datetime.rst:2382 +#: ../../library/datetime.rst:2396 msgid ":mod:`zoneinfo`" msgstr ":mod:`zoneinfo`" -#: ../../library/datetime.rst:2383 +#: ../../library/datetime.rst:2397 msgid "" "The :mod:`!datetime` module has a basic :class:`timezone` class (for " "handling arbitrary fixed offsets from UTC) and its :attr:`timezone.utc` " "attribute (a UTC :class:`!timezone` instance)." msgstr "" -#: ../../library/datetime.rst:2387 +#: ../../library/datetime.rst:2401 msgid "" "``zoneinfo`` brings the *IANA time zone database* (also known as the Olson " "database) to Python, and its usage is recommended." msgstr "" -#: ../../library/datetime.rst:2390 +#: ../../library/datetime.rst:2404 msgid "`IANA time zone database `_" msgstr "`IANA 時區資料庫 `_" -#: ../../library/datetime.rst:2391 +#: ../../library/datetime.rst:2405 msgid "" "The Time Zone Database (often called tz, tzdata or zoneinfo) contains code " "and data that represent the history of local time for many representative " @@ -3541,24 +3584,24 @@ msgid "" "saving rules." msgstr "" -#: ../../library/datetime.rst:2401 +#: ../../library/datetime.rst:2415 msgid ":class:`!timezone` objects" msgstr ":class:`!timezone` 物件" -#: ../../library/datetime.rst:2403 +#: ../../library/datetime.rst:2417 msgid "" "The :class:`timezone` class is a subclass of :class:`tzinfo`, each instance " "of which represents a time zone defined by a fixed offset from UTC." msgstr "" -#: ../../library/datetime.rst:2407 +#: ../../library/datetime.rst:2421 msgid "" "Objects of this class cannot be used to represent time zone information in " "the locations where different offsets are used in different days of the year " "or where historical changes have been made to civil time." msgstr "" -#: ../../library/datetime.rst:2414 +#: ../../library/datetime.rst:2428 msgid "" "The *offset* argument must be specified as a :class:`timedelta` object " "representing the difference between the local time and UTC. It must be " @@ -3566,25 +3609,25 @@ msgid "" "otherwise :exc:`ValueError` is raised." msgstr "" -#: ../../library/datetime.rst:2419 +#: ../../library/datetime.rst:2433 msgid "" "The *name* argument is optional. If specified it must be a string that will " "be used as the value returned by the :meth:`datetime.tzname` method." msgstr "" -#: ../../library/datetime.rst:2430 ../../library/datetime.rst:2442 +#: ../../library/datetime.rst:2444 ../../library/datetime.rst:2456 msgid "" "Return the fixed value specified when the :class:`timezone` instance is " "constructed." msgstr "" -#: ../../library/datetime.rst:2433 +#: ../../library/datetime.rst:2447 msgid "" "The *dt* argument is ignored. The return value is a :class:`timedelta` " "instance equal to the difference between the local time and UTC." msgstr "" -#: ../../library/datetime.rst:2445 +#: ../../library/datetime.rst:2459 msgid "" "If *name* is not provided in the constructor, the name returned by " "``tzname(dt)`` is generated from the value of the ``offset`` as follows. If " @@ -3593,108 +3636,110 @@ msgid "" "are two digits of ``offset.hours`` and ``offset.minutes`` respectively." msgstr "" -#: ../../library/datetime.rst:2451 +#: ../../library/datetime.rst:2465 msgid "" "Name generated from ``offset=timedelta(0)`` is now plain ``'UTC'``, not " "``'UTC+00:00'``." msgstr "" -#: ../../library/datetime.rst:2458 +#: ../../library/datetime.rst:2472 msgid "Always returns ``None``." msgstr "總是回傳 ``None``。" -#: ../../library/datetime.rst:2463 +#: ../../library/datetime.rst:2477 msgid "" "Return ``dt + offset``. The *dt* argument must be an aware :class:`." "datetime` instance, with ``tzinfo`` set to ``self``." msgstr "" -#: ../../library/datetime.rst:2471 +#: ../../library/datetime.rst:2485 msgid "The UTC time zone, ``timezone(timedelta(0))``." msgstr "UTC 時區,``timezone(timedelta(0))``。" -#: ../../library/datetime.rst:2480 +#: ../../library/datetime.rst:2494 msgid ":meth:`!strftime` and :meth:`!strptime` behavior" msgstr ":meth:`!strftime` 與 :meth:`!strptime` 的行為" -#: ../../library/datetime.rst:2482 +#: ../../library/datetime.rst:2496 msgid "" ":class:`date`, :class:`.datetime`, and :class:`.time` objects all support a " "``strftime(format)`` method, to create a string representing the time under " "the control of an explicit format string." msgstr "" -#: ../../library/datetime.rst:2486 +#: ../../library/datetime.rst:2500 msgid "" "Conversely, the :meth:`date.strptime`, :meth:`datetime.strptime` and :meth:" "`time.strptime` class methods create an object from a string representing " "the time and a corresponding format string." msgstr "" -#: ../../library/datetime.rst:2490 +#: ../../library/datetime.rst:2504 msgid "" "The table below provides a high-level comparison of :meth:`~.datetime." "strftime` versus :meth:`~.datetime.strptime`:" msgstr "" -#: ../../library/datetime.rst:2494 +#: ../../library/datetime.rst:2508 msgid "``strftime``" msgstr "``strftime``" -#: ../../library/datetime.rst:2494 +#: ../../library/datetime.rst:2508 msgid "``strptime``" msgstr "``strptime``" -#: ../../library/datetime.rst:2496 +#: ../../library/datetime.rst:2510 msgid "Usage" msgstr "用法" -#: ../../library/datetime.rst:2496 +#: ../../library/datetime.rst:2510 msgid "Convert object to a string according to a given format" msgstr "" -#: ../../library/datetime.rst:2496 +#: ../../library/datetime.rst:2510 msgid "Parse a string into an object given a corresponding format" msgstr "" -#: ../../library/datetime.rst:2498 +#: ../../library/datetime.rst:2512 msgid "Type of method" msgstr "" -#: ../../library/datetime.rst:2498 +#: ../../library/datetime.rst:2512 msgid "Instance method" msgstr "實例方法" -#: ../../library/datetime.rst:2498 +#: ../../library/datetime.rst:2512 msgid "Class method" msgstr "類別方法" -#: ../../library/datetime.rst:2500 +#: ../../library/datetime.rst:2514 msgid "Signature" msgstr "" -#: ../../library/datetime.rst:2500 +#: ../../library/datetime.rst:2514 msgid "``strftime(format)``" msgstr "``strftime(format)``" -#: ../../library/datetime.rst:2500 +#: ../../library/datetime.rst:2514 msgid "``strptime(date_string, format)``" msgstr "``strptime(date_string, format)``" -#: ../../library/datetime.rst:2507 +#: ../../library/datetime.rst:2521 msgid ":meth:`!strftime` and :meth:`!strptime` format codes" msgstr ":meth:`!strftime` 與 :meth:`!strptime` 格式碼" -#: ../../library/datetime.rst:2509 +#: ../../library/datetime.rst:2523 msgid "" "These methods accept format codes that can be used to parse and format " "dates::" msgstr "" -#: ../../library/datetime.rst:2511 +#: ../../library/datetime.rst:2525 +#, fuzzy msgid "" -">>> datetime.strptime('31/01/22 23:59:59.999999',\n" -"... '%d/%m/%y %H:%M:%S.%f')\n" +">>> import datetime as dt\n" +">>> dt.datetime.strptime('31/01/22 23:59:59.999999',\n" +"... '%d/%m/%y %H:%M:%S.%f')\n" "datetime.datetime(2022, 1, 31, 23, 59, 59, 999999)\n" ">>> _.strftime('%a %d %b %Y, %I:%M%p')\n" "'Mon 31 Jan 2022, 11:59PM'" @@ -3705,33 +3750,33 @@ msgstr "" ">>> _.strftime('%a %d %b %Y, %I:%M%p')\n" "'Mon 31 Jan 2022, 11:59PM'" -#: ../../library/datetime.rst:2517 +#: ../../library/datetime.rst:2532 msgid "" "The following is a list of all the format codes that the 1989 C standard " "requires, and these work on all platforms with a standard C implementation." msgstr "" -#: ../../library/datetime.rst:2521 ../../library/datetime.rst:2624 +#: ../../library/datetime.rst:2536 ../../library/datetime.rst:2639 msgid "Directive" msgstr "" -#: ../../library/datetime.rst:2521 ../../library/datetime.rst:2624 +#: ../../library/datetime.rst:2536 ../../library/datetime.rst:2639 msgid "Meaning" msgstr "含義" -#: ../../library/datetime.rst:2521 ../../library/datetime.rst:2624 +#: ../../library/datetime.rst:2536 ../../library/datetime.rst:2639 msgid "Example" msgstr "範例" -#: ../../library/datetime.rst:2521 ../../library/datetime.rst:2624 +#: ../../library/datetime.rst:2536 ../../library/datetime.rst:2639 msgid "Notes" msgstr "註解" -#: ../../library/datetime.rst:2523 +#: ../../library/datetime.rst:2538 msgid "``%a``" msgstr "``%a``" -#: ../../library/datetime.rst:2523 +#: ../../library/datetime.rst:2538 msgid "Weekday as locale's abbreviated name." msgstr "" @@ -3743,11 +3788,11 @@ msgstr "" msgid "So, Mo, ..., Sa (de_DE)" msgstr "" -#: ../../library/datetime.rst:2528 +#: ../../library/datetime.rst:2543 msgid "``%A``" msgstr "``%A``" -#: ../../library/datetime.rst:2528 +#: ../../library/datetime.rst:2543 msgid "Weekday as locale's full name." msgstr "" @@ -3759,42 +3804,42 @@ msgstr "" msgid "Sonntag, Montag, ..., Samstag (de_DE)" msgstr "" -#: ../../library/datetime.rst:2533 +#: ../../library/datetime.rst:2548 msgid "``%w``" msgstr "``%w``" -#: ../../library/datetime.rst:2533 +#: ../../library/datetime.rst:2548 msgid "Weekday as a decimal number, where 0 is Sunday and 6 is Saturday." msgstr "" -#: ../../library/datetime.rst:2533 +#: ../../library/datetime.rst:2548 msgid "0, 1, ..., 6" msgstr "0, 1, ..., 6" -#: ../../library/datetime.rst:2537 +#: ../../library/datetime.rst:2552 msgid "``%d``" msgstr "``%d``" -#: ../../library/datetime.rst:2537 +#: ../../library/datetime.rst:2552 msgid "Day of the month as a zero-padded decimal number." msgstr "" -#: ../../library/datetime.rst:2537 +#: ../../library/datetime.rst:2552 msgid "01, 02, ..., 31" msgstr "01, 02, ..., 31" -#: ../../library/datetime.rst:2537 ../../library/datetime.rst:2550 -#: ../../library/datetime.rst:2553 ../../library/datetime.rst:2559 -#: ../../library/datetime.rst:2562 ../../library/datetime.rst:2568 -#: ../../library/datetime.rst:2586 +#: ../../library/datetime.rst:2552 ../../library/datetime.rst:2565 +#: ../../library/datetime.rst:2568 ../../library/datetime.rst:2574 +#: ../../library/datetime.rst:2577 ../../library/datetime.rst:2583 +#: ../../library/datetime.rst:2601 msgid "\\(9)" msgstr "\\(9)" -#: ../../library/datetime.rst:2540 +#: ../../library/datetime.rst:2555 msgid "``%b``" msgstr "``%b``" -#: ../../library/datetime.rst:2540 +#: ../../library/datetime.rst:2555 msgid "Month as locale's abbreviated name." msgstr "" @@ -3806,11 +3851,11 @@ msgstr "" msgid "Jan, Feb, ..., Dez (de_DE)" msgstr "" -#: ../../library/datetime.rst:2545 +#: ../../library/datetime.rst:2560 msgid "``%B``" msgstr "``%B``" -#: ../../library/datetime.rst:2545 +#: ../../library/datetime.rst:2560 msgid "Month as locale's full name." msgstr "" @@ -3822,67 +3867,67 @@ msgstr "" msgid "Januar, Februar, ..., Dezember (de_DE)" msgstr "" -#: ../../library/datetime.rst:2550 +#: ../../library/datetime.rst:2565 msgid "``%m``" msgstr "``%m``" -#: ../../library/datetime.rst:2550 +#: ../../library/datetime.rst:2565 msgid "Month as a zero-padded decimal number." msgstr "以零填充的並以十進位數字表示的月份。" -#: ../../library/datetime.rst:2550 ../../library/datetime.rst:2562 +#: ../../library/datetime.rst:2565 ../../library/datetime.rst:2577 msgid "01, 02, ..., 12" msgstr "01, 02, ..., 12" -#: ../../library/datetime.rst:2553 +#: ../../library/datetime.rst:2568 msgid "``%y``" msgstr "``%y``" -#: ../../library/datetime.rst:2553 +#: ../../library/datetime.rst:2568 msgid "Year without century as a zero-padded decimal number." msgstr "" -#: ../../library/datetime.rst:2553 +#: ../../library/datetime.rst:2568 msgid "00, 01, ..., 99" msgstr "00, 01, ..., 99" -#: ../../library/datetime.rst:2556 +#: ../../library/datetime.rst:2571 msgid "``%Y``" msgstr "``%Y``" -#: ../../library/datetime.rst:2556 +#: ../../library/datetime.rst:2571 msgid "Year with century as a decimal number." msgstr "" -#: ../../library/datetime.rst:2556 ../../library/datetime.rst:2626 +#: ../../library/datetime.rst:2571 ../../library/datetime.rst:2641 msgid "0001, 0002, ..., 2013, 2014, ..., 9998, 9999" msgstr "0001, 0002, ..., 2013, 2014, ..., 9998, 9999" -#: ../../library/datetime.rst:2559 +#: ../../library/datetime.rst:2574 msgid "``%H``" msgstr "``%H``" -#: ../../library/datetime.rst:2559 +#: ../../library/datetime.rst:2574 msgid "Hour (24-hour clock) as a zero-padded decimal number." msgstr "" -#: ../../library/datetime.rst:2559 +#: ../../library/datetime.rst:2574 msgid "00, 01, ..., 23" msgstr "00, 01, ..., 23" -#: ../../library/datetime.rst:2562 +#: ../../library/datetime.rst:2577 msgid "``%I``" msgstr "``%I``" -#: ../../library/datetime.rst:2562 +#: ../../library/datetime.rst:2577 msgid "Hour (12-hour clock) as a zero-padded decimal number." msgstr "" -#: ../../library/datetime.rst:2565 +#: ../../library/datetime.rst:2580 msgid "``%p``" msgstr "``%p``" -#: ../../library/datetime.rst:2565 +#: ../../library/datetime.rst:2580 msgid "Locale's equivalent of either AM or PM." msgstr "" @@ -3894,128 +3939,128 @@ msgstr "AM, PM (en_US);" msgid "am, pm (de_DE)" msgstr "am, pm (de_DE)" -#: ../../library/datetime.rst:2565 +#: ../../library/datetime.rst:2580 msgid "\\(1), \\(3)" msgstr "\\(1), \\(3)" -#: ../../library/datetime.rst:2568 +#: ../../library/datetime.rst:2583 msgid "``%M``" msgstr "``%M``" -#: ../../library/datetime.rst:2568 +#: ../../library/datetime.rst:2583 msgid "Minute as a zero-padded decimal number." msgstr "" -#: ../../library/datetime.rst:2568 ../../library/datetime.rst:2571 +#: ../../library/datetime.rst:2583 ../../library/datetime.rst:2586 msgid "00, 01, ..., 59" msgstr "00, 01, ..., 59" -#: ../../library/datetime.rst:2571 +#: ../../library/datetime.rst:2586 msgid "``%S``" msgstr "``%S``" -#: ../../library/datetime.rst:2571 +#: ../../library/datetime.rst:2586 msgid "Second as a zero-padded decimal number." msgstr "" -#: ../../library/datetime.rst:2571 +#: ../../library/datetime.rst:2586 msgid "\\(4), \\(9)" msgstr "\\(4), \\(9)" -#: ../../library/datetime.rst:2574 +#: ../../library/datetime.rst:2589 msgid "``%f``" msgstr "``%f``" -#: ../../library/datetime.rst:2574 +#: ../../library/datetime.rst:2589 msgid "Microsecond as a decimal number, zero-padded to 6 digits." msgstr "" -#: ../../library/datetime.rst:2574 +#: ../../library/datetime.rst:2589 msgid "000000, 000001, ..., 999999" msgstr "000000, 000001, ..., 999999" -#: ../../library/datetime.rst:2574 +#: ../../library/datetime.rst:2589 msgid "\\(5)" msgstr "\\(5)" -#: ../../library/datetime.rst:2578 ../../library/datetime.rst:2776 +#: ../../library/datetime.rst:2593 ../../library/datetime.rst:2791 msgid "``%z``" msgstr "``%z``" -#: ../../library/datetime.rst:2578 +#: ../../library/datetime.rst:2593 msgid "" "UTC offset in the form ``±HHMM[SS[.ffffff]]`` (empty string if the object is " "naive)." msgstr "" -#: ../../library/datetime.rst:2578 +#: ../../library/datetime.rst:2593 msgid "(empty), +0000, -0400, +1030, +063415, -030712.345216" msgstr "" -#: ../../library/datetime.rst:2578 ../../library/datetime.rst:2583 -#: ../../library/datetime.rst:2640 +#: ../../library/datetime.rst:2593 ../../library/datetime.rst:2598 +#: ../../library/datetime.rst:2655 msgid "\\(6)" msgstr "\\(6)" -#: ../../library/datetime.rst:2583 ../../library/datetime.rst:2802 +#: ../../library/datetime.rst:2598 ../../library/datetime.rst:2817 msgid "``%Z``" msgstr "``%Z``" -#: ../../library/datetime.rst:2583 +#: ../../library/datetime.rst:2598 msgid "Time zone name (empty string if the object is naive)." msgstr "" -#: ../../library/datetime.rst:2583 +#: ../../library/datetime.rst:2598 msgid "(empty), UTC, GMT" msgstr "" -#: ../../library/datetime.rst:2586 +#: ../../library/datetime.rst:2601 msgid "``%j``" msgstr "``%j``" -#: ../../library/datetime.rst:2586 +#: ../../library/datetime.rst:2601 msgid "Day of the year as a zero-padded decimal number." msgstr "" -#: ../../library/datetime.rst:2586 +#: ../../library/datetime.rst:2601 msgid "001, 002, ..., 366" msgstr "001, 002, ..., 366" -#: ../../library/datetime.rst:2589 +#: ../../library/datetime.rst:2604 msgid "``%U``" msgstr "``%U``" -#: ../../library/datetime.rst:2589 +#: ../../library/datetime.rst:2604 msgid "" "Week number of the year (Sunday as the first day of the week) as a zero-" "padded decimal number. All days in a new year preceding the first Sunday are " "considered to be in week 0." msgstr "" -#: ../../library/datetime.rst:2589 ../../library/datetime.rst:2597 +#: ../../library/datetime.rst:2604 ../../library/datetime.rst:2612 msgid "00, 01, ..., 53" msgstr "00, 01, ..., 53" -#: ../../library/datetime.rst:2589 ../../library/datetime.rst:2597 +#: ../../library/datetime.rst:2604 ../../library/datetime.rst:2612 msgid "\\(7), \\(9)" msgstr "\\(7), \\(9)" -#: ../../library/datetime.rst:2597 +#: ../../library/datetime.rst:2612 msgid "``%W``" msgstr "``%W``" -#: ../../library/datetime.rst:2597 +#: ../../library/datetime.rst:2612 msgid "" "Week number of the year (Monday as the first day of the week) as a zero-" "padded decimal number. All days in a new year preceding the first Monday are " "considered to be in week 0." msgstr "" -#: ../../library/datetime.rst:2605 +#: ../../library/datetime.rst:2620 msgid "``%c``" msgstr "``%c``" -#: ../../library/datetime.rst:2605 +#: ../../library/datetime.rst:2620 msgid "Locale's appropriate date and time representation." msgstr "" @@ -4027,11 +4072,11 @@ msgstr "" msgid "Di 16 Aug 21:30:00 1988 (de_DE)" msgstr "" -#: ../../library/datetime.rst:2610 +#: ../../library/datetime.rst:2625 msgid "``%x``" msgstr "``%x``" -#: ../../library/datetime.rst:2610 +#: ../../library/datetime.rst:2625 msgid "Locale's appropriate date representation." msgstr "" @@ -4047,11 +4092,11 @@ msgstr "" msgid "16.08.1988 (de_DE)" msgstr "" -#: ../../library/datetime.rst:2614 +#: ../../library/datetime.rst:2629 msgid "``%X``" msgstr "``%X``" -#: ../../library/datetime.rst:2614 +#: ../../library/datetime.rst:2629 msgid "Locale's appropriate time representation." msgstr "" @@ -4063,83 +4108,83 @@ msgstr "" msgid "21:30:00 (de_DE)" msgstr "" -#: ../../library/datetime.rst:2617 +#: ../../library/datetime.rst:2632 msgid "``%%``" msgstr "``%%``" -#: ../../library/datetime.rst:2617 +#: ../../library/datetime.rst:2632 msgid "A literal ``'%'`` character." msgstr "" -#: ../../library/datetime.rst:2617 +#: ../../library/datetime.rst:2632 msgid "%" msgstr "%" -#: ../../library/datetime.rst:2620 +#: ../../library/datetime.rst:2635 msgid "" "Several additional directives not required by the C89 standard are included " "for convenience. These parameters all correspond to ISO 8601 date values." msgstr "" -#: ../../library/datetime.rst:2626 +#: ../../library/datetime.rst:2641 msgid "``%G``" msgstr "``%G``" -#: ../../library/datetime.rst:2626 +#: ../../library/datetime.rst:2641 msgid "" "ISO 8601 year with century representing the year that contains the greater " "part of the ISO week (``%V``)." msgstr "" -#: ../../library/datetime.rst:2626 +#: ../../library/datetime.rst:2641 msgid "\\(8)" msgstr "\\(8)" -#: ../../library/datetime.rst:2631 +#: ../../library/datetime.rst:2646 msgid "``%u``" msgstr "``%u``" -#: ../../library/datetime.rst:2631 +#: ../../library/datetime.rst:2646 msgid "ISO 8601 weekday as a decimal number where 1 is Monday." msgstr "" -#: ../../library/datetime.rst:2631 +#: ../../library/datetime.rst:2646 msgid "1, 2, ..., 7" msgstr "1, 2, ..., 7" -#: ../../library/datetime.rst:2634 +#: ../../library/datetime.rst:2649 msgid "``%V``" msgstr "``%V``" -#: ../../library/datetime.rst:2634 +#: ../../library/datetime.rst:2649 msgid "" "ISO 8601 week as a decimal number with Monday as the first day of the week. " "Week 01 is the week containing Jan 4." msgstr "" -#: ../../library/datetime.rst:2634 +#: ../../library/datetime.rst:2649 msgid "01, 02, ..., 53" msgstr "01, 02, ..., 53" -#: ../../library/datetime.rst:2634 +#: ../../library/datetime.rst:2649 msgid "\\(8), \\(9)" msgstr "\\(8), \\(9)" -#: ../../library/datetime.rst:2640 ../../library/datetime.rst:2798 +#: ../../library/datetime.rst:2655 ../../library/datetime.rst:2813 msgid "``%:z``" msgstr "``%:z``" -#: ../../library/datetime.rst:2640 +#: ../../library/datetime.rst:2655 msgid "" "UTC offset in the form ``±HH:MM[:SS[.ffffff]]`` (empty string if the object " "is naive)." msgstr "" -#: ../../library/datetime.rst:2640 +#: ../../library/datetime.rst:2655 msgid "(empty), +00:00, -04:00, +10:30, +06:34:15, -03:07:12.345216" msgstr "" -#: ../../library/datetime.rst:2646 +#: ../../library/datetime.rst:2661 msgid "" "These may not be available on all platforms when used with the :meth:`~." "datetime.strftime` method. The ISO 8601 year and ISO 8601 week directives " @@ -4148,7 +4193,7 @@ msgid "" "directives will raise a :exc:`ValueError`." msgstr "" -#: ../../library/datetime.rst:2651 +#: ../../library/datetime.rst:2666 msgid "" "The full set of format codes supported varies across platforms, because " "Python calls the platform C library's :c:func:`strftime` function, and " @@ -4158,33 +4203,33 @@ msgid "" "unsupported format specifiers." msgstr "" -#: ../../library/datetime.rst:2657 +#: ../../library/datetime.rst:2672 msgid "``%G``, ``%u`` and ``%V`` were added." msgstr "新增 ``%G``、``%u`` 與 ``%V``。" -#: ../../library/datetime.rst:2660 +#: ../../library/datetime.rst:2675 msgid "``%:z`` was added." msgstr "新增 ``%:z``。" -#: ../../library/datetime.rst:2665 +#: ../../library/datetime.rst:2680 msgid "Technical detail" msgstr "技術細節" -#: ../../library/datetime.rst:2667 +#: ../../library/datetime.rst:2682 msgid "" "Broadly speaking, ``d.strftime(fmt)`` acts like the :mod:`time` module's " "``time.strftime(fmt, d.timetuple())`` although not all objects support a :" "meth:`~date.timetuple` method." msgstr "" -#: ../../library/datetime.rst:2671 +#: ../../library/datetime.rst:2686 msgid "" "For the :meth:`.datetime.strptime` and :meth:`.date.strptime` class methods, " "the default value is ``1900-01-01T00:00:00.000``: any components not " "specified in the format string will be pulled from the default value." msgstr "" -#: ../../library/datetime.rst:2676 +#: ../../library/datetime.rst:2691 msgid "" "Format strings without separators can be ambiguous for parsing. For example, " "with ``%Y%m%d``, the string ``2026111`` may be parsed either as " @@ -4192,7 +4237,7 @@ msgid "" "parsed as intended." msgstr "" -#: ../../library/datetime.rst:2682 +#: ../../library/datetime.rst:2697 msgid "" "When used to parse partial dates lacking a year, :meth:`.datetime.strptime` " "and :meth:`.date.strptime` will raise when encountering February 29 because " @@ -4200,30 +4245,30 @@ msgid "" "year to partial date strings before parsing." msgstr "" -#: ../../library/datetime.rst:2702 +#: ../../library/datetime.rst:2717 msgid "" -">>> from datetime import datetime\n" +">>> import datetime as dt\n" ">>> value = \"2/29\"\n" -">>> datetime.strptime(value, \"%m/%d\")\n" +">>> dt.datetime.strptime(value, \"%m/%d\")\n" "Traceback (most recent call last):\n" "...\n" "ValueError: day 29 must be in range 1..28 for month 2 in year 1900\n" -">>> datetime.strptime(f\"1904 {value}\", \"%Y %m/%d\")\n" +">>> dt.datetime.strptime(f\"1904 {value}\", \"%Y %m/%d\")\n" "datetime.datetime(1904, 2, 29, 0, 0)" msgstr "" -#: ../../library/datetime.rst:2713 +#: ../../library/datetime.rst:2728 msgid "Using ``datetime.strptime(date_string, format)`` is equivalent to::" msgstr "" -#: ../../library/datetime.rst:2717 +#: ../../library/datetime.rst:2732 msgid "" "except when the format includes sub-second components or time zone offset " "information, which are supported in ``datetime.strptime`` but are discarded " "by ``time.strptime``." msgstr "" -#: ../../library/datetime.rst:2721 +#: ../../library/datetime.rst:2736 msgid "" "For :class:`.time` objects, the format codes for year, month, and day should " "not be used, as :class:`!time` objects have no such values. If they're used " @@ -4233,7 +4278,7 @@ msgstr "" "time` 物件並沒有這些值。如果使用這些格式碼,年份會以 1900 代替、月及日會以 1 " "代替。" -#: ../../library/datetime.rst:2725 +#: ../../library/datetime.rst:2740 msgid "" "For :class:`date` objects, the format codes for hours, minutes, seconds, and " "microseconds should not be used, as :class:`date` objects have no such " @@ -4242,7 +4287,7 @@ msgstr "" "對 :class:`.date` 物件來說,不應該使用時、分、秒、微秒的格式碼,因為 :class:" "`date` 物件並沒有這些值。如果使用這些格式碼,這些值都會以 0 代替。" -#: ../../library/datetime.rst:2729 +#: ../../library/datetime.rst:2744 msgid "" "For the same reason, handling of format strings containing Unicode code " "points that can't be represented in the charset of the current locale is " @@ -4251,7 +4296,7 @@ msgid "" "`UnicodeError` or return an empty string instead." msgstr "" -#: ../../library/datetime.rst:2738 +#: ../../library/datetime.rst:2753 msgid "" "Because the format depends on the current locale, care should be taken when " "making assumptions about the output value. Field orderings will vary (for " @@ -4259,38 +4304,38 @@ msgid "" "contain non-ASCII characters." msgstr "" -#: ../../library/datetime.rst:2744 +#: ../../library/datetime.rst:2759 msgid "" "The :meth:`~.datetime.strptime` method can parse years in the full [1, 9999] " "range, but years < 1000 must be zero-filled to 4-digit width." msgstr "" -#: ../../library/datetime.rst:2747 +#: ../../library/datetime.rst:2762 msgid "" "In previous versions, :meth:`~.datetime.strftime` method was restricted to " "years >= 1900." msgstr "" -#: ../../library/datetime.rst:2751 +#: ../../library/datetime.rst:2766 msgid "" "In version 3.2, :meth:`~.datetime.strftime` method was restricted to years " ">= 1000." msgstr "" -#: ../../library/datetime.rst:2756 +#: ../../library/datetime.rst:2771 msgid "" "When used with the :meth:`~.datetime.strptime` method, the ``%p`` directive " "only affects the output hour field if the ``%I`` directive is used to parse " "the hour." msgstr "" -#: ../../library/datetime.rst:2760 +#: ../../library/datetime.rst:2775 msgid "" "Unlike the :mod:`time` module, the :mod:`!datetime` module does not support " "leap seconds." msgstr "" -#: ../../library/datetime.rst:2764 +#: ../../library/datetime.rst:2779 msgid "" "When used with the :meth:`~.datetime.strptime` method, the ``%f`` directive " "accepts from one to six digits and zero pads on the right. ``%f`` is an " @@ -4298,17 +4343,17 @@ msgid "" "separately in datetime objects, and therefore always available)." msgstr "" -#: ../../library/datetime.rst:2771 +#: ../../library/datetime.rst:2786 msgid "" "For a naive object, the ``%z``, ``%:z`` and ``%Z`` format codes are replaced " "by empty strings." msgstr "" -#: ../../library/datetime.rst:2774 +#: ../../library/datetime.rst:2789 msgid "For an aware object:" msgstr "" -#: ../../library/datetime.rst:2777 +#: ../../library/datetime.rst:2792 msgid "" ":meth:`~.datetime.utcoffset` is transformed into a string of the form " "``±HHMM[SS[.ffffff]]``, where ``HH`` is a 2-digit string giving the number " @@ -4322,7 +4367,7 @@ msgid "" "replaced with the string ``'-0330'``." msgstr "" -#: ../../library/datetime.rst:2791 +#: ../../library/datetime.rst:2806 msgid "" "When the ``%z`` directive is provided to the :meth:`~.datetime.strptime` " "method, the UTC offsets can have a colon as a separator between hours, " @@ -4331,53 +4376,53 @@ msgid "" "``'+00:00'``." msgstr "" -#: ../../library/datetime.rst:2799 +#: ../../library/datetime.rst:2814 msgid "" "Behaves exactly as ``%z``, but has a colon separator added between hours, " "minutes and seconds." msgstr "" -#: ../../library/datetime.rst:2803 +#: ../../library/datetime.rst:2818 msgid "" "In :meth:`~.datetime.strftime`, ``%Z`` is replaced by an empty string if :" "meth:`~.datetime.tzname` returns ``None``; otherwise ``%Z`` is replaced by " "the returned value, which must be a string." msgstr "" -#: ../../library/datetime.rst:2807 +#: ../../library/datetime.rst:2822 msgid ":meth:`~.datetime.strptime` only accepts certain values for ``%Z``:" msgstr "" -#: ../../library/datetime.rst:2809 +#: ../../library/datetime.rst:2824 msgid "any value in ``time.tzname`` for your machine's locale" msgstr "" -#: ../../library/datetime.rst:2810 +#: ../../library/datetime.rst:2825 msgid "the hard-coded values ``UTC`` and ``GMT``" msgstr "" -#: ../../library/datetime.rst:2812 +#: ../../library/datetime.rst:2827 msgid "" "So someone living in Japan may have ``JST``, ``UTC``, and ``GMT`` as valid " "values, but probably not ``EST``. It will raise ``ValueError`` for invalid " "values." msgstr "" -#: ../../library/datetime.rst:2816 +#: ../../library/datetime.rst:2831 msgid "" "When the ``%z`` directive is provided to the :meth:`~.datetime.strptime` " "method, an aware :class:`.datetime` object will be produced. The ``tzinfo`` " "of the result will be set to a :class:`timezone` instance." msgstr "" -#: ../../library/datetime.rst:2822 +#: ../../library/datetime.rst:2837 msgid "" "When used with the :meth:`~.datetime.strptime` method, ``%U`` and ``%W`` are " "only used in calculations when the day of the week and the calendar year " "(``%Y``) are specified." msgstr "" -#: ../../library/datetime.rst:2827 +#: ../../library/datetime.rst:2842 msgid "" "Similar to ``%U`` and ``%W``, ``%V`` is only used in calculations when the " "day of the week and the ISO year (``%G``) are specified in a :meth:`~." @@ -4385,7 +4430,7 @@ msgid "" "interchangeable." msgstr "" -#: ../../library/datetime.rst:2833 +#: ../../library/datetime.rst:2848 msgid "" "When used with the :meth:`~.datetime.strptime` method, the leading zero is " "optional for formats ``%d``, ``%m``, ``%H``, ``%I``, ``%M``, ``%S``, " @@ -4393,7 +4438,7 @@ msgid "" "zero." msgstr "" -#: ../../library/datetime.rst:2838 +#: ../../library/datetime.rst:2853 msgid "" "When parsing a month and day using :meth:`~.datetime.strptime`, always " "include a year in the format. If the value you need to parse lacks a year, " @@ -4402,11 +4447,12 @@ msgid "" "parser (1900) is not a leap year. Users run into that bug every leap year." msgstr "" -#: ../../library/datetime.rst:2844 +#: ../../library/datetime.rst:2859 +#, fuzzy msgid "" ">>> month_day = \"02/29\"\n" -">>> datetime.strptime(f\"{month_day};1984\", \"%m/%d;%Y\") # No leap year " -"bug.\n" +">>> dt.datetime.strptime(f\"{month_day};1984\", \"%m/%d;%Y\") # No leap " +"year bug.\n" "datetime.datetime(1984, 2, 29, 0, 0)" msgstr "" ">>> month_day = \"02/29\"\n" @@ -4414,7 +4460,7 @@ msgstr "" "題。\n" "datetime.datetime(1984, 2, 29, 0, 0)" -#: ../../library/datetime.rst:2850 +#: ../../library/datetime.rst:2865 msgid "" ":meth:`~.datetime.strptime` calls using a format string containing a day of " "month without a year now emit a :exc:`DeprecationWarning`. In 3.15 or later " @@ -4422,15 +4468,16 @@ msgid "" "See :gh:`70647`." msgstr "" -#: ../../library/datetime.rst:2857 +#: ../../library/datetime.rst:2872 msgid "Footnotes" msgstr "註解" -#: ../../library/datetime.rst:2858 -msgid "If, that is, we ignore the effects of Relativity" +#: ../../library/datetime.rst:2873 +#, fuzzy +msgid "If, that is, we ignore the effects of relativity." msgstr "也就是說,我們會忽略相對論的效應" -#: ../../library/datetime.rst:2860 +#: ../../library/datetime.rst:2875 msgid "" "This matches the definition of the \"proleptic Gregorian\" calendar in " "Dershowitz and Reingold's book *Calendrical Calculations*, where it's the " @@ -4439,21 +4486,44 @@ msgid "" "systems." msgstr "" -#: ../../library/datetime.rst:2866 +#: ../../library/datetime.rst:2881 msgid "" "See R. H. van Gent's `guide to the mathematics of the ISO 8601 calendar " "`_ for a good explanation." msgstr "" -#: ../../library/datetime.rst:2474 +#: ../../library/datetime.rst:2488 msgid "% (percent)" msgstr "% (百分號)" -#: ../../library/datetime.rst:2474 +#: ../../library/datetime.rst:2488 msgid "datetime format" msgstr "datetime format(日期時間格式)" +#~ msgid "" +#~ ">>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc)\n" +#~ ">>> for i in range(4):\n" +#~ "... u = u0 + i*HOUR\n" +#~ "... t = u.astimezone(Eastern)\n" +#~ "... print(u.time(), 'UTC =', t.time(), t.tzname(), t.fold)\n" +#~ "...\n" +#~ "04:00:00 UTC = 00:00:00 EDT 0\n" +#~ "05:00:00 UTC = 01:00:00 EDT 0\n" +#~ "06:00:00 UTC = 01:00:00 EST 1\n" +#~ "07:00:00 UTC = 02:00:00 EST 0" +#~ msgstr "" +#~ ">>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc)\n" +#~ ">>> for i in range(4):\n" +#~ "... u = u0 + i*HOUR\n" +#~ "... t = u.astimezone(Eastern)\n" +#~ "... print(u.time(), 'UTC =', t.time(), t.tzname(), t.fold)\n" +#~ "...\n" +#~ "04:00:00 UTC = 00:00:00 EDT 0\n" +#~ "05:00:00 UTC = 01:00:00 EDT 0\n" +#~ "06:00:00 UTC = 01:00:00 EST 1\n" +#~ "07:00:00 UTC = 02:00:00 EST 0" + #~ msgid "" #~ "object\n" #~ " timedelta\n" diff --git a/library/functools.po b/library/functools.po index b59ea21c11c..bedfd9ff8df 100644 --- a/library/functools.po +++ b/library/functools.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-07 00:19+0000\n" +"POT-Creation-Date: 2026-03-08 00:18+0000\n" "PO-Revision-Date: 2024-05-11 16:02+0800\n" "Last-Translator: Matt Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -34,8 +34,8 @@ msgid "" "act on or return other functions. In general, any callable object can be " "treated as a function for the purposes of this module." msgstr "" -":mod:`!functools` 模組用於高階函式:作用於或回傳其他函式的函式。一般來說,任何" -"可呼叫物件都可以被視為用於此模組的函式。" +":mod:`!functools` 模組用於高階函式:作用於或回傳其他函式的函式。一般來說,任" +"何可呼叫物件都可以被視為用於此模組的函式。" #: ../../library/functools.rst:27 msgid "The :mod:`!functools` module defines the following functions:" @@ -337,10 +337,11 @@ msgstr "" "如 *str* 和 *int* 可能會被單獨快取起來,即使 *typed* 為 false。)" #: ../../library/functools.rst:191 +#, fuzzy msgid "" "Note, type specificity applies only to the function's immediate arguments " "rather than their contents. The scalar arguments, ``Decimal(42)`` and " -"``Fraction(42)`` are be treated as distinct calls with distinct results. In " +"``Fraction(42)`` are treated as distinct calls with distinct results. In " "contrast, the tuple arguments ``('answer', Decimal(42))`` and ``('answer', " "Fraction(42))`` are treated as equivalent." msgstr "" diff --git a/library/stdtypes.po b/library/stdtypes.po index 0d51b5d38ea..bdc66588d4d 100644 --- a/library/stdtypes.po +++ b/library/stdtypes.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-26 00:17+0000\n" +"POT-Creation-Date: 2026-03-11 00:16+0000\n" "PO-Revision-Date: 2022-06-12 15:22+0800\n" "Last-Translator: Matt Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -139,8 +139,8 @@ msgstr "結果" #: ../../library/stdtypes.rst:88 ../../library/stdtypes.rst:292 #: ../../library/stdtypes.rst:432 ../../library/stdtypes.rst:1015 -#: ../../library/stdtypes.rst:1237 ../../library/stdtypes.rst:3113 -#: ../../library/stdtypes.rst:4373 +#: ../../library/stdtypes.rst:1237 ../../library/stdtypes.rst:3147 +#: ../../library/stdtypes.rst:4407 msgid "Notes" msgstr "註解" @@ -154,7 +154,7 @@ msgstr "假如 *x* 為真,則 *x*,否則 *y*" #: ../../library/stdtypes.rst:90 ../../library/stdtypes.rst:1017 #: ../../library/stdtypes.rst:1020 ../../library/stdtypes.rst:1252 -#: ../../library/stdtypes.rst:3119 ../../library/stdtypes.rst:4379 +#: ../../library/stdtypes.rst:3153 ../../library/stdtypes.rst:4413 msgid "\\(1)" msgstr "\\(1)" @@ -168,8 +168,8 @@ msgstr "假如 *x* 為假,則 *x*,否則 *y*" #: ../../library/stdtypes.rst:93 ../../library/stdtypes.rst:305 #: ../../library/stdtypes.rst:325 ../../library/stdtypes.rst:1263 -#: ../../library/stdtypes.rst:3123 ../../library/stdtypes.rst:3125 -#: ../../library/stdtypes.rst:4383 ../../library/stdtypes.rst:4385 +#: ../../library/stdtypes.rst:3157 ../../library/stdtypes.rst:3159 +#: ../../library/stdtypes.rst:4417 ../../library/stdtypes.rst:4419 msgid "\\(2)" msgstr "\\(2)" @@ -181,18 +181,18 @@ msgstr "``not x``" msgid "if *x* is false, then ``True``, else ``False``" msgstr "假如 *x* 為假,則 ``True``,否則 ``False``" -#: ../../library/stdtypes.rst:96 ../../library/stdtypes.rst:3127 -#: ../../library/stdtypes.rst:3129 ../../library/stdtypes.rst:3131 -#: ../../library/stdtypes.rst:3133 ../../library/stdtypes.rst:4387 -#: ../../library/stdtypes.rst:4389 ../../library/stdtypes.rst:4391 -#: ../../library/stdtypes.rst:4393 +#: ../../library/stdtypes.rst:96 ../../library/stdtypes.rst:3161 +#: ../../library/stdtypes.rst:3163 ../../library/stdtypes.rst:3165 +#: ../../library/stdtypes.rst:3167 ../../library/stdtypes.rst:4421 +#: ../../library/stdtypes.rst:4423 ../../library/stdtypes.rst:4425 +#: ../../library/stdtypes.rst:4427 msgid "\\(3)" msgstr "\\(3)" #: ../../library/stdtypes.rst:105 ../../library/stdtypes.rst:336 #: ../../library/stdtypes.rst:450 ../../library/stdtypes.rst:1059 -#: ../../library/stdtypes.rst:1267 ../../library/stdtypes.rst:3159 -#: ../../library/stdtypes.rst:4423 +#: ../../library/stdtypes.rst:1267 ../../library/stdtypes.rst:3193 +#: ../../library/stdtypes.rst:4457 msgid "Notes:" msgstr "註解:" @@ -239,9 +239,9 @@ msgstr "" msgid "This table summarizes the comparison operations:" msgstr "這個表格統整所有比較運算:" -#: ../../library/stdtypes.rst:146 ../../library/stdtypes.rst:3090 -#: ../../library/stdtypes.rst:3113 ../../library/stdtypes.rst:4350 -#: ../../library/stdtypes.rst:4373 +#: ../../library/stdtypes.rst:146 ../../library/stdtypes.rst:3124 +#: ../../library/stdtypes.rst:3147 ../../library/stdtypes.rst:4384 +#: ../../library/stdtypes.rst:4407 msgid "Meaning" msgstr "含義" @@ -420,8 +420,8 @@ msgid "" "has operands of different built-in numeric types, the operand with the " "\"narrower\" type is widened to that of the other:" msgstr "" -"Python 完全支援混和運算:當一個二元運算子的運算元有不同內建數值型別時,「較窄」型" -"別的運算元會被拓寬到另一個型別的運算元:" +"Python 完全支援混和運算:當一個二元運算子的運算元有不同內建數值型別時,「較" +"窄」型別的運算元會被拓寬到另一個型別的運算元:" #: ../../library/stdtypes.rst:274 msgid "If both arguments are complex numbers, no conversion is performed;" @@ -591,8 +591,8 @@ msgid "" "zero." msgstr "一個複數,其實部為 *re*,虛部為 *im*。*im* 預設為零。" -#: ../../library/stdtypes.rst:318 ../../library/stdtypes.rst:3121 -#: ../../library/stdtypes.rst:4410 +#: ../../library/stdtypes.rst:318 ../../library/stdtypes.rst:3155 +#: ../../library/stdtypes.rst:4444 msgid "\\(6)" msgstr "\\(6)" @@ -629,9 +629,9 @@ msgid "*x* to the power *y*" msgstr "*x* 的 *y* 次方" #: ../../library/stdtypes.rst:327 ../../library/stdtypes.rst:329 -#: ../../library/stdtypes.rst:3146 ../../library/stdtypes.rst:3149 -#: ../../library/stdtypes.rst:3152 ../../library/stdtypes.rst:4406 -#: ../../library/stdtypes.rst:4413 +#: ../../library/stdtypes.rst:3180 ../../library/stdtypes.rst:3183 +#: ../../library/stdtypes.rst:3186 ../../library/stdtypes.rst:4440 +#: ../../library/stdtypes.rst:4447 msgid "\\(5)" msgstr "\\(5)" @@ -789,9 +789,9 @@ msgid "bitwise :dfn:`or` of *x* and *y*" msgstr "*x* 及 *y* 的位元 :dfn:`或`" #: ../../library/stdtypes.rst:434 ../../library/stdtypes.rst:437 -#: ../../library/stdtypes.rst:440 ../../library/stdtypes.rst:3135 -#: ../../library/stdtypes.rst:3139 ../../library/stdtypes.rst:4395 -#: ../../library/stdtypes.rst:4399 +#: ../../library/stdtypes.rst:440 ../../library/stdtypes.rst:3169 +#: ../../library/stdtypes.rst:3173 ../../library/stdtypes.rst:4429 +#: ../../library/stdtypes.rst:4433 msgid "\\(4)" msgstr "\\(4)" @@ -3141,7 +3141,7 @@ msgstr "" msgid "Return the string encoded to :class:`bytes`." msgstr "" -#: ../../library/stdtypes.rst:1917 ../../library/stdtypes.rst:3549 +#: ../../library/stdtypes.rst:1917 ../../library/stdtypes.rst:3583 msgid "" "*encoding* defaults to ``'utf-8'``; see :ref:`standard-encodings` for " "possible values." @@ -3177,11 +3177,11 @@ msgstr "" ">>> encoded_str_to_bytes\n" "b'Python'" -#: ../../library/stdtypes.rst:1940 ../../library/stdtypes.rst:3568 +#: ../../library/stdtypes.rst:1940 ../../library/stdtypes.rst:3602 msgid "Added support for keyword arguments." msgstr "新增關鍵字引數的支援。" -#: ../../library/stdtypes.rst:1943 ../../library/stdtypes.rst:3571 +#: ../../library/stdtypes.rst:1943 ../../library/stdtypes.rst:3605 msgid "" "The value of the *errors* argument is now checked in :ref:`devmode` and in :" "ref:`debug mode `." @@ -3378,12 +3378,25 @@ msgid "" "Return ``True`` if all characters in the string are alphanumeric and there " "is at least one character, ``False`` otherwise. A character ``c`` is " "alphanumeric if one of the following returns ``True``: ``c.isalpha()``, ``c." -"isdecimal()``, ``c.isdigit()``, or ``c.isnumeric()``. For example::" +"isdecimal()``, ``c.isdigit()``, or ``c.isnumeric()``. For example:" msgstr "" #: ../../library/stdtypes.rst:2095 -msgid ".. doctest::" +#, fuzzy +msgid "" +">>> 'abc123'.isalnum()\n" +"True\n" +">>> 'abc123!@#'.isalnum()\n" +"False\n" +">>> ''.isalnum()\n" +"False\n" +">>> ' '.isalnum()\n" +"False" msgstr "" +">>> b'ABCabc1'.isalnum()\n" +"True\n" +">>> b'ABC abc1'.isalnum()\n" +"False" #: ../../library/stdtypes.rst:2109 msgid "" @@ -3570,10 +3583,12 @@ msgid "" "C), except the ASCII space." msgstr "" -#: ../../library/stdtypes.rst:2241 ../../library/stdtypes.rst:2268 -#: ../../library/stdtypes.rst:2323 ../../library/stdtypes.rst:2396 -#: ../../library/stdtypes.rst:2515 ../../library/stdtypes.rst:2694 -#: ../../library/stdtypes.rst:2716 ../../library/stdtypes.rst:2730 +#: ../../library/stdtypes.rst:2241 ../../library/stdtypes.rst:2258 +#: ../../library/stdtypes.rst:2285 ../../library/stdtypes.rst:2340 +#: ../../library/stdtypes.rst:2413 ../../library/stdtypes.rst:2524 +#: ../../library/stdtypes.rst:2545 ../../library/stdtypes.rst:2724 +#: ../../library/stdtypes.rst:2746 ../../library/stdtypes.rst:2760 +#: ../../library/stdtypes.rst:2853 msgid "For example:" msgstr "舉例來說:" @@ -3589,20 +3604,42 @@ msgstr "" ">>> '\\t'.isprintable(), '\\n'.isprintable()\n" "(False, False)" -#: ../../library/stdtypes.rst:2253 +#: ../../library/stdtypes.rst:2250 +#, fuzzy +msgid "See also :meth:`isspace`." +msgstr "另請參閱 :meth:`istitle`。" + +#: ../../library/stdtypes.rst:2255 msgid "" "Return ``True`` if there are only whitespace characters in the string and " "there is at least one character, ``False`` otherwise." msgstr "" -#: ../../library/stdtypes.rst:2256 +#: ../../library/stdtypes.rst:2260 +msgid "" +">>> ''.isspace()\n" +"False\n" +">>> ' '.isspace()\n" +"True\n" +">>> '\\t\\n'.isspace() # TAB and BREAK LINE\n" +"True\n" +">>> '\\u3000'.isspace() # IDEOGRAPHIC SPACE\n" +"True" +msgstr "" + +#: ../../library/stdtypes.rst:2271 msgid "" "A character is *whitespace* if in the Unicode character database (see :mod:" "`unicodedata`), either its general category is ``Zs`` (\"Separator, " "space\"), or its bidirectional class is one of ``WS``, ``B``, or ``S``." msgstr "" -#: ../../library/stdtypes.rst:2264 +#: ../../library/stdtypes.rst:2276 +#, fuzzy +msgid "See also :meth:`isprintable`." +msgstr "另請參閱 :meth:`istitle`。" + +#: ../../library/stdtypes.rst:2281 msgid "" "Return ``True`` if the string is a titlecased string and there is at least " "one character, for example uppercase characters may only follow uncased " @@ -3610,7 +3647,7 @@ msgid "" "otherwise." msgstr "" -#: ../../library/stdtypes.rst:2270 +#: ../../library/stdtypes.rst:2287 msgid "" ">>> 'Spam, Spam, Spam'.istitle()\n" "True\n" @@ -3626,17 +3663,17 @@ msgstr "" ">>> 'SPAM, SPAM, SPAM'.istitle()\n" "False" -#: ../../library/stdtypes.rst:2279 +#: ../../library/stdtypes.rst:2296 msgid "See also :meth:`title`." msgstr "另請參閱 :meth:`title`。" -#: ../../library/stdtypes.rst:2284 +#: ../../library/stdtypes.rst:2301 msgid "" "Return ``True`` if all cased characters [4]_ in the string are uppercase and " "there is at least one cased character, ``False`` otherwise." msgstr "" -#: ../../library/stdtypes.rst:2302 +#: ../../library/stdtypes.rst:2319 msgid "" "Return a string which is the concatenation of the strings in *iterable*. A :" "exc:`TypeError` will be raised if there are any non-string values in " @@ -3644,7 +3681,7 @@ msgid "" "elements is the string providing this method. For example:" msgstr "" -#: ../../library/stdtypes.rst:2307 +#: ../../library/stdtypes.rst:2324 msgid "" ">>> ', '.join(['spam', 'spam', 'spam'])\n" "'spam, spam, spam'\n" @@ -3656,18 +3693,18 @@ msgstr "" ">>> '-'.join('Python')\n" "'P-y-t-h-o-n'" -#: ../../library/stdtypes.rst:2314 +#: ../../library/stdtypes.rst:2331 msgid "See also :meth:`split`." msgstr "另請參閱 :meth:`split`。" -#: ../../library/stdtypes.rst:2319 +#: ../../library/stdtypes.rst:2336 msgid "" "Return the string left justified in a string of length *width*. Padding is " "done using the specified *fillchar* (default is an ASCII space). The " "original string is returned if *width* is less than or equal to ``len(s)``." msgstr "" -#: ../../library/stdtypes.rst:2325 +#: ../../library/stdtypes.rst:2342 msgid "" ">>> 'Python'.ljust(10)\n" "'Python '\n" @@ -3683,17 +3720,17 @@ msgstr "" ">>> 'Monty Python'.ljust(10, '.')\n" "'Monty Python'" -#: ../../library/stdtypes.rst:2334 +#: ../../library/stdtypes.rst:2351 ../../library/stdtypes.rst:2862 msgid "See also :meth:`rjust`." msgstr "另請參閱 :meth:`rjust`。" -#: ../../library/stdtypes.rst:2339 +#: ../../library/stdtypes.rst:2356 msgid "" "Return a copy of the string with all the cased characters [4]_ converted to " "lowercase. For example:" msgstr "" -#: ../../library/stdtypes.rst:2342 +#: ../../library/stdtypes.rst:2359 msgid "" ">>> 'Lower Method Example'.lower()\n" "'lower method example'" @@ -3701,14 +3738,14 @@ msgstr "" ">>> 'Lower Method Example'.lower()\n" "'lower method example'" -#: ../../library/stdtypes.rst:2347 +#: ../../library/stdtypes.rst:2364 msgid "" "The lowercasing algorithm used is `described in section 3.13 'Default Case " "Folding' of the Unicode Standard `__." msgstr "" -#: ../../library/stdtypes.rst:2354 +#: ../../library/stdtypes.rst:2371 msgid "" "Return a copy of the string with leading characters removed. The *chars* " "argument is a string specifying the set of characters to be removed. If " @@ -3717,7 +3754,7 @@ msgid "" "are stripped::" msgstr "" -#: ../../library/stdtypes.rst:2359 +#: ../../library/stdtypes.rst:2376 msgid "" ">>> ' spacious '.lstrip()\n" "'spacious '\n" @@ -3729,13 +3766,13 @@ msgstr "" ">>> 'www.example.com'.lstrip('cmowz.')\n" "'example.com'" -#: ../../library/stdtypes.rst:2364 +#: ../../library/stdtypes.rst:2381 msgid "" "See :meth:`str.removeprefix` for a method that will remove a single prefix " "string rather than all of a set of characters. For example::" msgstr "" -#: ../../library/stdtypes.rst:2367 +#: ../../library/stdtypes.rst:2384 msgid "" ">>> 'Arthur: three!'.lstrip('Arthur: ')\n" "'ee!'\n" @@ -3747,13 +3784,13 @@ msgstr "" ">>> 'Arthur: three!'.removeprefix('Arthur: ')\n" "'three!'" -#: ../../library/stdtypes.rst:2376 +#: ../../library/stdtypes.rst:2393 msgid "" "This static method returns a translation table usable for :meth:`str." "translate`." msgstr "" -#: ../../library/stdtypes.rst:2378 +#: ../../library/stdtypes.rst:2395 msgid "" "If there is only one argument, it must be a dictionary mapping Unicode " "ordinals (integers) or characters (strings of length 1) to Unicode ordinals, " @@ -3761,7 +3798,7 @@ msgid "" "converted to ordinals." msgstr "" -#: ../../library/stdtypes.rst:2383 +#: ../../library/stdtypes.rst:2400 msgid "" "If there are two arguments, they must be strings of equal length, and in the " "resulting dictionary, each character in *from* will be mapped to the " @@ -3769,7 +3806,7 @@ msgid "" "must be a string, whose characters will be mapped to ``None`` in the result." msgstr "" -#: ../../library/stdtypes.rst:2391 +#: ../../library/stdtypes.rst:2408 msgid "" "Split the string at the first occurrence of *sep*, and return a 3-tuple " "containing the part before the separator, the separator itself, and the part " @@ -3777,7 +3814,7 @@ msgid "" "containing the string itself, followed by two empty strings." msgstr "" -#: ../../library/stdtypes.rst:2398 +#: ../../library/stdtypes.rst:2415 msgid "" ">>> 'Monty Python'.partition(' ')\n" "('Monty', ' ', 'Python')\n" @@ -3793,17 +3830,17 @@ msgstr "" ">>> 'Monty Python'.partition('-')\n" "('Monty Python', '', '')" -#: ../../library/stdtypes.rst:2407 +#: ../../library/stdtypes.rst:2424 msgid "See also :meth:`rpartition`." msgstr "另請參閱 :meth:`rpartition`。" -#: ../../library/stdtypes.rst:2412 +#: ../../library/stdtypes.rst:2429 msgid "" "If the string starts with the *prefix* string, return " "``string[len(prefix):]``. Otherwise, return a copy of the original string:" msgstr "" -#: ../../library/stdtypes.rst:2416 +#: ../../library/stdtypes.rst:2433 msgid "" ">>> 'TestHook'.removeprefix('Test')\n" "'Hook'\n" @@ -3815,18 +3852,18 @@ msgstr "" ">>> 'BaseTestCase'.removeprefix('Test')\n" "'BaseTestCase'" -#: ../../library/stdtypes.rst:2425 +#: ../../library/stdtypes.rst:2442 msgid "See also :meth:`removesuffix` and :meth:`startswith`." msgstr "另請參閱 :meth:`removesuffix` 和 :meth:`startswith`。" -#: ../../library/stdtypes.rst:2430 +#: ../../library/stdtypes.rst:2447 msgid "" "If the string ends with the *suffix* string and that *suffix* is not empty, " "return ``string[:-len(suffix)]``. Otherwise, return a copy of the original " "string:" msgstr "" -#: ../../library/stdtypes.rst:2434 +#: ../../library/stdtypes.rst:2451 msgid "" ">>> 'MiscTests'.removesuffix('Tests')\n" "'Misc'\n" @@ -3838,11 +3875,11 @@ msgstr "" ">>> 'TmpDirMixin'.removesuffix('Tests')\n" "'TmpDirMixin'" -#: ../../library/stdtypes.rst:2443 +#: ../../library/stdtypes.rst:2460 msgid "See also :meth:`removeprefix` and :meth:`endswith`." msgstr "另請參閱 :meth:`removeprefix` 和 :meth:`endswith`。" -#: ../../library/stdtypes.rst:2448 +#: ../../library/stdtypes.rst:2465 msgid "" "Return a copy of the string with all occurrences of substring *old* replaced " "by *new*. If *count* is given, only the first *count* occurrences are " @@ -3850,7 +3887,7 @@ msgid "" "replaced. For example:" msgstr "" -#: ../../library/stdtypes.rst:2453 +#: ../../library/stdtypes.rst:2470 msgid "" ">>> 'spam, spam, spam'.replace('spam', 'eggs')\n" "'eggs, eggs, eggs'\n" @@ -3862,11 +3899,11 @@ msgstr "" ">>> 'spam, spam, spam'.replace('spam', 'eggs', 1)\n" "'eggs, spam, spam'" -#: ../../library/stdtypes.rst:2460 +#: ../../library/stdtypes.rst:2477 msgid "*count* is now supported as a keyword argument." msgstr "*count* 現在作為關鍵字引數被支援。" -#: ../../library/stdtypes.rst:2466 +#: ../../library/stdtypes.rst:2483 msgid "" "Return the highest index in the string where substring *sub* is found, such " "that *sub* is contained within ``s[start:end]``. Optional arguments *start* " @@ -3874,7 +3911,7 @@ msgid "" "For example:" msgstr "" -#: ../../library/stdtypes.rst:2471 +#: ../../library/stdtypes.rst:2488 msgid "" ">>> 'spam, spam, spam'.rfind('sp')\n" "12\n" @@ -3886,17 +3923,17 @@ msgstr "" ">>> 'spam, spam, spam'.rfind('sp', 0, 10)\n" "6" -#: ../../library/stdtypes.rst:2478 +#: ../../library/stdtypes.rst:2495 msgid "See also :meth:`find` and :meth:`rindex`." msgstr "另請參閱 :meth:`find` 和 :meth:`rindex`。" -#: ../../library/stdtypes.rst:2483 +#: ../../library/stdtypes.rst:2500 msgid "" "Like :meth:`rfind` but raises :exc:`ValueError` when the substring *sub* is " "not found. For example:" msgstr "" -#: ../../library/stdtypes.rst:2487 +#: ../../library/stdtypes.rst:2504 msgid "" ">>> 'spam, spam, spam'.rindex('spam')\n" "12\n" @@ -3916,18 +3953,38 @@ msgstr "" " ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^\n" "ValueError: substring not found" -#: ../../library/stdtypes.rst:2498 +#: ../../library/stdtypes.rst:2515 msgid "See also :meth:`index` and :meth:`find`." msgstr "另請參閱 :meth:`index` 和 :meth:`find`。" -#: ../../library/stdtypes.rst:2503 +#: ../../library/stdtypes.rst:2520 msgid "" "Return the string right justified in a string of length *width*. Padding is " "done using the specified *fillchar* (default is an ASCII space). The " "original string is returned if *width* is less than or equal to ``len(s)``." msgstr "" -#: ../../library/stdtypes.rst:2510 +#: ../../library/stdtypes.rst:2526 +msgid "" +">>> 'Python'.rjust(10)\n" +"' Python'\n" +">>> 'Python'.rjust(10, '.')\n" +"'....Python'\n" +">>> 'Monty Python'.rjust(10, '.')\n" +"'Monty Python'" +msgstr "" +">>> 'Python'.rjust(10)\n" +"' Python'\n" +">>> 'Python'.rjust(10, '.')\n" +"'....Python'\n" +">>> 'Monty Python'.rjust(10, '.')\n" +"'Monty Python'" + +#: ../../library/stdtypes.rst:2535 +msgid "See also :meth:`ljust` and :meth:`zfill`." +msgstr "另請參閱 :meth:`ljust` 和 :meth:`zfill`。" + +#: ../../library/stdtypes.rst:2540 msgid "" "Split the string at the last occurrence of *sep*, and return a 3-tuple " "containing the part before the separator, the separator itself, and the part " @@ -3935,7 +3992,7 @@ msgid "" "containing two empty strings, followed by the string itself." msgstr "" -#: ../../library/stdtypes.rst:2517 +#: ../../library/stdtypes.rst:2547 msgid "" ">>> 'Monty Python'.rpartition(' ')\n" "('Monty', ' ', 'Python')\n" @@ -3951,11 +4008,11 @@ msgstr "" ">>> 'Monty Python'.rpartition('-')\n" "('', '', 'Monty Python')" -#: ../../library/stdtypes.rst:2526 +#: ../../library/stdtypes.rst:2556 msgid "See also :meth:`partition`." msgstr "另請參閱 :meth:`partition`。" -#: ../../library/stdtypes.rst:2531 +#: ../../library/stdtypes.rst:2561 msgid "" "Return a list of the words in the string, using *sep* as the delimiter " "string. If *maxsplit* is given, at most *maxsplit* splits are done, the " @@ -3964,7 +4021,7 @@ msgid "" "behaves like :meth:`split` which is described in detail below." msgstr "" -#: ../../library/stdtypes.rst:2540 +#: ../../library/stdtypes.rst:2570 msgid "" "Return a copy of the string with trailing characters removed. The *chars* " "argument is a string specifying the set of characters to be removed. If " @@ -3973,7 +4030,7 @@ msgid "" "are stripped. For example:" msgstr "" -#: ../../library/stdtypes.rst:2546 +#: ../../library/stdtypes.rst:2576 msgid "" ">>> ' spacious '.rstrip()\n" "' spacious'\n" @@ -3985,13 +4042,13 @@ msgstr "" ">>> 'mississippi'.rstrip('ipz')\n" "'mississ'" -#: ../../library/stdtypes.rst:2553 +#: ../../library/stdtypes.rst:2583 msgid "" "See :meth:`removesuffix` for a method that will remove a single suffix " "string rather than all of a set of characters. For example::" msgstr "" -#: ../../library/stdtypes.rst:2556 +#: ../../library/stdtypes.rst:2586 msgid "" ">>> 'Monty Python'.rstrip(' Python')\n" "'M'\n" @@ -4003,11 +4060,11 @@ msgstr "" ">>> 'Monty Python'.removesuffix(' Python')\n" "'Monty'" -#: ../../library/stdtypes.rst:2561 +#: ../../library/stdtypes.rst:2591 msgid "See also :meth:`strip`." msgstr "另請參閱 :meth:`strip`。" -#: ../../library/stdtypes.rst:2566 +#: ../../library/stdtypes.rst:2596 msgid "" "Return a list of the words in the string, using *sep* as the delimiter " "string. If *maxsplit* is given, at most *maxsplit* splits are done (thus, " @@ -4016,7 +4073,7 @@ msgid "" "possible splits are made)." msgstr "" -#: ../../library/stdtypes.rst:2572 +#: ../../library/stdtypes.rst:2602 msgid "" "If *sep* is given, consecutive delimiters are not grouped together and are " "deemed to delimit empty strings (for example, ``'1,,2'.split(',')`` returns " @@ -4026,21 +4083,20 @@ msgid "" "``['']``." msgstr "" -#: ../../library/stdtypes.rst:2579 ../../library/stdtypes.rst:2597 -#: ../../library/stdtypes.rst:2609 ../../library/stdtypes.rst:2663 -#: ../../library/stdtypes.rst:2753 ../../library/stdtypes.rst:2823 -#: ../../library/stdtypes.rst:2918 ../../library/stdtypes.rst:3884 -#: ../../library/stdtypes.rst:3902 ../../library/stdtypes.rst:3992 -#: ../../library/stdtypes.rst:4008 ../../library/stdtypes.rst:4033 -#: ../../library/stdtypes.rst:4047 ../../library/stdtypes.rst:4075 -#: ../../library/stdtypes.rst:4089 ../../library/stdtypes.rst:4107 -#: ../../library/stdtypes.rst:4134 ../../library/stdtypes.rst:4157 -#: ../../library/stdtypes.rst:4184 ../../library/stdtypes.rst:4226 -#: ../../library/stdtypes.rst:4250 +#: ../../library/stdtypes.rst:2609 ../../library/stdtypes.rst:2627 +#: ../../library/stdtypes.rst:2639 ../../library/stdtypes.rst:2693 +#: ../../library/stdtypes.rst:2783 ../../library/stdtypes.rst:2952 +#: ../../library/stdtypes.rst:3918 ../../library/stdtypes.rst:3936 +#: ../../library/stdtypes.rst:4026 ../../library/stdtypes.rst:4042 +#: ../../library/stdtypes.rst:4067 ../../library/stdtypes.rst:4081 +#: ../../library/stdtypes.rst:4109 ../../library/stdtypes.rst:4123 +#: ../../library/stdtypes.rst:4141 ../../library/stdtypes.rst:4168 +#: ../../library/stdtypes.rst:4191 ../../library/stdtypes.rst:4218 +#: ../../library/stdtypes.rst:4260 ../../library/stdtypes.rst:4284 msgid "For example::" msgstr "舉例來說: ::" -#: ../../library/stdtypes.rst:2581 +#: ../../library/stdtypes.rst:2611 msgid "" ">>> '1,2,3'.split(',')\n" "['1', '2', '3']\n" @@ -4060,7 +4116,7 @@ msgstr "" ">>> '1<>2<>3<4'.split('<>')\n" "['1', '2', '3<4']" -#: ../../library/stdtypes.rst:2590 +#: ../../library/stdtypes.rst:2620 msgid "" "If *sep* is not specified or is ``None``, a different splitting algorithm is " "applied: runs of consecutive whitespace are regarded as a single separator, " @@ -4070,7 +4126,7 @@ msgid "" "returns ``[]``." msgstr "" -#: ../../library/stdtypes.rst:2599 +#: ../../library/stdtypes.rst:2629 msgid "" ">>> '1 2 3'.split()\n" "['1', '2', '3']\n" @@ -4086,13 +4142,13 @@ msgstr "" ">>> ' 1 2 3 '.split()\n" "['1', '2', '3']" -#: ../../library/stdtypes.rst:2606 +#: ../../library/stdtypes.rst:2636 msgid "" "If *sep* is not specified or is ``None`` and *maxsplit* is ``0``, only " "leading runs of consecutive whitespace are considered." msgstr "" -#: ../../library/stdtypes.rst:2611 +#: ../../library/stdtypes.rst:2641 msgid "" ">>> \"\".split(None, 0)\n" "[]\n" @@ -4108,124 +4164,124 @@ msgstr "" ">>> \" foo \".split(maxsplit=0)\n" "['foo ']" -#: ../../library/stdtypes.rst:2618 +#: ../../library/stdtypes.rst:2648 msgid "See also :meth:`join`." msgstr "另請參閱 :meth:`join`。" -#: ../../library/stdtypes.rst:2626 +#: ../../library/stdtypes.rst:2656 msgid "" "Return a list of the lines in the string, breaking at line boundaries. Line " "breaks are not included in the resulting list unless *keepends* is given and " "true." msgstr "" -#: ../../library/stdtypes.rst:2630 +#: ../../library/stdtypes.rst:2660 msgid "" "This method splits on the following line boundaries. In particular, the " "boundaries are a superset of :term:`universal newlines`." msgstr "" -#: ../../library/stdtypes.rst:2634 +#: ../../library/stdtypes.rst:2664 msgid "Representation" msgstr "" -#: ../../library/stdtypes.rst:2634 +#: ../../library/stdtypes.rst:2664 msgid "Description" msgstr "描述" -#: ../../library/stdtypes.rst:2636 +#: ../../library/stdtypes.rst:2666 msgid "``\\n``" msgstr "``\\n``" -#: ../../library/stdtypes.rst:2636 +#: ../../library/stdtypes.rst:2666 msgid "Line Feed" msgstr "" -#: ../../library/stdtypes.rst:2638 +#: ../../library/stdtypes.rst:2668 msgid "``\\r``" msgstr "``\\r``" -#: ../../library/stdtypes.rst:2638 +#: ../../library/stdtypes.rst:2668 msgid "Carriage Return" msgstr "" -#: ../../library/stdtypes.rst:2640 +#: ../../library/stdtypes.rst:2670 msgid "``\\r\\n``" msgstr "``\\r\\n``" -#: ../../library/stdtypes.rst:2640 +#: ../../library/stdtypes.rst:2670 msgid "Carriage Return + Line Feed" msgstr "" -#: ../../library/stdtypes.rst:2642 +#: ../../library/stdtypes.rst:2672 msgid "``\\v`` or ``\\x0b``" msgstr "``\\v`` 或 ``\\x0b``" -#: ../../library/stdtypes.rst:2642 +#: ../../library/stdtypes.rst:2672 msgid "Line Tabulation" msgstr "" -#: ../../library/stdtypes.rst:2644 +#: ../../library/stdtypes.rst:2674 msgid "``\\f`` or ``\\x0c``" msgstr "``\\f`` 或 ``\\x0c``" -#: ../../library/stdtypes.rst:2644 +#: ../../library/stdtypes.rst:2674 msgid "Form Feed" msgstr "" -#: ../../library/stdtypes.rst:2646 +#: ../../library/stdtypes.rst:2676 msgid "``\\x1c``" msgstr "``\\x1c``" -#: ../../library/stdtypes.rst:2646 +#: ../../library/stdtypes.rst:2676 msgid "File Separator" msgstr "" -#: ../../library/stdtypes.rst:2648 +#: ../../library/stdtypes.rst:2678 msgid "``\\x1d``" msgstr "``\\x1d``" -#: ../../library/stdtypes.rst:2648 +#: ../../library/stdtypes.rst:2678 msgid "Group Separator" msgstr "" -#: ../../library/stdtypes.rst:2650 +#: ../../library/stdtypes.rst:2680 msgid "``\\x1e``" msgstr "``\\x1e``" -#: ../../library/stdtypes.rst:2650 +#: ../../library/stdtypes.rst:2680 msgid "Record Separator" msgstr "" -#: ../../library/stdtypes.rst:2652 +#: ../../library/stdtypes.rst:2682 msgid "``\\x85``" msgstr "``\\x85``" -#: ../../library/stdtypes.rst:2652 +#: ../../library/stdtypes.rst:2682 msgid "Next Line (C1 Control Code)" msgstr "" -#: ../../library/stdtypes.rst:2654 +#: ../../library/stdtypes.rst:2684 msgid "``\\u2028``" msgstr "``\\u2028``" -#: ../../library/stdtypes.rst:2654 +#: ../../library/stdtypes.rst:2684 msgid "Line Separator" msgstr "" -#: ../../library/stdtypes.rst:2656 +#: ../../library/stdtypes.rst:2686 msgid "``\\u2029``" msgstr "``\\u2029``" -#: ../../library/stdtypes.rst:2656 +#: ../../library/stdtypes.rst:2686 msgid "Paragraph Separator" msgstr "" -#: ../../library/stdtypes.rst:2661 +#: ../../library/stdtypes.rst:2691 msgid "``\\v`` and ``\\f`` added to list of line boundaries." msgstr "" -#: ../../library/stdtypes.rst:2665 +#: ../../library/stdtypes.rst:2695 msgid "" ">>> 'ab c\\n\\nde fg\\rkl\\r\\n'.splitlines()\n" "['ab c', '', 'de fg', 'kl']\n" @@ -4237,14 +4293,14 @@ msgstr "" ">>> 'ab c\\n\\nde fg\\rkl\\r\\n'.splitlines(keepends=True)\n" "['ab c\\n', '\\n', 'de fg\\r', 'kl\\r\\n']" -#: ../../library/stdtypes.rst:2670 +#: ../../library/stdtypes.rst:2700 msgid "" "Unlike :meth:`~str.split` when a delimiter string *sep* is given, this " "method returns an empty list for the empty string, and a terminal line break " "does not result in an extra line::" msgstr "" -#: ../../library/stdtypes.rst:2674 +#: ../../library/stdtypes.rst:2704 msgid "" ">>> \"\".splitlines()\n" "[]\n" @@ -4256,11 +4312,11 @@ msgstr "" ">>> \"One line\\n\".splitlines()\n" "['One line']" -#: ../../library/stdtypes.rst:2679 +#: ../../library/stdtypes.rst:2709 msgid "For comparison, ``split('\\n')`` gives::" msgstr "" -#: ../../library/stdtypes.rst:2681 +#: ../../library/stdtypes.rst:2711 msgid "" ">>> ''.split('\\n')\n" "['']\n" @@ -4272,7 +4328,7 @@ msgstr "" ">>> 'Two lines\\n'.split('\\n')\n" "['Two lines', '']" -#: ../../library/stdtypes.rst:2689 +#: ../../library/stdtypes.rst:2719 msgid "" "Return ``True`` if string starts with the *prefix*, otherwise return " "``False``. *prefix* can also be a tuple of prefixes to look for. With " @@ -4280,7 +4336,7 @@ msgid "" "*end*, stop comparing string at that position." msgstr "" -#: ../../library/stdtypes.rst:2696 +#: ../../library/stdtypes.rst:2726 msgid "" ">>> 'Python'.startswith('Py')\n" "True\n" @@ -4296,11 +4352,11 @@ msgstr "" ">>> 'Python is amazing'.startswith('is', 7)\n" "True" -#: ../../library/stdtypes.rst:2705 +#: ../../library/stdtypes.rst:2735 msgid "See also :meth:`endswith` and :meth:`removeprefix`." msgstr "另請參閱 :meth:`endswith` 和 :meth:`removeprefix`。" -#: ../../library/stdtypes.rst:2710 +#: ../../library/stdtypes.rst:2740 msgid "" "Return a copy of the string with the leading and trailing characters " "removed. The *chars* argument is a string specifying the set of characters " @@ -4309,7 +4365,7 @@ msgid "" "all combinations of its values are stripped." msgstr "" -#: ../../library/stdtypes.rst:2718 +#: ../../library/stdtypes.rst:2748 msgid "" ">>> ' spacious '.strip()\n" "'spacious'\n" @@ -4321,7 +4377,7 @@ msgstr "" ">>> 'www.example.com'.strip('cmowz.')\n" "'example'" -#: ../../library/stdtypes.rst:2725 +#: ../../library/stdtypes.rst:2755 msgid "" "The outermost leading and trailing *chars* argument values are stripped from " "the string. Characters are removed from the leading end until reaching a " @@ -4329,7 +4385,7 @@ msgid "" "A similar action takes place on the trailing end." msgstr "" -#: ../../library/stdtypes.rst:2732 +#: ../../library/stdtypes.rst:2762 msgid "" ">>> comment_string = '#....... Section 3.2.1 Issue #32 .......'\n" ">>> comment_string.strip('.#! ')\n" @@ -4339,24 +4395,24 @@ msgstr "" ">>> comment_string.strip('.#! ')\n" "'Section 3.2.1 Issue #32'" -#: ../../library/stdtypes.rst:2738 +#: ../../library/stdtypes.rst:2768 msgid "See also :meth:`rstrip`." msgstr "另請參閱 :meth:`rstrip`。" -#: ../../library/stdtypes.rst:2743 +#: ../../library/stdtypes.rst:2773 msgid "" "Return a copy of the string with uppercase characters converted to lowercase " "and vice versa. Note that it is not necessarily true that ``s.swapcase()." "swapcase() == s``." msgstr "" -#: ../../library/stdtypes.rst:2750 +#: ../../library/stdtypes.rst:2780 msgid "" "Return a titlecased version of the string where words start with an " "uppercase character and the remaining characters are lowercase." msgstr "" -#: ../../library/stdtypes.rst:2755 +#: ../../library/stdtypes.rst:2785 msgid "" ">>> 'Hello world'.title()\n" "'Hello World'" @@ -4364,7 +4420,7 @@ msgstr "" ">>> 'Hello world'.title()\n" "'Hello World'" -#: ../../library/stdtypes.rst:2758 ../../library/stdtypes.rst:4194 +#: ../../library/stdtypes.rst:2788 ../../library/stdtypes.rst:4228 msgid "" "The algorithm uses a simple language-independent definition of a word as " "groups of consecutive letters. The definition works in many contexts but it " @@ -4372,7 +4428,7 @@ msgid "" "which may not be the desired result::" msgstr "" -#: ../../library/stdtypes.rst:2763 +#: ../../library/stdtypes.rst:2793 msgid "" ">>> \"they're bill's friends from the UK\".title()\n" "\"They'Re Bill'S Friends From The Uk\"" @@ -4380,19 +4436,19 @@ msgstr "" ">>> \"they're bill's friends from the UK\".title()\n" "\"They'Re Bill'S Friends From The Uk\"" -#: ../../library/stdtypes.rst:2766 +#: ../../library/stdtypes.rst:2796 msgid "" "The :func:`string.capwords` function does not have this problem, as it " "splits words on spaces only." msgstr "" -#: ../../library/stdtypes.rst:2769 +#: ../../library/stdtypes.rst:2799 msgid "" "Alternatively, a workaround for apostrophes can be constructed using regular " "expressions::" msgstr "" -#: ../../library/stdtypes.rst:2772 +#: ../../library/stdtypes.rst:2802 msgid "" ">>> import re\n" ">>> def titlecase(s):\n" @@ -4412,11 +4468,11 @@ msgstr "" ">>> titlecase(\"they're bill's friends.\")\n" "\"They're Bill's Friends.\"" -#: ../../library/stdtypes.rst:2781 +#: ../../library/stdtypes.rst:2811 msgid "See also :meth:`istitle`." msgstr "另請參閱 :meth:`istitle`。" -#: ../../library/stdtypes.rst:2786 +#: ../../library/stdtypes.rst:2816 msgid "" "Return a copy of the string in which each character has been mapped through " "the given translation table. The table must be an object that implements " @@ -4428,19 +4484,19 @@ msgid "" "exception, to map the character to itself." msgstr "" -#: ../../library/stdtypes.rst:2795 +#: ../../library/stdtypes.rst:2825 msgid "" "You can use :meth:`str.maketrans` to create a translation map from character-" "to-character mappings in different formats." msgstr "" -#: ../../library/stdtypes.rst:2798 +#: ../../library/stdtypes.rst:2828 msgid "" "See also the :mod:`codecs` module for a more flexible approach to custom " "character mappings." msgstr "" -#: ../../library/stdtypes.rst:2804 +#: ../../library/stdtypes.rst:2834 msgid "" "Return a copy of the string with all the cased characters [4]_ converted to " "uppercase. Note that ``s.upper().isupper()`` might be ``False`` if ``s`` " @@ -4449,14 +4505,14 @@ msgid "" "titlecase)." msgstr "" -#: ../../library/stdtypes.rst:2810 +#: ../../library/stdtypes.rst:2840 msgid "" "The uppercasing algorithm used is `described in section 3.13 'Default Case " "Folding' of the Unicode Standard `__." msgstr "" -#: ../../library/stdtypes.rst:2817 +#: ../../library/stdtypes.rst:2847 msgid "" "Return a copy of the string left filled with ASCII ``'0'`` digits to make a " "string of length *width*. A leading sign prefix (``'+'``/``'-'``) is handled " @@ -4464,7 +4520,7 @@ msgid "" "original string is returned if *width* is less than or equal to ``len(s)``." msgstr "" -#: ../../library/stdtypes.rst:2825 +#: ../../library/stdtypes.rst:2855 msgid "" ">>> \"42\".zfill(5)\n" "'00042'\n" @@ -4476,27 +4532,27 @@ msgstr "" ">>> \"-42\".zfill(5)\n" "'-0042'" -#: ../../library/stdtypes.rst:2848 +#: ../../library/stdtypes.rst:2882 msgid "Formatted String Literals (f-strings)" msgstr "" -#: ../../library/stdtypes.rst:2851 +#: ../../library/stdtypes.rst:2885 msgid "" "The :keyword:`await` and :keyword:`async for` can be used in expressions " "within f-strings." msgstr "" -#: ../../library/stdtypes.rst:2854 +#: ../../library/stdtypes.rst:2888 msgid "Added the debug specifier (``=``)" msgstr "" -#: ../../library/stdtypes.rst:2856 +#: ../../library/stdtypes.rst:2890 msgid "" "Many restrictions on expressions within f-strings have been removed. " "Notably, nested strings, comments, and backslashes are now permitted." msgstr "" -#: ../../library/stdtypes.rst:2860 +#: ../../library/stdtypes.rst:2894 msgid "" "An :dfn:`f-string` (formally a :dfn:`formatted string literal`) is a string " "literal that is prefixed with ``f`` or ``F``. This type of string literal " @@ -4505,29 +4561,29 @@ msgid "" "replacement field must contain an expression, optionally followed by:" msgstr "" -#: ../../library/stdtypes.rst:2867 +#: ../../library/stdtypes.rst:2901 msgid "a *debug specifier* -- an equal sign (``=``);" msgstr "" -#: ../../library/stdtypes.rst:2868 +#: ../../library/stdtypes.rst:2902 msgid "a *conversion specifier* -- ``!s``, ``!r`` or ``!a``; and/or" msgstr "" -#: ../../library/stdtypes.rst:2869 +#: ../../library/stdtypes.rst:2903 msgid "a *format specifier* prefixed with a colon (``:``)." msgstr "" -#: ../../library/stdtypes.rst:2871 +#: ../../library/stdtypes.rst:2905 msgid "" "See the :ref:`Lexical Analysis section on f-strings ` for details " "on the syntax of these fields." msgstr "" -#: ../../library/stdtypes.rst:2875 +#: ../../library/stdtypes.rst:2909 msgid "Debug specifier" msgstr "" -#: ../../library/stdtypes.rst:2879 +#: ../../library/stdtypes.rst:2913 msgid "" "If a debug specifier -- an equal sign (``=``) -- appears after the " "replacement field expression, the resulting f-string will contain the " @@ -4535,7 +4591,7 @@ msgid "" "is often useful for debugging::" msgstr "" -#: ../../library/stdtypes.rst:2884 +#: ../../library/stdtypes.rst:2918 msgid "" ">>> number = 14.3\n" ">>> f'{number=}'\n" @@ -4545,13 +4601,13 @@ msgstr "" ">>> f'{number=}'\n" "'number=14.3'" -#: ../../library/stdtypes.rst:2888 +#: ../../library/stdtypes.rst:2922 msgid "" "Whitespace before, inside and after the expression, as well as whitespace " "after the equal sign, is significant --- it is retained in the result::" msgstr "" -#: ../../library/stdtypes.rst:2891 +#: ../../library/stdtypes.rst:2925 msgid "" ">>> f'{ number - 4 = }'\n" "' number - 4 = 10.3'" @@ -4559,17 +4615,17 @@ msgstr "" ">>> f'{ number - 4 = }'\n" "' number - 4 = 10.3'" -#: ../../library/stdtypes.rst:2896 +#: ../../library/stdtypes.rst:2930 msgid "Conversion specifier" msgstr "" -#: ../../library/stdtypes.rst:2898 +#: ../../library/stdtypes.rst:2932 msgid "" "By default, the value of a replacement field expression is converted to a " "string using :func:`str`::" msgstr "" -#: ../../library/stdtypes.rst:2901 +#: ../../library/stdtypes.rst:2935 msgid "" ">>> from fractions import Fraction\n" ">>> one_third = Fraction(1, 3)\n" @@ -4581,13 +4637,13 @@ msgstr "" ">>> f'{one_third}'\n" "'1/3'" -#: ../../library/stdtypes.rst:2906 +#: ../../library/stdtypes.rst:2940 msgid "" "When a debug specifier but no format specifier is used, the default " "conversion instead uses :func:`repr`::" msgstr "" -#: ../../library/stdtypes.rst:2909 +#: ../../library/stdtypes.rst:2943 msgid "" ">>> f'{one_third = }'\n" "'one_third = Fraction(1, 3)'" @@ -4595,24 +4651,24 @@ msgstr "" ">>> f'{one_third = }'\n" "'one_third = Fraction(1, 3)'" -#: ../../library/stdtypes.rst:2912 +#: ../../library/stdtypes.rst:2946 msgid "" "The conversion can be specified explicitly using one of these specifiers:" msgstr "" -#: ../../library/stdtypes.rst:2914 +#: ../../library/stdtypes.rst:2948 msgid "``!s`` for :func:`str`" msgstr "``!s`` 用於 :func:`str`" -#: ../../library/stdtypes.rst:2915 +#: ../../library/stdtypes.rst:2949 msgid "``!r`` for :func:`repr`" msgstr "``!r`` 用於 :func:`repr`" -#: ../../library/stdtypes.rst:2916 +#: ../../library/stdtypes.rst:2950 msgid "``!a`` for :func:`ascii`" msgstr "``!a`` 用於 :func:`ascii`" -#: ../../library/stdtypes.rst:2920 +#: ../../library/stdtypes.rst:2954 msgid "" ">>> str(one_third)\n" "'1/3'\n" @@ -4644,11 +4700,11 @@ msgstr "" ">>> f'{string = !a}'\n" "\"string = '\\\\xa1ko\\\\u010dka \\\\U0001f638!'\"" -#: ../../library/stdtypes.rst:2937 +#: ../../library/stdtypes.rst:2971 msgid "Format specifier" msgstr "" -#: ../../library/stdtypes.rst:2939 +#: ../../library/stdtypes.rst:2973 msgid "" "After the expression has been evaluated, and possibly converted using an " "explicit conversion specifier, it is formatted using the :func:`format` " @@ -4658,7 +4714,7 @@ msgid "" "the replacement field. For example::" msgstr "" -#: ../../library/stdtypes.rst:2946 +#: ../../library/stdtypes.rst:2980 msgid "" ">>> from fractions import Fraction\n" ">>> one_third = Fraction(1, 3)\n" @@ -4682,29 +4738,29 @@ msgstr "" ">>> f'{one_third = :~>10}~'\n" "'one_third = ~~~~~~~1/3~'" -#: ../../library/stdtypes.rst:2960 +#: ../../library/stdtypes.rst:2994 msgid "Template String Literals (t-strings)" msgstr "模板字串字面值 (t-strings)" -#: ../../library/stdtypes.rst:2962 +#: ../../library/stdtypes.rst:2996 msgid "" "An :dfn:`t-string` (formally a :dfn:`template string literal`) is a string " "literal that is prefixed with ``t`` or ``T``." msgstr "" -#: ../../library/stdtypes.rst:2965 +#: ../../library/stdtypes.rst:2999 msgid "" "These strings follow the same syntax and evaluation rules as :ref:`formatted " "string literals `, with for the following differences:" msgstr "" -#: ../../library/stdtypes.rst:2969 +#: ../../library/stdtypes.rst:3003 msgid "" "Rather than evaluating to a ``str`` object, template string literals " "evaluate to a :class:`string.templatelib.Template` object." msgstr "" -#: ../../library/stdtypes.rst:2972 +#: ../../library/stdtypes.rst:3006 msgid "" "The :func:`format` protocol is not used. Instead, the format specifier and " "conversions (if any) are passed to a new :class:`~string.templatelib." @@ -4713,7 +4769,7 @@ msgid "" "Template` object to decide how to handle format specifiers and conversions." msgstr "" -#: ../../library/stdtypes.rst:2979 +#: ../../library/stdtypes.rst:3013 msgid "" "Format specifiers containing nested replacement fields are evaluated " "eagerly, prior to being passed to the :class:`~string.templatelib." @@ -4723,7 +4779,7 @@ msgid "" "to be ``2``, the resulting format specifier would be ``'.2f'``." msgstr "" -#: ../../library/stdtypes.rst:2987 +#: ../../library/stdtypes.rst:3021 msgid "" "When the equals sign ``'='`` is provided in an interpolation expression, the " "text of the expression is appended to the literal string that precedes the " @@ -4735,18 +4791,18 @@ msgid "" "behaviour." msgstr "" -#: ../../library/stdtypes.rst:3001 +#: ../../library/stdtypes.rst:3035 msgid "``printf``-style String Formatting" msgstr "" -#: ../../library/stdtypes.rst:3014 +#: ../../library/stdtypes.rst:3048 msgid "" "The formatting operations described here exhibit a variety of quirks that " "lead to a number of common errors (such as failing to display tuples and " "dictionaries correctly)." msgstr "" -#: ../../library/stdtypes.rst:3018 +#: ../../library/stdtypes.rst:3052 msgid "" "Using :ref:`formatted string literals `, the :meth:`str.format` " "interface, or :class:`string.Template` may help avoid these errors. Each of " @@ -4754,7 +4810,7 @@ msgid "" "flexibility, and/or extensibility." msgstr "" -#: ../../library/stdtypes.rst:3023 +#: ../../library/stdtypes.rst:3057 msgid "" "String objects have one unique built-in operation: the ``%`` operator " "(modulo). This is also known as the string *formatting* or *interpolation* " @@ -4764,7 +4820,7 @@ msgid "" "function in the C language. For example:" msgstr "" -#: ../../library/stdtypes.rst:3030 +#: ../../library/stdtypes.rst:3064 msgid "" ">>> print('%s has %d quote types.' % ('Python', 2))\n" "Python has 2 quote types." @@ -4772,7 +4828,7 @@ msgstr "" ">>> print('%s has %d quote types.' % ('Python', 2))\n" "Python has 2 quote types." -#: ../../library/stdtypes.rst:3035 +#: ../../library/stdtypes.rst:3069 msgid "" "If *format* requires a single argument, *values* may be a single non-tuple " "object. [5]_ Otherwise, *values* must be a tuple with exactly the number of " @@ -4780,36 +4836,36 @@ msgid "" "example, a dictionary)." msgstr "" -#: ../../library/stdtypes.rst:3045 ../../library/stdtypes.rst:4305 +#: ../../library/stdtypes.rst:3079 ../../library/stdtypes.rst:4339 msgid "" "A conversion specifier contains two or more characters and has the following " "components, which must occur in this order:" msgstr "" -#: ../../library/stdtypes.rst:3048 ../../library/stdtypes.rst:4308 +#: ../../library/stdtypes.rst:3082 ../../library/stdtypes.rst:4342 msgid "The ``'%'`` character, which marks the start of the specifier." msgstr "" -#: ../../library/stdtypes.rst:3050 ../../library/stdtypes.rst:4310 +#: ../../library/stdtypes.rst:3084 ../../library/stdtypes.rst:4344 msgid "" "Mapping key (optional), consisting of a parenthesised sequence of characters " "(for example, ``(somename)``)." msgstr "" -#: ../../library/stdtypes.rst:3053 ../../library/stdtypes.rst:4313 +#: ../../library/stdtypes.rst:3087 ../../library/stdtypes.rst:4347 msgid "" "Conversion flags (optional), which affect the result of some conversion " "types." msgstr "" -#: ../../library/stdtypes.rst:3056 ../../library/stdtypes.rst:4316 +#: ../../library/stdtypes.rst:3090 ../../library/stdtypes.rst:4350 msgid "" "Minimum field width (optional). If specified as an ``'*'`` (asterisk), the " "actual width is read from the next element of the tuple in *values*, and the " "object to convert comes after the minimum field width and optional precision." msgstr "" -#: ../../library/stdtypes.rst:3060 ../../library/stdtypes.rst:4320 +#: ../../library/stdtypes.rst:3094 ../../library/stdtypes.rst:4354 msgid "" "Precision (optional), given as a ``'.'`` (dot) followed by the precision. " "If specified as ``'*'`` (an asterisk), the actual precision is read from the " @@ -4817,15 +4873,15 @@ msgid "" "the precision." msgstr "" -#: ../../library/stdtypes.rst:3065 ../../library/stdtypes.rst:4325 +#: ../../library/stdtypes.rst:3099 ../../library/stdtypes.rst:4359 msgid "Length modifier (optional)." msgstr "" -#: ../../library/stdtypes.rst:3067 ../../library/stdtypes.rst:4327 +#: ../../library/stdtypes.rst:3101 ../../library/stdtypes.rst:4361 msgid "Conversion type." msgstr "" -#: ../../library/stdtypes.rst:3069 +#: ../../library/stdtypes.rst:3103 msgid "" "When the right argument is a dictionary (or other mapping type), then the " "formats in the string *must* include a parenthesised mapping key into that " @@ -4833,279 +4889,279 @@ msgid "" "selects the value to be formatted from the mapping. For example:" msgstr "" -#: ../../library/stdtypes.rst:3078 ../../library/stdtypes.rst:4338 +#: ../../library/stdtypes.rst:3112 ../../library/stdtypes.rst:4372 msgid "" "In this case no ``*`` specifiers may occur in a format (since they require a " "sequential parameter list)." msgstr "" -#: ../../library/stdtypes.rst:3081 ../../library/stdtypes.rst:4341 +#: ../../library/stdtypes.rst:3115 ../../library/stdtypes.rst:4375 msgid "The conversion flag characters are:" msgstr "" -#: ../../library/stdtypes.rst:3090 ../../library/stdtypes.rst:4350 +#: ../../library/stdtypes.rst:3124 ../../library/stdtypes.rst:4384 msgid "Flag" msgstr "" -#: ../../library/stdtypes.rst:3092 ../../library/stdtypes.rst:4352 +#: ../../library/stdtypes.rst:3126 ../../library/stdtypes.rst:4386 msgid "``'#'``" msgstr "``'#'``" -#: ../../library/stdtypes.rst:3092 ../../library/stdtypes.rst:4352 +#: ../../library/stdtypes.rst:3126 ../../library/stdtypes.rst:4386 msgid "" "The value conversion will use the \"alternate form\" (where defined below)." msgstr "" -#: ../../library/stdtypes.rst:3095 ../../library/stdtypes.rst:4355 +#: ../../library/stdtypes.rst:3129 ../../library/stdtypes.rst:4389 msgid "``'0'``" msgstr "``'0'``" -#: ../../library/stdtypes.rst:3095 ../../library/stdtypes.rst:4355 +#: ../../library/stdtypes.rst:3129 ../../library/stdtypes.rst:4389 msgid "The conversion will be zero padded for numeric values." msgstr "" -#: ../../library/stdtypes.rst:3097 ../../library/stdtypes.rst:4357 +#: ../../library/stdtypes.rst:3131 ../../library/stdtypes.rst:4391 msgid "``'-'``" msgstr "``'-'``" -#: ../../library/stdtypes.rst:3097 ../../library/stdtypes.rst:4357 +#: ../../library/stdtypes.rst:3131 ../../library/stdtypes.rst:4391 msgid "" "The converted value is left adjusted (overrides the ``'0'`` conversion if " "both are given)." msgstr "" -#: ../../library/stdtypes.rst:3100 ../../library/stdtypes.rst:4360 +#: ../../library/stdtypes.rst:3134 ../../library/stdtypes.rst:4394 msgid "``' '``" msgstr "``' '``" -#: ../../library/stdtypes.rst:3100 ../../library/stdtypes.rst:4360 +#: ../../library/stdtypes.rst:3134 ../../library/stdtypes.rst:4394 msgid "" "(a space) A blank should be left before a positive number (or empty string) " "produced by a signed conversion." msgstr "" -#: ../../library/stdtypes.rst:3103 ../../library/stdtypes.rst:4363 +#: ../../library/stdtypes.rst:3137 ../../library/stdtypes.rst:4397 msgid "``'+'``" msgstr "``'+'``" -#: ../../library/stdtypes.rst:3103 ../../library/stdtypes.rst:4363 +#: ../../library/stdtypes.rst:3137 ../../library/stdtypes.rst:4397 msgid "" "A sign character (``'+'`` or ``'-'``) will precede the conversion (overrides " "a \"space\" flag)." msgstr "" -#: ../../library/stdtypes.rst:3107 ../../library/stdtypes.rst:4367 +#: ../../library/stdtypes.rst:3141 ../../library/stdtypes.rst:4401 msgid "" "A length modifier (``h``, ``l``, or ``L``) may be present, but is ignored as " "it is not necessary for Python -- so e.g. ``%ld`` is identical to ``%d``." msgstr "" -#: ../../library/stdtypes.rst:3110 ../../library/stdtypes.rst:4370 +#: ../../library/stdtypes.rst:3144 ../../library/stdtypes.rst:4404 msgid "The conversion types are:" msgstr "" -#: ../../library/stdtypes.rst:3113 ../../library/stdtypes.rst:4373 +#: ../../library/stdtypes.rst:3147 ../../library/stdtypes.rst:4407 msgid "Conversion" msgstr "" -#: ../../library/stdtypes.rst:3115 ../../library/stdtypes.rst:4375 +#: ../../library/stdtypes.rst:3149 ../../library/stdtypes.rst:4409 msgid "``'d'``" msgstr "``'d'``" -#: ../../library/stdtypes.rst:3115 ../../library/stdtypes.rst:3117 -#: ../../library/stdtypes.rst:4375 ../../library/stdtypes.rst:4377 +#: ../../library/stdtypes.rst:3149 ../../library/stdtypes.rst:3151 +#: ../../library/stdtypes.rst:4409 ../../library/stdtypes.rst:4411 msgid "Signed integer decimal." msgstr "" -#: ../../library/stdtypes.rst:3117 ../../library/stdtypes.rst:4377 +#: ../../library/stdtypes.rst:3151 ../../library/stdtypes.rst:4411 msgid "``'i'``" msgstr "``'i'``" -#: ../../library/stdtypes.rst:3119 ../../library/stdtypes.rst:4379 +#: ../../library/stdtypes.rst:3153 ../../library/stdtypes.rst:4413 msgid "``'o'``" msgstr "``'o'``" -#: ../../library/stdtypes.rst:3119 ../../library/stdtypes.rst:4379 +#: ../../library/stdtypes.rst:3153 ../../library/stdtypes.rst:4413 msgid "Signed octal value." msgstr "" -#: ../../library/stdtypes.rst:3121 ../../library/stdtypes.rst:4381 +#: ../../library/stdtypes.rst:3155 ../../library/stdtypes.rst:4415 msgid "``'u'``" msgstr "``'u'``" -#: ../../library/stdtypes.rst:3121 ../../library/stdtypes.rst:4381 +#: ../../library/stdtypes.rst:3155 ../../library/stdtypes.rst:4415 msgid "Obsolete type -- it is identical to ``'d'``." msgstr "" -#: ../../library/stdtypes.rst:3123 ../../library/stdtypes.rst:4383 +#: ../../library/stdtypes.rst:3157 ../../library/stdtypes.rst:4417 msgid "``'x'``" msgstr "``'x'``" -#: ../../library/stdtypes.rst:3123 ../../library/stdtypes.rst:4383 +#: ../../library/stdtypes.rst:3157 ../../library/stdtypes.rst:4417 msgid "Signed hexadecimal (lowercase)." msgstr "" -#: ../../library/stdtypes.rst:3125 ../../library/stdtypes.rst:4385 +#: ../../library/stdtypes.rst:3159 ../../library/stdtypes.rst:4419 msgid "``'X'``" msgstr "``'X'``" -#: ../../library/stdtypes.rst:3125 ../../library/stdtypes.rst:4385 +#: ../../library/stdtypes.rst:3159 ../../library/stdtypes.rst:4419 msgid "Signed hexadecimal (uppercase)." msgstr "" -#: ../../library/stdtypes.rst:3127 ../../library/stdtypes.rst:4387 +#: ../../library/stdtypes.rst:3161 ../../library/stdtypes.rst:4421 msgid "``'e'``" msgstr "``'e'``" -#: ../../library/stdtypes.rst:3127 ../../library/stdtypes.rst:4387 +#: ../../library/stdtypes.rst:3161 ../../library/stdtypes.rst:4421 msgid "Floating-point exponential format (lowercase)." msgstr "" -#: ../../library/stdtypes.rst:3129 ../../library/stdtypes.rst:4389 +#: ../../library/stdtypes.rst:3163 ../../library/stdtypes.rst:4423 msgid "``'E'``" msgstr "``'E'``" -#: ../../library/stdtypes.rst:3129 ../../library/stdtypes.rst:4389 +#: ../../library/stdtypes.rst:3163 ../../library/stdtypes.rst:4423 msgid "Floating-point exponential format (uppercase)." msgstr "" -#: ../../library/stdtypes.rst:3131 ../../library/stdtypes.rst:4391 +#: ../../library/stdtypes.rst:3165 ../../library/stdtypes.rst:4425 msgid "``'f'``" msgstr "``'f'``" -#: ../../library/stdtypes.rst:3131 ../../library/stdtypes.rst:3133 -#: ../../library/stdtypes.rst:4391 ../../library/stdtypes.rst:4393 +#: ../../library/stdtypes.rst:3165 ../../library/stdtypes.rst:3167 +#: ../../library/stdtypes.rst:4425 ../../library/stdtypes.rst:4427 msgid "Floating-point decimal format." msgstr "" -#: ../../library/stdtypes.rst:3133 ../../library/stdtypes.rst:4393 +#: ../../library/stdtypes.rst:3167 ../../library/stdtypes.rst:4427 msgid "``'F'``" msgstr "``'F'``" -#: ../../library/stdtypes.rst:3135 ../../library/stdtypes.rst:4395 +#: ../../library/stdtypes.rst:3169 ../../library/stdtypes.rst:4429 msgid "``'g'``" msgstr "``'g'``" -#: ../../library/stdtypes.rst:3135 ../../library/stdtypes.rst:4395 +#: ../../library/stdtypes.rst:3169 ../../library/stdtypes.rst:4429 msgid "" "Floating-point format. Uses lowercase exponential format if exponent is less " "than -4 or not less than precision, decimal format otherwise." msgstr "" -#: ../../library/stdtypes.rst:3139 ../../library/stdtypes.rst:4399 +#: ../../library/stdtypes.rst:3173 ../../library/stdtypes.rst:4433 msgid "``'G'``" msgstr "``'G'``" -#: ../../library/stdtypes.rst:3139 ../../library/stdtypes.rst:4399 +#: ../../library/stdtypes.rst:3173 ../../library/stdtypes.rst:4433 msgid "" "Floating-point format. Uses uppercase exponential format if exponent is less " "than -4 or not less than precision, decimal format otherwise." msgstr "" -#: ../../library/stdtypes.rst:3143 ../../library/stdtypes.rst:4403 +#: ../../library/stdtypes.rst:3177 ../../library/stdtypes.rst:4437 msgid "``'c'``" msgstr "``'c'``" -#: ../../library/stdtypes.rst:3143 +#: ../../library/stdtypes.rst:3177 msgid "Single character (accepts integer or single character string)." msgstr "" -#: ../../library/stdtypes.rst:3146 ../../library/stdtypes.rst:4416 +#: ../../library/stdtypes.rst:3180 ../../library/stdtypes.rst:4450 msgid "``'r'``" msgstr "``'r'``" -#: ../../library/stdtypes.rst:3146 +#: ../../library/stdtypes.rst:3180 msgid "String (converts any Python object using :func:`repr`)." msgstr "" -#: ../../library/stdtypes.rst:3149 ../../library/stdtypes.rst:4410 +#: ../../library/stdtypes.rst:3183 ../../library/stdtypes.rst:4444 msgid "``'s'``" msgstr "``'s'``" -#: ../../library/stdtypes.rst:3149 +#: ../../library/stdtypes.rst:3183 msgid "String (converts any Python object using :func:`str`)." msgstr "" -#: ../../library/stdtypes.rst:3152 ../../library/stdtypes.rst:4413 +#: ../../library/stdtypes.rst:3186 ../../library/stdtypes.rst:4447 msgid "``'a'``" msgstr "``'a'``" -#: ../../library/stdtypes.rst:3152 +#: ../../library/stdtypes.rst:3186 msgid "String (converts any Python object using :func:`ascii`)." msgstr "" -#: ../../library/stdtypes.rst:3155 ../../library/stdtypes.rst:4419 +#: ../../library/stdtypes.rst:3189 ../../library/stdtypes.rst:4453 msgid "``'%'``" msgstr "``'%'``" -#: ../../library/stdtypes.rst:3155 ../../library/stdtypes.rst:4419 +#: ../../library/stdtypes.rst:3189 ../../library/stdtypes.rst:4453 msgid "No argument is converted, results in a ``'%'`` character in the result." msgstr "" -#: ../../library/stdtypes.rst:3162 ../../library/stdtypes.rst:4426 +#: ../../library/stdtypes.rst:3196 ../../library/stdtypes.rst:4460 msgid "" "The alternate form causes a leading octal specifier (``'0o'``) to be " "inserted before the first digit." msgstr "" -#: ../../library/stdtypes.rst:3166 ../../library/stdtypes.rst:4430 +#: ../../library/stdtypes.rst:3200 ../../library/stdtypes.rst:4464 msgid "" "The alternate form causes a leading ``'0x'`` or ``'0X'`` (depending on " "whether the ``'x'`` or ``'X'`` format was used) to be inserted before the " "first digit." msgstr "" -#: ../../library/stdtypes.rst:3170 ../../library/stdtypes.rst:4434 +#: ../../library/stdtypes.rst:3204 ../../library/stdtypes.rst:4468 msgid "" "The alternate form causes the result to always contain a decimal point, even " "if no digits follow it." msgstr "" -#: ../../library/stdtypes.rst:3173 ../../library/stdtypes.rst:4437 +#: ../../library/stdtypes.rst:3207 ../../library/stdtypes.rst:4471 msgid "" "The precision determines the number of digits after the decimal point and " "defaults to 6." msgstr "" -#: ../../library/stdtypes.rst:3177 ../../library/stdtypes.rst:4441 +#: ../../library/stdtypes.rst:3211 ../../library/stdtypes.rst:4475 msgid "" "The alternate form causes the result to always contain a decimal point, and " "trailing zeroes are not removed as they would otherwise be." msgstr "" -#: ../../library/stdtypes.rst:3180 ../../library/stdtypes.rst:4444 +#: ../../library/stdtypes.rst:3214 ../../library/stdtypes.rst:4478 msgid "" "The precision determines the number of significant digits before and after " "the decimal point and defaults to 6." msgstr "" -#: ../../library/stdtypes.rst:3184 ../../library/stdtypes.rst:4448 +#: ../../library/stdtypes.rst:3218 ../../library/stdtypes.rst:4482 msgid "If precision is ``N``, the output is truncated to ``N`` characters." msgstr "" -#: ../../library/stdtypes.rst:3187 ../../library/stdtypes.rst:4457 +#: ../../library/stdtypes.rst:3221 ../../library/stdtypes.rst:4491 msgid "See :pep:`237`." msgstr "參閱 :pep:`237`。" -#: ../../library/stdtypes.rst:3189 +#: ../../library/stdtypes.rst:3223 msgid "" "Since Python strings have an explicit length, ``%s`` conversions do not " "assume that ``'\\0'`` is the end of the string." msgstr "" -#: ../../library/stdtypes.rst:3194 +#: ../../library/stdtypes.rst:3228 msgid "" "``%f`` conversions for numbers whose absolute value is over 1e50 are no " "longer replaced by ``%g`` conversions." msgstr "" -#: ../../library/stdtypes.rst:3205 +#: ../../library/stdtypes.rst:3239 msgid "" "Binary Sequence Types --- :class:`bytes`, :class:`bytearray`, :class:" "`memoryview`" msgstr "" -#: ../../library/stdtypes.rst:3213 +#: ../../library/stdtypes.rst:3247 msgid "" "The core built-in types for manipulating binary data are :class:`bytes` and :" "class:`bytearray`. They are supported by :class:`memoryview` which uses the :" @@ -5113,17 +5169,17 @@ msgid "" "objects without needing to make a copy." msgstr "" -#: ../../library/stdtypes.rst:3218 +#: ../../library/stdtypes.rst:3252 msgid "" "The :mod:`array` module supports efficient storage of basic data types like " "32-bit integers and IEEE754 double-precision floating values." msgstr "" -#: ../../library/stdtypes.rst:3224 +#: ../../library/stdtypes.rst:3258 msgid "Bytes Objects" msgstr "" -#: ../../library/stdtypes.rst:3228 +#: ../../library/stdtypes.rst:3262 msgid "" "Bytes objects are immutable sequences of single bytes. Since many major " "binary protocols are based on the ASCII text encoding, bytes objects offer " @@ -5131,40 +5187,40 @@ msgid "" "and are closely related to string objects in a variety of other ways." msgstr "" -#: ../../library/stdtypes.rst:3236 +#: ../../library/stdtypes.rst:3270 msgid "" "Firstly, the syntax for bytes literals is largely the same as that for " "string literals, except that a ``b`` prefix is added:" msgstr "" -#: ../../library/stdtypes.rst:3239 +#: ../../library/stdtypes.rst:3273 msgid "Single quotes: ``b'still allows embedded \"double\" quotes'``" msgstr "" -#: ../../library/stdtypes.rst:3240 +#: ../../library/stdtypes.rst:3274 msgid "Double quotes: ``b\"still allows embedded 'single' quotes\"``" msgstr "" -#: ../../library/stdtypes.rst:3241 +#: ../../library/stdtypes.rst:3275 msgid "" "Triple quoted: ``b'''3 single quotes'''``, ``b\"\"\"3 double quotes\"\"\"``" msgstr "" -#: ../../library/stdtypes.rst:3243 +#: ../../library/stdtypes.rst:3277 msgid "" "Only ASCII characters are permitted in bytes literals (regardless of the " "declared source code encoding). Any binary values over 127 must be entered " "into bytes literals using the appropriate escape sequence." msgstr "" -#: ../../library/stdtypes.rst:3247 +#: ../../library/stdtypes.rst:3281 msgid "" "As with string literals, bytes literals may also use a ``r`` prefix to " "disable processing of escape sequences. See :ref:`strings` for more about " "the various forms of bytes literal, including supported escape sequences." msgstr "" -#: ../../library/stdtypes.rst:3251 +#: ../../library/stdtypes.rst:3285 msgid "" "While bytes literals and representations are based on ASCII text, bytes " "objects actually behave like immutable sequences of integers, with each " @@ -5177,29 +5233,29 @@ msgid "" "compatible will usually lead to data corruption)." msgstr "" -#: ../../library/stdtypes.rst:3261 +#: ../../library/stdtypes.rst:3295 msgid "" "In addition to the literal forms, bytes objects can be created in a number " "of other ways:" msgstr "" -#: ../../library/stdtypes.rst:3264 +#: ../../library/stdtypes.rst:3298 msgid "A zero-filled bytes object of a specified length: ``bytes(10)``" msgstr "" -#: ../../library/stdtypes.rst:3265 +#: ../../library/stdtypes.rst:3299 msgid "From an iterable of integers: ``bytes(range(20))``" msgstr "" -#: ../../library/stdtypes.rst:3266 +#: ../../library/stdtypes.rst:3300 msgid "Copying existing binary data via the buffer protocol: ``bytes(obj)``" msgstr "" -#: ../../library/stdtypes.rst:3268 +#: ../../library/stdtypes.rst:3302 msgid "Also see the :ref:`bytes ` built-in." msgstr "另見內建的 :ref:`bytes `。" -#: ../../library/stdtypes.rst:3270 +#: ../../library/stdtypes.rst:3304 msgid "" "Since 2 hexadecimal digits correspond precisely to a single byte, " "hexadecimal numbers are a commonly used format for describing binary data. " @@ -5207,38 +5263,38 @@ msgid "" "that format:" msgstr "" -#: ../../library/stdtypes.rst:3276 +#: ../../library/stdtypes.rst:3310 msgid "" "This :class:`bytes` class method returns a bytes object, decoding the given " "string object. The string must contain two hexadecimal digits per byte, " "with ASCII whitespace being ignored." msgstr "" -#: ../../library/stdtypes.rst:3283 +#: ../../library/stdtypes.rst:3317 msgid "" ":meth:`bytes.fromhex` now skips all ASCII whitespace in the string, not just " "spaces." msgstr "" -#: ../../library/stdtypes.rst:3287 +#: ../../library/stdtypes.rst:3321 msgid "" ":meth:`bytes.fromhex` now accepts ASCII :class:`bytes` and :term:`bytes-like " "objects ` as input." msgstr "" -#: ../../library/stdtypes.rst:3291 +#: ../../library/stdtypes.rst:3325 msgid "" "A reverse conversion function exists to transform a bytes object into its " "hexadecimal representation." msgstr "" -#: ../../library/stdtypes.rst:3297 ../../library/stdtypes.rst:3388 +#: ../../library/stdtypes.rst:3331 ../../library/stdtypes.rst:3422 msgid "" "Return a string object containing two hexadecimal digits for each byte in " "the instance." msgstr "" -#: ../../library/stdtypes.rst:3303 +#: ../../library/stdtypes.rst:3337 msgid "" "If you want to make the hex string easier to read, you can specify a single " "character separator *sep* parameter to include in the output. By default, " @@ -5247,13 +5303,13 @@ msgid "" "the separator position from the right, negative values from the left." msgstr "" -#: ../../library/stdtypes.rst:3320 +#: ../../library/stdtypes.rst:3354 msgid "" ":meth:`bytes.hex` now supports optional *sep* and *bytes_per_sep* parameters " "to insert separators between bytes in the hex output." msgstr "" -#: ../../library/stdtypes.rst:3324 +#: ../../library/stdtypes.rst:3358 msgid "" "Since bytes objects are sequences of integers (akin to a tuple), for a bytes " "object *b*, ``b[0]`` will be an integer, while ``b[0:1]`` will be a bytes " @@ -5261,58 +5317,58 @@ msgid "" "and slicing will produce a string of length 1)" msgstr "" -#: ../../library/stdtypes.rst:3329 +#: ../../library/stdtypes.rst:3363 msgid "" "The representation of bytes objects uses the literal format (``b'...'``) " "since it is often more useful than e.g. ``bytes([46, 46, 46])``. You can " "always convert a bytes object into a list of integers using ``list(b)``." msgstr "" -#: ../../library/stdtypes.rst:3337 +#: ../../library/stdtypes.rst:3371 msgid "Bytearray Objects" msgstr "Bytearray 物件" -#: ../../library/stdtypes.rst:3341 +#: ../../library/stdtypes.rst:3375 msgid "" ":class:`bytearray` objects are a mutable counterpart to :class:`bytes` " "objects." msgstr "" -#: ../../library/stdtypes.rst:3347 +#: ../../library/stdtypes.rst:3381 msgid "" "There is no dedicated literal syntax for bytearray objects, instead they are " "always created by calling the constructor:" msgstr "" -#: ../../library/stdtypes.rst:3350 +#: ../../library/stdtypes.rst:3384 msgid "Creating an empty instance: ``bytearray()``" msgstr "建立一個空的實例:``bytearray()``" -#: ../../library/stdtypes.rst:3351 +#: ../../library/stdtypes.rst:3385 msgid "Creating a zero-filled instance with a given length: ``bytearray(10)``" msgstr "" -#: ../../library/stdtypes.rst:3352 +#: ../../library/stdtypes.rst:3386 msgid "From an iterable of integers: ``bytearray(range(20))``" msgstr "" -#: ../../library/stdtypes.rst:3353 +#: ../../library/stdtypes.rst:3387 msgid "" "Copying existing binary data via the buffer protocol: ``bytearray(b'Hi!')``" msgstr "" -#: ../../library/stdtypes.rst:3355 +#: ../../library/stdtypes.rst:3389 msgid "" "As bytearray objects are mutable, they support the :ref:`mutable ` sequence operations in addition to the common bytes and bytearray " "operations described in :ref:`bytes-methods`." msgstr "" -#: ../../library/stdtypes.rst:3359 +#: ../../library/stdtypes.rst:3393 msgid "Also see the :ref:`bytearray ` built-in." msgstr "另見內建的 :ref:`bytearray `。" -#: ../../library/stdtypes.rst:3361 +#: ../../library/stdtypes.rst:3395 msgid "" "Since 2 hexadecimal digits correspond precisely to a single byte, " "hexadecimal numbers are a commonly used format for describing binary data. " @@ -5320,64 +5376,64 @@ msgid "" "in that format:" msgstr "" -#: ../../library/stdtypes.rst:3367 +#: ../../library/stdtypes.rst:3401 msgid "" "This :class:`bytearray` class method returns bytearray object, decoding the " "given string object. The string must contain two hexadecimal digits per " "byte, with ASCII whitespace being ignored." msgstr "" -#: ../../library/stdtypes.rst:3374 +#: ../../library/stdtypes.rst:3408 msgid "" ":meth:`bytearray.fromhex` now skips all ASCII whitespace in the string, not " "just spaces." msgstr "" -#: ../../library/stdtypes.rst:3378 +#: ../../library/stdtypes.rst:3412 msgid "" ":meth:`bytearray.fromhex` now accepts ASCII :class:`bytes` and :term:`bytes-" "like objects ` as input." msgstr "" -#: ../../library/stdtypes.rst:3382 +#: ../../library/stdtypes.rst:3416 msgid "" "A reverse conversion function exists to transform a bytearray object into " "its hexadecimal representation." msgstr "" -#: ../../library/stdtypes.rst:3396 +#: ../../library/stdtypes.rst:3430 msgid "" "Similar to :meth:`bytes.hex`, :meth:`bytearray.hex` now supports optional " "*sep* and *bytes_per_sep* parameters to insert separators between bytes in " "the hex output." msgstr "" -#: ../../library/stdtypes.rst:3403 +#: ../../library/stdtypes.rst:3437 msgid "" "Resize the :class:`bytearray` to contain *size* bytes. *size* must be " "greater than or equal to 0." msgstr "" -#: ../../library/stdtypes.rst:3406 +#: ../../library/stdtypes.rst:3440 msgid "" "If the :class:`bytearray` needs to shrink, bytes beyond *size* are truncated." msgstr "" -#: ../../library/stdtypes.rst:3408 +#: ../../library/stdtypes.rst:3442 msgid "" "If the :class:`bytearray` needs to grow, all new bytes, those beyond *size*, " "will be set to null bytes." msgstr "" -#: ../../library/stdtypes.rst:3412 +#: ../../library/stdtypes.rst:3446 msgid "This is equivalent to:" msgstr "等同於:" -#: ../../library/stdtypes.rst:3420 +#: ../../library/stdtypes.rst:3454 msgid "Examples:" msgstr "範例:" -#: ../../library/stdtypes.rst:3433 +#: ../../library/stdtypes.rst:3467 msgid "" "Since bytearray objects are sequences of integers (akin to a list), for a " "bytearray object *b*, ``b[0]`` will be an integer, while ``b[0:1]`` will be " @@ -5385,7 +5441,7 @@ msgid "" "both indexing and slicing will produce a string of length 1)" msgstr "" -#: ../../library/stdtypes.rst:3438 +#: ../../library/stdtypes.rst:3472 msgid "" "The representation of bytearray objects uses the bytes literal format " "(``bytearray(b'...')``) since it is often more useful than e.g. " @@ -5393,11 +5449,11 @@ msgid "" "a list of integers using ``list(b)``." msgstr "" -#: ../../library/stdtypes.rst:3447 +#: ../../library/stdtypes.rst:3481 msgid "Bytes and Bytearray Operations" msgstr "Bytes 和 Bytearray 的操作" -#: ../../library/stdtypes.rst:3452 +#: ../../library/stdtypes.rst:3486 msgid "" "Both bytes and bytearray objects support the :ref:`common ` " "sequence operations. They interoperate not just with operands of the same " @@ -5406,14 +5462,14 @@ msgid "" "return type of the result may depend on the order of operands." msgstr "" -#: ../../library/stdtypes.rst:3460 +#: ../../library/stdtypes.rst:3494 msgid "" "The methods on bytes and bytearray objects don't accept strings as their " "arguments, just as the methods on strings don't accept bytes as their " "arguments. For example, you have to write::" msgstr "" -#: ../../library/stdtypes.rst:3464 +#: ../../library/stdtypes.rst:3498 msgid "" "a = \"abc\"\n" "b = a.replace(\"a\", \"f\")" @@ -5421,11 +5477,11 @@ msgstr "" "a = \"abc\"\n" "b = a.replace(\"a\", \"f\")" -#: ../../library/stdtypes.rst:3467 +#: ../../library/stdtypes.rst:3501 msgid "and::" msgstr "和: ::" -#: ../../library/stdtypes.rst:3469 +#: ../../library/stdtypes.rst:3503 msgid "" "a = b\"abc\"\n" "b = a.replace(b\"a\", b\"f\")" @@ -5433,60 +5489,60 @@ msgstr "" "a = b\"abc\"\n" "b = a.replace(b\"a\", b\"f\")" -#: ../../library/stdtypes.rst:3472 +#: ../../library/stdtypes.rst:3506 msgid "" "Some bytes and bytearray operations assume the use of ASCII compatible " "binary formats, and hence should be avoided when working with arbitrary " "binary data. These restrictions are covered below." msgstr "" -#: ../../library/stdtypes.rst:3477 +#: ../../library/stdtypes.rst:3511 msgid "" "Using these ASCII based operations to manipulate binary data that is not " "stored in an ASCII based format may lead to data corruption." msgstr "" -#: ../../library/stdtypes.rst:3480 +#: ../../library/stdtypes.rst:3514 msgid "" "The following methods on bytes and bytearray objects can be used with " "arbitrary binary data." msgstr "" -#: ../../library/stdtypes.rst:3486 +#: ../../library/stdtypes.rst:3520 msgid "" "Return the number of non-overlapping occurrences of subsequence *sub* in the " "range [*start*, *end*]. Optional arguments *start* and *end* are " "interpreted as in slice notation." msgstr "" -#: ../../library/stdtypes.rst:3490 ../../library/stdtypes.rst:3595 -#: ../../library/stdtypes.rst:3617 ../../library/stdtypes.rst:3683 -#: ../../library/stdtypes.rst:3696 +#: ../../library/stdtypes.rst:3524 ../../library/stdtypes.rst:3629 +#: ../../library/stdtypes.rst:3651 ../../library/stdtypes.rst:3717 +#: ../../library/stdtypes.rst:3730 msgid "" "The subsequence to search for may be any :term:`bytes-like object` or an " "integer in the range 0 to 255." msgstr "" -#: ../../library/stdtypes.rst:3493 +#: ../../library/stdtypes.rst:3527 msgid "" "If *sub* is empty, returns the number of empty slices between characters " "which is the length of the bytes object plus one." msgstr "" -#: ../../library/stdtypes.rst:3496 ../../library/stdtypes.rst:3607 -#: ../../library/stdtypes.rst:3620 ../../library/stdtypes.rst:3686 -#: ../../library/stdtypes.rst:3699 +#: ../../library/stdtypes.rst:3530 ../../library/stdtypes.rst:3641 +#: ../../library/stdtypes.rst:3654 ../../library/stdtypes.rst:3720 +#: ../../library/stdtypes.rst:3733 msgid "Also accept an integer in the range 0 to 255 as the subsequence." msgstr "" -#: ../../library/stdtypes.rst:3503 +#: ../../library/stdtypes.rst:3537 msgid "" "If the binary data starts with the *prefix* string, return " "``bytes[len(prefix):]``. Otherwise, return a copy of the original binary " "data::" msgstr "" -#: ../../library/stdtypes.rst:3507 +#: ../../library/stdtypes.rst:3541 msgid "" ">>> b'TestHook'.removeprefix(b'Test')\n" "b'Hook'\n" @@ -5498,32 +5554,32 @@ msgstr "" ">>> b'BaseTestCase'.removeprefix(b'Test')\n" "b'BaseTestCase'" -#: ../../library/stdtypes.rst:3512 +#: ../../library/stdtypes.rst:3546 msgid "The *prefix* may be any :term:`bytes-like object`." msgstr "*prefix* 可以是任何的 :term:`bytes-like object`。" -#: ../../library/stdtypes.rst:3516 ../../library/stdtypes.rst:3538 -#: ../../library/stdtypes.rst:3671 ../../library/stdtypes.rst:3764 -#: ../../library/stdtypes.rst:3778 ../../library/stdtypes.rst:3808 -#: ../../library/stdtypes.rst:3822 ../../library/stdtypes.rst:3863 -#: ../../library/stdtypes.rst:3933 ../../library/stdtypes.rst:3951 -#: ../../library/stdtypes.rst:3979 ../../library/stdtypes.rst:4118 -#: ../../library/stdtypes.rst:4173 ../../library/stdtypes.rst:4216 -#: ../../library/stdtypes.rst:4237 ../../library/stdtypes.rst:4259 -#: ../../library/stdtypes.rst:4461 +#: ../../library/stdtypes.rst:3550 ../../library/stdtypes.rst:3572 +#: ../../library/stdtypes.rst:3705 ../../library/stdtypes.rst:3798 +#: ../../library/stdtypes.rst:3812 ../../library/stdtypes.rst:3842 +#: ../../library/stdtypes.rst:3856 ../../library/stdtypes.rst:3897 +#: ../../library/stdtypes.rst:3967 ../../library/stdtypes.rst:3985 +#: ../../library/stdtypes.rst:4013 ../../library/stdtypes.rst:4152 +#: ../../library/stdtypes.rst:4207 ../../library/stdtypes.rst:4250 +#: ../../library/stdtypes.rst:4271 ../../library/stdtypes.rst:4293 +#: ../../library/stdtypes.rst:4495 msgid "" "The bytearray version of this method does *not* operate in place - it always " "produces a new object, even if no changes were made." msgstr "" -#: ../../library/stdtypes.rst:3525 +#: ../../library/stdtypes.rst:3559 msgid "" "If the binary data ends with the *suffix* string and that *suffix* is not " "empty, return ``bytes[:-len(suffix)]``. Otherwise, return a copy of the " "original binary data::" msgstr "" -#: ../../library/stdtypes.rst:3529 +#: ../../library/stdtypes.rst:3563 msgid "" ">>> b'MiscTests'.removesuffix(b'Tests')\n" "b'Misc'\n" @@ -5535,15 +5591,15 @@ msgstr "" ">>> b'TmpDirMixin'.removesuffix(b'Tests')\n" "b'TmpDirMixin'" -#: ../../library/stdtypes.rst:3534 +#: ../../library/stdtypes.rst:3568 msgid "The *suffix* may be any :term:`bytes-like object`." msgstr "" -#: ../../library/stdtypes.rst:3547 +#: ../../library/stdtypes.rst:3581 msgid "Return the bytes decoded to a :class:`str`." msgstr "" -#: ../../library/stdtypes.rst:3552 +#: ../../library/stdtypes.rst:3586 msgid "" "*errors* controls how decoding errors are handled. If ``'strict'`` (the " "default), a :exc:`UnicodeError` exception is raised. Other possible values " @@ -5551,21 +5607,21 @@ msgid "" "`codecs.register_error`. See :ref:`error-handlers` for details." msgstr "" -#: ../../library/stdtypes.rst:3558 +#: ../../library/stdtypes.rst:3592 msgid "" "For performance reasons, the value of *errors* is not checked for validity " "unless a decoding error actually occurs, :ref:`devmode` is enabled or a :ref:" "`debug build ` is used." msgstr "" -#: ../../library/stdtypes.rst:3564 +#: ../../library/stdtypes.rst:3598 msgid "" "Passing the *encoding* argument to :class:`str` allows decoding any :term:" "`bytes-like object` directly, without needing to make a temporary :class:`!" "bytes` or :class:`!bytearray` object." msgstr "" -#: ../../library/stdtypes.rst:3579 +#: ../../library/stdtypes.rst:3613 msgid "" "Return ``True`` if the binary data ends with the specified *suffix*, " "otherwise return ``False``. *suffix* can also be a tuple of suffixes to " @@ -5573,11 +5629,11 @@ msgid "" "optional *end*, stop comparing at that position." msgstr "" -#: ../../library/stdtypes.rst:3584 +#: ../../library/stdtypes.rst:3618 msgid "The suffix(es) to search for may be any :term:`bytes-like object`." msgstr "" -#: ../../library/stdtypes.rst:3590 +#: ../../library/stdtypes.rst:3624 msgid "" "Return the lowest index in the data where the subsequence *sub* is found, " "such that *sub* is contained in the slice ``s[start:end]``. Optional " @@ -5585,14 +5641,14 @@ msgid "" "``-1`` if *sub* is not found." msgstr "" -#: ../../library/stdtypes.rst:3600 +#: ../../library/stdtypes.rst:3634 msgid "" "The :meth:`~bytes.find` method should be used only if you need to know the " "position of *sub*. To check if *sub* is a substring or not, use the :" "keyword:`in` operator::" msgstr "" -#: ../../library/stdtypes.rst:3604 +#: ../../library/stdtypes.rst:3638 msgid "" ">>> b'Py' in b'Python'\n" "True" @@ -5600,13 +5656,13 @@ msgstr "" ">>> b'Py' in b'Python'\n" "True" -#: ../../library/stdtypes.rst:3614 +#: ../../library/stdtypes.rst:3648 msgid "" "Like :meth:`~bytes.find`, but raise :exc:`ValueError` when the subsequence " "is not found." msgstr "" -#: ../../library/stdtypes.rst:3627 +#: ../../library/stdtypes.rst:3661 msgid "" "Return a bytes or bytearray object which is the concatenation of the binary " "data sequences in *iterable*. A :exc:`TypeError` will be raised if there " @@ -5616,7 +5672,7 @@ msgid "" "method." msgstr "" -#: ../../library/stdtypes.rst:3638 +#: ../../library/stdtypes.rst:3672 msgid "" "This static method returns a translation table usable for :meth:`bytes." "translate` that will map each character in *from* into the character at the " @@ -5624,7 +5680,7 @@ msgid "" "objects ` and have the same length." msgstr "" -#: ../../library/stdtypes.rst:3649 +#: ../../library/stdtypes.rst:3683 msgid "" "Split the sequence at the first occurrence of *sep*, and return a 3-tuple " "containing the part before the separator, the separator itself or its " @@ -5633,24 +5689,24 @@ msgid "" "by two empty bytes or bytearray objects." msgstr "" -#: ../../library/stdtypes.rst:3656 ../../library/stdtypes.rst:3713 +#: ../../library/stdtypes.rst:3690 ../../library/stdtypes.rst:3747 msgid "The separator to search for may be any :term:`bytes-like object`." msgstr "" -#: ../../library/stdtypes.rst:3662 +#: ../../library/stdtypes.rst:3696 msgid "" "Return a copy of the sequence with all occurrences of subsequence *old* " "replaced by *new*. If the optional argument *count* is given, only the " "first *count* occurrences are replaced." msgstr "" -#: ../../library/stdtypes.rst:3666 +#: ../../library/stdtypes.rst:3700 msgid "" "The subsequence to search for and its replacement may be any :term:`bytes-" "like object`." msgstr "" -#: ../../library/stdtypes.rst:3678 +#: ../../library/stdtypes.rst:3712 msgid "" "Return the highest index in the sequence where the subsequence *sub* is " "found, such that *sub* is contained within ``s[start:end]``. Optional " @@ -5658,13 +5714,13 @@ msgid "" "``-1`` on failure." msgstr "" -#: ../../library/stdtypes.rst:3693 +#: ../../library/stdtypes.rst:3727 msgid "" "Like :meth:`~bytes.rfind` but raises :exc:`ValueError` when the subsequence " "*sub* is not found." msgstr "" -#: ../../library/stdtypes.rst:3706 +#: ../../library/stdtypes.rst:3740 msgid "" "Split the sequence at the last occurrence of *sep*, and return a 3-tuple " "containing the part before the separator, the separator itself or its " @@ -5673,7 +5729,7 @@ msgid "" "followed by a copy of the original sequence." msgstr "" -#: ../../library/stdtypes.rst:3719 +#: ../../library/stdtypes.rst:3753 msgid "" "Return ``True`` if the binary data starts with the specified *prefix*, " "otherwise return ``False``. *prefix* can also be a tuple of prefixes to " @@ -5681,11 +5737,11 @@ msgid "" "optional *end*, stop comparing at that position." msgstr "" -#: ../../library/stdtypes.rst:3724 +#: ../../library/stdtypes.rst:3758 msgid "The prefix(es) to search for may be any :term:`bytes-like object`." msgstr "" -#: ../../library/stdtypes.rst:3730 +#: ../../library/stdtypes.rst:3764 msgid "" "Return a copy of the bytes or bytearray object where all bytes occurring in " "the optional argument *delete* are removed, and the remaining bytes have " @@ -5693,18 +5749,18 @@ msgid "" "object of length 256." msgstr "" -#: ../../library/stdtypes.rst:3735 +#: ../../library/stdtypes.rst:3769 msgid "" "You can use the :func:`bytes.maketrans` method to create a translation table." msgstr "" -#: ../../library/stdtypes.rst:3738 +#: ../../library/stdtypes.rst:3772 msgid "" "Set the *table* argument to ``None`` for translations that only delete " "characters::" msgstr "" -#: ../../library/stdtypes.rst:3741 +#: ../../library/stdtypes.rst:3775 msgid "" ">>> b'read this short text'.translate(None, b'aeiou')\n" "b'rd ths shrt txt'" @@ -5712,11 +5768,11 @@ msgstr "" ">>> b'read this short text'.translate(None, b'aeiou')\n" "b'rd ths shrt txt'" -#: ../../library/stdtypes.rst:3744 +#: ../../library/stdtypes.rst:3778 msgid "*delete* is now supported as a keyword argument." msgstr "支援 *delete* 關鍵字引數。" -#: ../../library/stdtypes.rst:3748 +#: ../../library/stdtypes.rst:3782 msgid "" "The following methods on bytes and bytearray objects have default behaviours " "that assume the use of ASCII compatible binary formats, but can still be " @@ -5725,7 +5781,7 @@ msgid "" "instead produce new objects." msgstr "" -#: ../../library/stdtypes.rst:3757 +#: ../../library/stdtypes.rst:3791 msgid "" "Return a copy of the object centered in a sequence of length *width*. " "Padding is done using the specified *fillbyte* (default is an ASCII space). " @@ -5733,7 +5789,7 @@ msgid "" "less than or equal to ``len(s)``." msgstr "" -#: ../../library/stdtypes.rst:3771 +#: ../../library/stdtypes.rst:3805 msgid "" "Return a copy of the object left justified in a sequence of length *width*. " "Padding is done using the specified *fillbyte* (default is an ASCII space). " @@ -5741,7 +5797,7 @@ msgid "" "less than or equal to ``len(s)``." msgstr "" -#: ../../library/stdtypes.rst:3785 +#: ../../library/stdtypes.rst:3819 msgid "" "Return a copy of the sequence with specified leading bytes removed. The " "*bytes* argument is a binary sequence specifying the set of byte values to " @@ -5750,7 +5806,7 @@ msgid "" "all combinations of its values are stripped::" msgstr "" -#: ../../library/stdtypes.rst:3791 +#: ../../library/stdtypes.rst:3825 msgid "" ">>> b' spacious '.lstrip()\n" "b'spacious '\n" @@ -5762,14 +5818,14 @@ msgstr "" ">>> b'www.example.com'.lstrip(b'cmowz.')\n" "b'example.com'" -#: ../../library/stdtypes.rst:3796 +#: ../../library/stdtypes.rst:3830 msgid "" "The binary sequence of byte values to remove may be any :term:`bytes-like " "object`. See :meth:`~bytes.removeprefix` for a method that will remove a " "single prefix string rather than all of a set of characters. For example::" msgstr "" -#: ../../library/stdtypes.rst:3801 +#: ../../library/stdtypes.rst:3835 msgid "" ">>> b'Arthur: three!'.lstrip(b'Arthur: ')\n" "b'ee!'\n" @@ -5781,7 +5837,7 @@ msgstr "" ">>> b'Arthur: three!'.removeprefix(b'Arthur: ')\n" "b'three!'" -#: ../../library/stdtypes.rst:3815 +#: ../../library/stdtypes.rst:3849 msgid "" "Return a copy of the object right justified in a sequence of length *width*. " "Padding is done using the specified *fillbyte* (default is an ASCII space). " @@ -5789,7 +5845,7 @@ msgid "" "less than or equal to ``len(s)``." msgstr "" -#: ../../library/stdtypes.rst:3829 +#: ../../library/stdtypes.rst:3863 msgid "" "Split the binary sequence into subsequences of the same type, using *sep* as " "the delimiter string. If *maxsplit* is given, at most *maxsplit* splits are " @@ -5799,7 +5855,7 @@ msgid "" "described in detail below." msgstr "" -#: ../../library/stdtypes.rst:3840 +#: ../../library/stdtypes.rst:3874 msgid "" "Return a copy of the sequence with specified trailing bytes removed. The " "*bytes* argument is a binary sequence specifying the set of byte values to " @@ -5808,7 +5864,7 @@ msgid "" "all combinations of its values are stripped::" msgstr "" -#: ../../library/stdtypes.rst:3846 +#: ../../library/stdtypes.rst:3880 msgid "" ">>> b' spacious '.rstrip()\n" "b' spacious'\n" @@ -5820,14 +5876,14 @@ msgstr "" ">>> b'mississippi'.rstrip(b'ipz')\n" "b'mississ'" -#: ../../library/stdtypes.rst:3851 +#: ../../library/stdtypes.rst:3885 msgid "" "The binary sequence of byte values to remove may be any :term:`bytes-like " "object`. See :meth:`~bytes.removesuffix` for a method that will remove a " "single suffix string rather than all of a set of characters. For example::" msgstr "" -#: ../../library/stdtypes.rst:3856 +#: ../../library/stdtypes.rst:3890 msgid "" ">>> b'Monty Python'.rstrip(b' Python')\n" "b'M'\n" @@ -5839,7 +5895,7 @@ msgstr "" ">>> b'Monty Python'.removesuffix(b' Python')\n" "b'Monty'" -#: ../../library/stdtypes.rst:3870 +#: ../../library/stdtypes.rst:3904 msgid "" "Split the binary sequence into subsequences of the same type, using *sep* as " "the delimiter string. If *maxsplit* is given and non-negative, at most " @@ -5848,7 +5904,7 @@ msgid "" "limit on the number of splits (all possible splits are made)." msgstr "" -#: ../../library/stdtypes.rst:3876 +#: ../../library/stdtypes.rst:3910 msgid "" "If *sep* is given, consecutive delimiters are not grouped together and are " "deemed to delimit empty subsequences (for example, ``b'1,,2'.split(b',')`` " @@ -5859,7 +5915,7 @@ msgid "" "like object`." msgstr "" -#: ../../library/stdtypes.rst:3886 +#: ../../library/stdtypes.rst:3920 msgid "" ">>> b'1,2,3'.split(b',')\n" "[b'1', b'2', b'3']\n" @@ -5879,7 +5935,7 @@ msgstr "" ">>> b'1<>2<>3<4'.split(b'<>')\n" "[b'1', b'2', b'3<4']" -#: ../../library/stdtypes.rst:3895 +#: ../../library/stdtypes.rst:3929 msgid "" "If *sep* is not specified or is ``None``, a different splitting algorithm is " "applied: runs of consecutive ASCII whitespace are regarded as a single " @@ -5889,7 +5945,7 @@ msgid "" "without a specified separator returns ``[]``." msgstr "" -#: ../../library/stdtypes.rst:3905 +#: ../../library/stdtypes.rst:3939 msgid "" ">>> b'1 2 3'.split()\n" "[b'1', b'2', b'3']\n" @@ -5905,7 +5961,7 @@ msgstr "" ">>> b' 1 2 3 '.split()\n" "[b'1', b'2', b'3']" -#: ../../library/stdtypes.rst:3916 +#: ../../library/stdtypes.rst:3950 msgid "" "Return a copy of the sequence with specified leading and trailing bytes " "removed. The *bytes* argument is a binary sequence specifying the set of " @@ -5914,7 +5970,7 @@ msgid "" "or suffix; rather, all combinations of its values are stripped::" msgstr "" -#: ../../library/stdtypes.rst:3923 +#: ../../library/stdtypes.rst:3957 msgid "" ">>> b' spacious '.strip()\n" "b'spacious'\n" @@ -5926,13 +5982,13 @@ msgstr "" ">>> b'www.example.com'.strip(b'cmowz.')\n" "b'example'" -#: ../../library/stdtypes.rst:3928 +#: ../../library/stdtypes.rst:3962 msgid "" "The binary sequence of byte values to remove may be any :term:`bytes-like " "object`." msgstr "" -#: ../../library/stdtypes.rst:3937 +#: ../../library/stdtypes.rst:3971 msgid "" "The following methods on bytes and bytearray objects assume the use of ASCII " "compatible binary formats and should not be applied to arbitrary binary " @@ -5940,14 +5996,14 @@ msgid "" "operate in place, and instead produce new objects." msgstr "" -#: ../../library/stdtypes.rst:3945 +#: ../../library/stdtypes.rst:3979 msgid "" "Return a copy of the sequence with each byte interpreted as an ASCII " "character, and the first byte capitalized and the rest lowercased. Non-ASCII " "byte values are passed through unchanged." msgstr "" -#: ../../library/stdtypes.rst:3958 +#: ../../library/stdtypes.rst:3992 msgid "" "Return a copy of the sequence where all ASCII tab characters are replaced by " "one or more ASCII spaces, depending on the current column and the given tab " @@ -5963,7 +6019,7 @@ msgid "" "by one regardless of how the byte value is represented when printed::" msgstr "" -#: ../../library/stdtypes.rst:3972 +#: ../../library/stdtypes.rst:4006 msgid "" ">>> b'01\\t012\\t0123\\t01234'.expandtabs()\n" "b'01 012 0123 01234'\n" @@ -5975,7 +6031,7 @@ msgstr "" ">>> b'01\\t012\\t0123\\t01234'.expandtabs(4)\n" "b'01 012 0123 01234'" -#: ../../library/stdtypes.rst:3986 +#: ../../library/stdtypes.rst:4020 msgid "" "Return ``True`` if all bytes in the sequence are alphabetical ASCII " "characters or ASCII decimal digits and the sequence is not empty, ``False`` " @@ -5984,7 +6040,7 @@ msgid "" "digits are those byte values in the sequence ``b'0123456789'``." msgstr "" -#: ../../library/stdtypes.rst:3994 +#: ../../library/stdtypes.rst:4028 msgid "" ">>> b'ABCabc1'.isalnum()\n" "True\n" @@ -5996,7 +6052,7 @@ msgstr "" ">>> b'ABC abc1'.isalnum()\n" "False" -#: ../../library/stdtypes.rst:4003 +#: ../../library/stdtypes.rst:4037 msgid "" "Return ``True`` if all bytes in the sequence are alphabetic ASCII characters " "and the sequence is not empty, ``False`` otherwise. Alphabetic ASCII " @@ -6004,7 +6060,7 @@ msgid "" "``b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'``." msgstr "" -#: ../../library/stdtypes.rst:4010 +#: ../../library/stdtypes.rst:4044 msgid "" ">>> b'ABCabc'.isalpha()\n" "True\n" @@ -6016,20 +6072,20 @@ msgstr "" ">>> b'ABCabc1'.isalpha()\n" "False" -#: ../../library/stdtypes.rst:4019 +#: ../../library/stdtypes.rst:4053 msgid "" "Return ``True`` if the sequence is empty or all bytes in the sequence are " "ASCII, ``False`` otherwise. ASCII bytes are in the range 0-0x7F." msgstr "" -#: ../../library/stdtypes.rst:4029 +#: ../../library/stdtypes.rst:4063 msgid "" "Return ``True`` if all bytes in the sequence are ASCII decimal digits and " "the sequence is not empty, ``False`` otherwise. ASCII decimal digits are " "those byte values in the sequence ``b'0123456789'``." msgstr "" -#: ../../library/stdtypes.rst:4035 +#: ../../library/stdtypes.rst:4069 msgid "" ">>> b'1234'.isdigit()\n" "True\n" @@ -6041,13 +6097,13 @@ msgstr "" ">>> b'1.23'.isdigit()\n" "False" -#: ../../library/stdtypes.rst:4044 +#: ../../library/stdtypes.rst:4078 msgid "" "Return ``True`` if there is at least one lowercase ASCII character in the " "sequence and no uppercase ASCII characters, ``False`` otherwise." msgstr "" -#: ../../library/stdtypes.rst:4049 +#: ../../library/stdtypes.rst:4083 msgid "" ">>> b'hello world'.islower()\n" "True\n" @@ -6059,16 +6115,16 @@ msgstr "" ">>> b'Hello world'.islower()\n" "False" -#: ../../library/stdtypes.rst:4054 ../../library/stdtypes.rst:4096 -#: ../../library/stdtypes.rst:4112 ../../library/stdtypes.rst:4162 -#: ../../library/stdtypes.rst:4231 +#: ../../library/stdtypes.rst:4088 ../../library/stdtypes.rst:4130 +#: ../../library/stdtypes.rst:4146 ../../library/stdtypes.rst:4196 +#: ../../library/stdtypes.rst:4265 msgid "" "Lowercase ASCII characters are those byte values in the sequence " "``b'abcdefghijklmnopqrstuvwxyz'``. Uppercase ASCII characters are those byte " "values in the sequence ``b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'``." msgstr "" -#: ../../library/stdtypes.rst:4062 +#: ../../library/stdtypes.rst:4096 msgid "" "Return ``True`` if all bytes in the sequence are ASCII whitespace and the " "sequence is not empty, ``False`` otherwise. ASCII whitespace characters are " @@ -6076,14 +6132,14 @@ msgid "" "newline, carriage return, vertical tab, form feed)." msgstr "" -#: ../../library/stdtypes.rst:4071 +#: ../../library/stdtypes.rst:4105 msgid "" "Return ``True`` if the sequence is ASCII titlecase and the sequence is not " "empty, ``False`` otherwise. See :meth:`bytes.title` for more details on the " "definition of \"titlecase\"." msgstr "" -#: ../../library/stdtypes.rst:4077 +#: ../../library/stdtypes.rst:4111 msgid "" ">>> b'Hello World'.istitle()\n" "True\n" @@ -6095,14 +6151,14 @@ msgstr "" ">>> b'Hello world'.istitle()\n" "False" -#: ../../library/stdtypes.rst:4086 +#: ../../library/stdtypes.rst:4120 msgid "" "Return ``True`` if there is at least one uppercase alphabetic ASCII " "character in the sequence and no lowercase ASCII characters, ``False`` " "otherwise." msgstr "" -#: ../../library/stdtypes.rst:4091 +#: ../../library/stdtypes.rst:4125 msgid "" ">>> b'HELLO WORLD'.isupper()\n" "True\n" @@ -6114,13 +6170,13 @@ msgstr "" ">>> b'Hello world'.isupper()\n" "False" -#: ../../library/stdtypes.rst:4104 +#: ../../library/stdtypes.rst:4138 msgid "" "Return a copy of the sequence with all the uppercase ASCII characters " "converted to their corresponding lowercase counterpart." msgstr "" -#: ../../library/stdtypes.rst:4109 +#: ../../library/stdtypes.rst:4143 msgid "" ">>> b'Hello World'.lower()\n" "b'hello world'" @@ -6128,7 +6184,7 @@ msgstr "" ">>> b'Hello World'.lower()\n" "b'hello world'" -#: ../../library/stdtypes.rst:4129 +#: ../../library/stdtypes.rst:4163 msgid "" "Return a list of the lines in the binary sequence, breaking at ASCII line " "boundaries. This method uses the :term:`universal newlines` approach to " @@ -6136,7 +6192,7 @@ msgid "" "*keepends* is given and true." msgstr "" -#: ../../library/stdtypes.rst:4136 +#: ../../library/stdtypes.rst:4170 msgid "" ">>> b'ab c\\n\\nde fg\\rkl\\r\\n'.splitlines()\n" "[b'ab c', b'', b'de fg', b'kl']\n" @@ -6148,14 +6204,14 @@ msgstr "" ">>> b'ab c\\n\\nde fg\\rkl\\r\\n'.splitlines(keepends=True)\n" "[b'ab c\\n', b'\\n', b'de fg\\r', b'kl\\r\\n']" -#: ../../library/stdtypes.rst:4141 +#: ../../library/stdtypes.rst:4175 msgid "" "Unlike :meth:`~bytes.split` when a delimiter string *sep* is given, this " "method returns an empty list for the empty string, and a terminal line break " "does not result in an extra line::" msgstr "" -#: ../../library/stdtypes.rst:4145 +#: ../../library/stdtypes.rst:4179 msgid "" ">>> b\"\".split(b'\\n'), b\"Two lines\\n\".split(b'\\n')\n" "([b''], [b'Two lines', b''])\n" @@ -6167,13 +6223,13 @@ msgstr "" ">>> b\"\".splitlines(), b\"One line\\n\".splitlines()\n" "([], [b'One line'])" -#: ../../library/stdtypes.rst:4154 +#: ../../library/stdtypes.rst:4188 msgid "" "Return a copy of the sequence with all the lowercase ASCII characters " "converted to their corresponding uppercase counterpart and vice-versa." msgstr "" -#: ../../library/stdtypes.rst:4159 +#: ../../library/stdtypes.rst:4193 msgid "" ">>> b'Hello World'.swapcase()\n" "b'hELLO wORLD'" @@ -6181,7 +6237,7 @@ msgstr "" ">>> b'Hello World'.swapcase()\n" "b'hELLO wORLD'" -#: ../../library/stdtypes.rst:4166 +#: ../../library/stdtypes.rst:4200 msgid "" "Unlike :func:`str.swapcase`, it is always the case that ``bin.swapcase()." "swapcase() == bin`` for the binary versions. Case conversions are " @@ -6189,14 +6245,14 @@ msgid "" "Unicode code points." msgstr "" -#: ../../library/stdtypes.rst:4180 +#: ../../library/stdtypes.rst:4214 msgid "" "Return a titlecased version of the binary sequence where words start with an " "uppercase ASCII character and the remaining characters are lowercase. " "Uncased byte values are left unmodified." msgstr "" -#: ../../library/stdtypes.rst:4186 +#: ../../library/stdtypes.rst:4220 msgid "" ">>> b'Hello world'.title()\n" "b'Hello World'" @@ -6204,7 +6260,7 @@ msgstr "" ">>> b'Hello world'.title()\n" "b'Hello World'" -#: ../../library/stdtypes.rst:4189 +#: ../../library/stdtypes.rst:4223 msgid "" "Lowercase ASCII characters are those byte values in the sequence " "``b'abcdefghijklmnopqrstuvwxyz'``. Uppercase ASCII characters are those byte " @@ -6212,7 +6268,7 @@ msgid "" "values are uncased." msgstr "" -#: ../../library/stdtypes.rst:4199 +#: ../../library/stdtypes.rst:4233 msgid "" ">>> b\"they're bill's friends from the UK\".title()\n" "b\"They'Re Bill'S Friends From The Uk\"" @@ -6220,12 +6276,12 @@ msgstr "" ">>> b\"they're bill's friends from the UK\".title()\n" "b\"They'Re Bill'S Friends From The Uk\"" -#: ../../library/stdtypes.rst:4202 +#: ../../library/stdtypes.rst:4236 msgid "" "A workaround for apostrophes can be constructed using regular expressions::" msgstr "" -#: ../../library/stdtypes.rst:4204 +#: ../../library/stdtypes.rst:4238 msgid "" ">>> import re\n" ">>> def titlecase(s):\n" @@ -6247,13 +6303,13 @@ msgstr "" ">>> titlecase(b\"they're bill's friends.\")\n" "b\"They're Bill's Friends.\"" -#: ../../library/stdtypes.rst:4223 +#: ../../library/stdtypes.rst:4257 msgid "" "Return a copy of the sequence with all the lowercase ASCII characters " "converted to their corresponding uppercase counterpart." msgstr "" -#: ../../library/stdtypes.rst:4228 +#: ../../library/stdtypes.rst:4262 msgid "" ">>> b'Hello World'.upper()\n" "b'HELLO WORLD'" @@ -6261,7 +6317,7 @@ msgstr "" ">>> b'Hello World'.upper()\n" "b'HELLO WORLD'" -#: ../../library/stdtypes.rst:4244 +#: ../../library/stdtypes.rst:4278 msgid "" "Return a copy of the sequence left filled with ASCII ``b'0'`` digits to make " "a sequence of length *width*. A leading sign prefix (``b'+'``/ ``b'-'``) is " @@ -6270,7 +6326,7 @@ msgid "" "*width* is less than or equal to ``len(seq)``." msgstr "" -#: ../../library/stdtypes.rst:4252 +#: ../../library/stdtypes.rst:4286 msgid "" ">>> b\"42\".zfill(5)\n" "b'00042'\n" @@ -6282,11 +6338,11 @@ msgstr "" ">>> b\"-42\".zfill(5)\n" "b'-0042'" -#: ../../library/stdtypes.rst:4266 +#: ../../library/stdtypes.rst:4300 msgid "``printf``-style Bytes Formatting" msgstr "" -#: ../../library/stdtypes.rst:4283 +#: ../../library/stdtypes.rst:4317 msgid "" "The formatting operations described here exhibit a variety of quirks that " "lead to a number of common errors (such as failing to display tuples and " @@ -6294,7 +6350,7 @@ msgid "" "dictionary, wrap it in a tuple." msgstr "" -#: ../../library/stdtypes.rst:4288 +#: ../../library/stdtypes.rst:4322 msgid "" "Bytes objects (``bytes``/``bytearray``) have one unique built-in operation: " "the ``%`` operator (modulo). This is also known as the bytes *formatting* or " @@ -6304,7 +6360,7 @@ msgid "" "func:`sprintf` in the C language." msgstr "" -#: ../../library/stdtypes.rst:4295 +#: ../../library/stdtypes.rst:4329 msgid "" "If *format* requires a single argument, *values* may be a single non-tuple " "object. [5]_ Otherwise, *values* must be a tuple with exactly the number of " @@ -6312,7 +6368,7 @@ msgid "" "example, a dictionary)." msgstr "" -#: ../../library/stdtypes.rst:4329 +#: ../../library/stdtypes.rst:4363 msgid "" "When the right argument is a dictionary (or other mapping type), then the " "formats in the bytes object *must* include a parenthesised mapping key into " @@ -6320,77 +6376,77 @@ msgid "" "mapping key selects the value to be formatted from the mapping. For example:" msgstr "" -#: ../../library/stdtypes.rst:4381 +#: ../../library/stdtypes.rst:4415 msgid "\\(8)" msgstr "\\(8)" -#: ../../library/stdtypes.rst:4403 +#: ../../library/stdtypes.rst:4437 msgid "Single byte (accepts integer or single byte objects)." msgstr "" -#: ../../library/stdtypes.rst:4406 +#: ../../library/stdtypes.rst:4440 msgid "``'b'``" msgstr "``'b'``" -#: ../../library/stdtypes.rst:4406 +#: ../../library/stdtypes.rst:4440 msgid "" "Bytes (any object that follows the :ref:`buffer protocol ` or " "has :meth:`~object.__bytes__`)." msgstr "" -#: ../../library/stdtypes.rst:4410 +#: ../../library/stdtypes.rst:4444 msgid "" "``'s'`` is an alias for ``'b'`` and should only be used for Python2/3 code " "bases." msgstr "" -#: ../../library/stdtypes.rst:4413 +#: ../../library/stdtypes.rst:4447 msgid "" "Bytes (converts any Python object using ``repr(obj).encode('ascii', " "'backslashreplace')``)." msgstr "" -#: ../../library/stdtypes.rst:4416 +#: ../../library/stdtypes.rst:4450 msgid "" "``'r'`` is an alias for ``'a'`` and should only be used for Python2/3 code " "bases." msgstr "" -#: ../../library/stdtypes.rst:4416 +#: ../../library/stdtypes.rst:4450 msgid "\\(7)" msgstr "\\(7)" -#: ../../library/stdtypes.rst:4451 +#: ../../library/stdtypes.rst:4485 msgid "``b'%s'`` is deprecated, but will not be removed during the 3.x series." msgstr "``b'%s'`` 已被棄用,但在 3.x 系列中不會被移除。" -#: ../../library/stdtypes.rst:4454 +#: ../../library/stdtypes.rst:4488 msgid "``b'%r'`` is deprecated, but will not be removed during the 3.x series." msgstr "``b'%r'`` 已被棄用,但在 3.x 系列中不會被移除。" -#: ../../library/stdtypes.rst:4466 +#: ../../library/stdtypes.rst:4500 msgid ":pep:`461` - Adding % formatting to bytes and bytearray" msgstr "" -#: ../../library/stdtypes.rst:4473 +#: ../../library/stdtypes.rst:4507 msgid "Memory Views" msgstr "" -#: ../../library/stdtypes.rst:4475 +#: ../../library/stdtypes.rst:4509 msgid "" ":class:`memoryview` objects allow Python code to access the internal data of " "an object that supports the :ref:`buffer protocol ` without " "copying." msgstr "" -#: ../../library/stdtypes.rst:4481 +#: ../../library/stdtypes.rst:4515 msgid "" "Create a :class:`memoryview` that references *object*. *object* must " "support the buffer protocol. Built-in objects that support the buffer " "protocol include :class:`bytes` and :class:`bytearray`." msgstr "" -#: ../../library/stdtypes.rst:4485 +#: ../../library/stdtypes.rst:4519 msgid "" "A :class:`memoryview` has the notion of an *element*, which is the atomic " "memory unit handled by the originating *object*. For many simple types such " @@ -6398,32 +6454,32 @@ msgid "" "other types such as :class:`array.array` may have bigger elements." msgstr "" -#: ../../library/stdtypes.rst:4490 +#: ../../library/stdtypes.rst:4524 msgid "" "``len(view)`` is equal to the length of :class:`~memoryview.tolist`, which " "is the nested list representation of the view. If ``view.ndim = 1``, this is " "equal to the number of elements in the view." msgstr "" -#: ../../library/stdtypes.rst:4494 +#: ../../library/stdtypes.rst:4528 msgid "" "If ``view.ndim == 0``, ``len(view)`` now raises :exc:`TypeError` instead of " "returning 1." msgstr "" -#: ../../library/stdtypes.rst:4497 +#: ../../library/stdtypes.rst:4531 msgid "" "The :class:`~memoryview.itemsize` attribute will give you the number of " "bytes in a single element." msgstr "" -#: ../../library/stdtypes.rst:4500 +#: ../../library/stdtypes.rst:4534 msgid "" "A :class:`memoryview` supports slicing and indexing to expose its data. One-" "dimensional slicing will result in a subview::" msgstr "" -#: ../../library/stdtypes.rst:4503 +#: ../../library/stdtypes.rst:4537 msgid "" ">>> v = memoryview(b'abcefg')\n" ">>> v[1]\n" @@ -6445,7 +6501,7 @@ msgstr "" ">>> bytes(v[1:4])\n" "b'bce'" -#: ../../library/stdtypes.rst:4513 +#: ../../library/stdtypes.rst:4547 msgid "" "If :class:`~memoryview.format` is one of the native format specifiers from " "the :mod:`struct` module, indexing with an integer or a tuple of integers is " @@ -6456,11 +6512,11 @@ msgid "" "memoryviews can be indexed with the empty tuple." msgstr "" -#: ../../library/stdtypes.rst:4522 +#: ../../library/stdtypes.rst:4556 msgid "Here is an example with a non-byte format::" msgstr "" -#: ../../library/stdtypes.rst:4524 +#: ../../library/stdtypes.rst:4558 msgid "" ">>> import array\n" ">>> a = array.array('l', [-11111111, 22222222, -33333333, 44444444])\n" @@ -6482,13 +6538,13 @@ msgstr "" ">>> m[::2].tolist()\n" "[-11111111, -33333333]" -#: ../../library/stdtypes.rst:4534 +#: ../../library/stdtypes.rst:4568 msgid "" "If the underlying object is writable, the memoryview supports one-" "dimensional slice assignment. Resizing is not allowed::" msgstr "" -#: ../../library/stdtypes.rst:4537 +#: ../../library/stdtypes.rst:4571 msgid "" ">>> data = bytearray(b'abcefg')\n" ">>> v = memoryview(data)\n" @@ -6528,14 +6584,14 @@ msgstr "" ">>> data\n" "bytearray(b'z1spam')" -#: ../../library/stdtypes.rst:4555 +#: ../../library/stdtypes.rst:4589 msgid "" "One-dimensional memoryviews of :term:`hashable` (read-only) types with " "formats 'B', 'b' or 'c' are also hashable. The hash is defined as ``hash(m) " "== hash(m.tobytes())``::" msgstr "" -#: ../../library/stdtypes.rst:4559 +#: ../../library/stdtypes.rst:4593 msgid "" ">>> v = memoryview(b'abcefg')\n" ">>> hash(v) == hash(b'abcefg')\n" @@ -6553,44 +6609,44 @@ msgstr "" ">>> hash(v[::-2]) == hash(b'abcefg'[::-2])\n" "True" -#: ../../library/stdtypes.rst:4567 +#: ../../library/stdtypes.rst:4601 msgid "" "One-dimensional memoryviews can now be sliced. One-dimensional memoryviews " "with formats 'B', 'b' or 'c' are now :term:`hashable`." msgstr "" -#: ../../library/stdtypes.rst:4571 +#: ../../library/stdtypes.rst:4605 msgid "" "memoryview is now registered automatically with :class:`collections.abc." "Sequence`" msgstr "" -#: ../../library/stdtypes.rst:4575 +#: ../../library/stdtypes.rst:4609 msgid "memoryviews can now be indexed with tuple of integers." msgstr "" -#: ../../library/stdtypes.rst:4578 +#: ../../library/stdtypes.rst:4612 msgid "memoryview is now a :term:`generic type`." msgstr "" -#: ../../library/stdtypes.rst:4581 +#: ../../library/stdtypes.rst:4615 msgid ":class:`memoryview` has several methods:" msgstr ":class:`memoryview` 有幾個方法:" -#: ../../library/stdtypes.rst:4585 +#: ../../library/stdtypes.rst:4619 msgid "" "A memoryview and a :pep:`3118` exporter are equal if their shapes are " "equivalent and if all corresponding values are equal when the operands' " "respective format codes are interpreted using :mod:`struct` syntax." msgstr "" -#: ../../library/stdtypes.rst:4589 +#: ../../library/stdtypes.rst:4623 msgid "" "For the subset of :mod:`struct` format strings currently supported by :meth:" "`tolist`, ``v`` and ``w`` are equal if ``v.tolist() == w.tolist()``::" msgstr "" -#: ../../library/stdtypes.rst:4592 +#: ../../library/stdtypes.rst:4626 msgid "" ">>> import array\n" ">>> a = array.array('I', [1, 2, 3, 4, 5])\n" @@ -6624,14 +6680,14 @@ msgstr "" ">>> z.tolist() == c.tolist()\n" "True" -#: ../../library/stdtypes.rst:4608 +#: ../../library/stdtypes.rst:4642 msgid "" "If either format string is not supported by the :mod:`struct` module, then " "the objects will always compare as unequal (even if the format strings and " "buffer contents are identical)::" msgstr "" -#: ../../library/stdtypes.rst:4612 +#: ../../library/stdtypes.rst:4646 msgid "" ">>> from ctypes import BigEndianStructure, c_long\n" ">>> class BEPoint(BigEndianStructure):\n" @@ -6657,25 +6713,25 @@ msgstr "" ">>> a == b\n" "False" -#: ../../library/stdtypes.rst:4624 +#: ../../library/stdtypes.rst:4658 msgid "" "Note that, as with floating-point numbers, ``v is w`` does *not* imply ``v " "== w`` for memoryview objects." msgstr "" -#: ../../library/stdtypes.rst:4627 +#: ../../library/stdtypes.rst:4661 msgid "" "Previous versions compared the raw memory disregarding the item format and " "the logical array structure." msgstr "" -#: ../../library/stdtypes.rst:4633 +#: ../../library/stdtypes.rst:4667 msgid "" "Return the data in the buffer as a bytestring. This is equivalent to " "calling the :class:`bytes` constructor on the memoryview. ::" msgstr "" -#: ../../library/stdtypes.rst:4636 +#: ../../library/stdtypes.rst:4670 msgid "" ">>> m = memoryview(b\"abc\")\n" ">>> m.tobytes()\n" @@ -6689,7 +6745,7 @@ msgstr "" ">>> bytes(m)\n" "b'abc'" -#: ../../library/stdtypes.rst:4642 +#: ../../library/stdtypes.rst:4676 msgid "" "For non-contiguous arrays the result is equal to the flattened list " "representation with all elements converted to bytes. :meth:`tobytes` " @@ -6697,7 +6753,7 @@ msgid "" "module syntax." msgstr "" -#: ../../library/stdtypes.rst:4647 +#: ../../library/stdtypes.rst:4681 msgid "" "*order* can be {'C', 'F', 'A'}. When *order* is 'C' or 'F', the data of the " "original array is converted to C or Fortran order. For contiguous views, 'A' " @@ -6706,13 +6762,13 @@ msgid "" "to C first. *order=None* is the same as *order='C'*." msgstr "" -#: ../../library/stdtypes.rst:4657 +#: ../../library/stdtypes.rst:4691 msgid "" "Return a string object containing two hexadecimal digits for each byte in " "the buffer. ::" msgstr "" -#: ../../library/stdtypes.rst:4660 +#: ../../library/stdtypes.rst:4694 msgid "" ">>> m = memoryview(b\"abc\")\n" ">>> m.hex()\n" @@ -6722,18 +6778,18 @@ msgstr "" ">>> m.hex()\n" "'616263'" -#: ../../library/stdtypes.rst:4666 +#: ../../library/stdtypes.rst:4700 msgid "" "Similar to :meth:`bytes.hex`, :meth:`memoryview.hex` now supports optional " "*sep* and *bytes_per_sep* parameters to insert separators between bytes in " "the hex output." msgstr "" -#: ../../library/stdtypes.rst:4673 +#: ../../library/stdtypes.rst:4707 msgid "Return the data in the buffer as a list of elements. ::" msgstr "" -#: ../../library/stdtypes.rst:4675 +#: ../../library/stdtypes.rst:4709 msgid "" ">>> memoryview(b'abc').tolist()\n" "[97, 98, 99]\n" @@ -6751,19 +6807,19 @@ msgstr "" ">>> m.tolist()\n" "[1.1, 2.2, 3.3]" -#: ../../library/stdtypes.rst:4683 +#: ../../library/stdtypes.rst:4717 msgid "" ":meth:`tolist` now supports all single character native formats in :mod:" "`struct` module syntax as well as multi-dimensional representations." msgstr "" -#: ../../library/stdtypes.rst:4690 +#: ../../library/stdtypes.rst:4724 msgid "" "Return a readonly version of the memoryview object. The original memoryview " "object is unchanged. ::" msgstr "" -#: ../../library/stdtypes.rst:4693 +#: ../../library/stdtypes.rst:4727 msgid "" ">>> m = memoryview(bytearray(b'abc'))\n" ">>> mm = m.toreadonly()\n" @@ -6789,7 +6845,7 @@ msgstr "" ">>> mm.tolist()\n" "[43, 98, 99]" -#: ../../library/stdtypes.rst:4709 +#: ../../library/stdtypes.rst:4743 msgid "" "Release the underlying buffer exposed by the memoryview object. Many " "objects take special actions when a view is held on them (for example, a :" @@ -6798,14 +6854,14 @@ msgid "" "resources) as soon as possible." msgstr "" -#: ../../library/stdtypes.rst:4715 +#: ../../library/stdtypes.rst:4749 msgid "" "After this method has been called, any further operation on the view raises " "a :class:`ValueError` (except :meth:`release` itself which can be called " "multiple times)::" msgstr "" -#: ../../library/stdtypes.rst:4719 +#: ../../library/stdtypes.rst:4753 msgid "" ">>> m = memoryview(b'abc')\n" ">>> m.release()\n" @@ -6821,13 +6877,13 @@ msgstr "" " File \"\", line 1, in \n" "ValueError: operation forbidden on released memoryview object" -#: ../../library/stdtypes.rst:4726 +#: ../../library/stdtypes.rst:4760 msgid "" "The context management protocol can be used for a similar effect, using the " "``with`` statement::" msgstr "" -#: ../../library/stdtypes.rst:4729 +#: ../../library/stdtypes.rst:4763 msgid "" ">>> with memoryview(b'abc') as m:\n" "... m[0]\n" @@ -6847,7 +6903,7 @@ msgstr "" " File \"\", line 1, in \n" "ValueError: operation forbidden on released memoryview object" -#: ../../library/stdtypes.rst:4743 +#: ../../library/stdtypes.rst:4777 msgid "" "Cast a memoryview to a new format or shape. *shape* defaults to " "``[byte_length//new_itemsize]``, which means that the result view will be " @@ -6856,7 +6912,7 @@ msgid "" "contiguous -> 1D." msgstr "" -#: ../../library/stdtypes.rst:4749 +#: ../../library/stdtypes.rst:4783 msgid "" "The destination format is restricted to a single element native format in :" "mod:`struct` syntax. One of the formats must be a byte format ('B', 'b' or " @@ -6864,11 +6920,11 @@ msgid "" "Note that all byte lengths may depend on the operating system." msgstr "" -#: ../../library/stdtypes.rst:4755 +#: ../../library/stdtypes.rst:4789 msgid "Cast 1D/long to 1D/unsigned bytes::" msgstr "" -#: ../../library/stdtypes.rst:4757 +#: ../../library/stdtypes.rst:4791 msgid "" ">>> import array\n" ">>> a = array.array('l', [1,2,3])\n" @@ -6912,11 +6968,11 @@ msgstr "" ">>> y.nbytes\n" "24" -#: ../../library/stdtypes.rst:4778 +#: ../../library/stdtypes.rst:4812 msgid "Cast 1D/unsigned bytes to 1D/char::" msgstr "" -#: ../../library/stdtypes.rst:4780 +#: ../../library/stdtypes.rst:4814 msgid "" ">>> b = bytearray(b'zyz')\n" ">>> x = memoryview(b)\n" @@ -6940,11 +6996,11 @@ msgstr "" ">>> b\n" "bytearray(b'ayz')" -#: ../../library/stdtypes.rst:4791 +#: ../../library/stdtypes.rst:4825 msgid "Cast 1D/bytes to 3D/ints to 1D/signed char::" msgstr "" -#: ../../library/stdtypes.rst:4793 +#: ../../library/stdtypes.rst:4827 msgid "" ">>> import struct\n" ">>> buf = struct.pack(\"i\"*12, *list(range(12)))\n" @@ -6994,11 +7050,11 @@ msgstr "" ">>> z.nbytes\n" "48" -#: ../../library/stdtypes.rst:4817 +#: ../../library/stdtypes.rst:4851 msgid "Cast 1D/unsigned long to 2D/unsigned long::" msgstr "" -#: ../../library/stdtypes.rst:4819 +#: ../../library/stdtypes.rst:4853 msgid "" ">>> buf = struct.pack(\"L\"*6, *list(range(6)))\n" ">>> x = memoryview(buf)\n" @@ -7020,33 +7076,33 @@ msgstr "" ">>> y.tolist()\n" "[[0, 1, 2], [3, 4, 5]]" -#: ../../library/stdtypes.rst:4831 +#: ../../library/stdtypes.rst:4865 msgid "The source format is no longer restricted when casting to a byte view." msgstr "" -#: ../../library/stdtypes.rst:4836 +#: ../../library/stdtypes.rst:4870 msgid "Count the number of occurrences of *value*." msgstr "計算 *value* 的出現次數" -#: ../../library/stdtypes.rst:4842 +#: ../../library/stdtypes.rst:4876 msgid "" "Return the index of the first occurrence of *value* (at or after index " "*start* and before index *stop*)." msgstr "" -#: ../../library/stdtypes.rst:4845 +#: ../../library/stdtypes.rst:4879 msgid "Raises a :exc:`ValueError` if *value* cannot be found." msgstr "在找不到 *value* 時引發 :exc:`ValueError`。" -#: ../../library/stdtypes.rst:4849 +#: ../../library/stdtypes.rst:4883 msgid "There are also several readonly attributes available:" msgstr "" -#: ../../library/stdtypes.rst:4853 +#: ../../library/stdtypes.rst:4887 msgid "The underlying object of the memoryview::" msgstr "memoryview 的底層物件: ::" -#: ../../library/stdtypes.rst:4855 +#: ../../library/stdtypes.rst:4889 msgid "" ">>> b = bytearray(b'xyz')\n" ">>> m = memoryview(b)\n" @@ -7058,14 +7114,14 @@ msgstr "" ">>> m.obj is b\n" "True" -#: ../../library/stdtypes.rst:4864 +#: ../../library/stdtypes.rst:4898 msgid "" "``nbytes == product(shape) * itemsize == len(m.tobytes())``. This is the " "amount of space in bytes that the array would use in a contiguous " "representation. It is not necessarily equal to ``len(m)``::" msgstr "" -#: ../../library/stdtypes.rst:4868 +#: ../../library/stdtypes.rst:4902 msgid "" ">>> import array\n" ">>> a = array.array('i', [1,2,3,4,5])\n" @@ -7097,11 +7153,11 @@ msgstr "" ">>> len(y.tobytes())\n" "12" -#: ../../library/stdtypes.rst:4883 +#: ../../library/stdtypes.rst:4917 msgid "Multi-dimensional arrays::" msgstr "" -#: ../../library/stdtypes.rst:4885 +#: ../../library/stdtypes.rst:4919 msgid "" ">>> import struct\n" ">>> buf = struct.pack(\"d\"*12, *[1.5*x for x in range(12)])\n" @@ -7125,11 +7181,11 @@ msgstr "" ">>> y.nbytes\n" "96" -#: ../../library/stdtypes.rst:4900 +#: ../../library/stdtypes.rst:4934 msgid "A bool indicating whether the memory is read only." msgstr "" -#: ../../library/stdtypes.rst:4904 +#: ../../library/stdtypes.rst:4938 msgid "" "A string containing the format (in :mod:`struct` module style) for each " "element in the view. A memoryview can be created from exporters with " @@ -7137,17 +7193,17 @@ msgid "" "restricted to native single element formats." msgstr "" -#: ../../library/stdtypes.rst:4909 +#: ../../library/stdtypes.rst:4943 msgid "" "format ``'B'`` is now handled according to the struct module syntax. This " "means that ``memoryview(b'abc')[0] == b'abc'[0] == 97``." msgstr "" -#: ../../library/stdtypes.rst:4915 +#: ../../library/stdtypes.rst:4949 msgid "The size in bytes of each element of the memoryview::" msgstr "" -#: ../../library/stdtypes.rst:4917 +#: ../../library/stdtypes.rst:4951 msgid "" ">>> import array, struct\n" ">>> m = memoryview(array.array('H', [32000, 32001, 32002]))\n" @@ -7167,49 +7223,49 @@ msgstr "" ">>> struct.calcsize('H') == m.itemsize\n" "True" -#: ../../library/stdtypes.rst:4928 +#: ../../library/stdtypes.rst:4962 msgid "" "An integer indicating how many dimensions of a multi-dimensional array the " "memory represents." msgstr "" -#: ../../library/stdtypes.rst:4933 +#: ../../library/stdtypes.rst:4967 msgid "" "A tuple of integers the length of :attr:`ndim` giving the shape of the " "memory as an N-dimensional array." msgstr "" -#: ../../library/stdtypes.rst:4936 ../../library/stdtypes.rst:4944 +#: ../../library/stdtypes.rst:4970 ../../library/stdtypes.rst:4978 msgid "An empty tuple instead of ``None`` when ndim = 0." msgstr "" -#: ../../library/stdtypes.rst:4941 +#: ../../library/stdtypes.rst:4975 msgid "" "A tuple of integers the length of :attr:`ndim` giving the size in bytes to " "access each element for each dimension of the array." msgstr "" -#: ../../library/stdtypes.rst:4949 +#: ../../library/stdtypes.rst:4983 msgid "Used internally for PIL-style arrays. The value is informational only." msgstr "" -#: ../../library/stdtypes.rst:4953 +#: ../../library/stdtypes.rst:4987 msgid "A bool indicating whether the memory is C-:term:`contiguous`." msgstr "" -#: ../../library/stdtypes.rst:4959 +#: ../../library/stdtypes.rst:4993 msgid "A bool indicating whether the memory is Fortran :term:`contiguous`." msgstr "" -#: ../../library/stdtypes.rst:4965 +#: ../../library/stdtypes.rst:4999 msgid "A bool indicating whether the memory is :term:`contiguous`." msgstr "" -#: ../../library/stdtypes.rst:4973 +#: ../../library/stdtypes.rst:5007 msgid "Set Types --- :class:`set`, :class:`frozenset`" msgstr "" -#: ../../library/stdtypes.rst:4977 +#: ../../library/stdtypes.rst:5011 msgid "" "A :dfn:`set` object is an unordered collection of distinct :term:`hashable` " "objects. Common uses include membership testing, removing duplicates from a " @@ -7219,7 +7275,7 @@ msgid "" "`collections` module.)" msgstr "" -#: ../../library/stdtypes.rst:4984 +#: ../../library/stdtypes.rst:5018 msgid "" "Like other collections, sets support ``x in set``, ``len(set)``, and ``for x " "in set``. Being an unordered collection, sets do not record element " @@ -7227,7 +7283,7 @@ msgid "" "slicing, or other sequence-like behavior." msgstr "" -#: ../../library/stdtypes.rst:4989 +#: ../../library/stdtypes.rst:5023 msgid "" "There are currently two built-in set types, :class:`set` and :class:" "`frozenset`. The :class:`set` type is mutable --- the contents can be " @@ -7239,18 +7295,18 @@ msgid "" "of another set." msgstr "" -#: ../../library/stdtypes.rst:4998 +#: ../../library/stdtypes.rst:5032 msgid "" "Non-empty sets (not frozensets) can be created by placing a comma-separated " "list of elements within braces, for example: ``{'jack', 'sjoerd'}``, in " "addition to the :class:`set` constructor." msgstr "" -#: ../../library/stdtypes.rst:5002 +#: ../../library/stdtypes.rst:5036 msgid "The constructors for both classes work the same:" msgstr "" -#: ../../library/stdtypes.rst:5007 +#: ../../library/stdtypes.rst:5041 msgid "" "Return a new set or frozenset object whose elements are taken from " "*iterable*. The elements of a set must be :term:`hashable`. To represent " @@ -7258,92 +7314,92 @@ msgid "" "*iterable* is not specified, a new empty set is returned." msgstr "" -#: ../../library/stdtypes.rst:5013 +#: ../../library/stdtypes.rst:5047 msgid "Sets can be created by several means:" msgstr "集合可以以多種方式建立:" -#: ../../library/stdtypes.rst:5015 +#: ../../library/stdtypes.rst:5049 msgid "" "Use a comma-separated list of elements within braces: ``{'jack', 'sjoerd'}``" msgstr "" -#: ../../library/stdtypes.rst:5016 +#: ../../library/stdtypes.rst:5050 msgid "" "Use a set comprehension: ``{c for c in 'abracadabra' if c not in 'abc'}``" msgstr "" -#: ../../library/stdtypes.rst:5017 +#: ../../library/stdtypes.rst:5051 msgid "" "Use the type constructor: ``set()``, ``set('foobar')``, ``set(['a', 'b', " "'foo'])``" msgstr "" -#: ../../library/stdtypes.rst:5019 +#: ../../library/stdtypes.rst:5053 msgid "" "Instances of :class:`set` and :class:`frozenset` provide the following " "operations:" msgstr "" -#: ../../library/stdtypes.rst:5024 +#: ../../library/stdtypes.rst:5058 msgid "Return the number of elements in set *s* (cardinality of *s*)." msgstr "" -#: ../../library/stdtypes.rst:5028 +#: ../../library/stdtypes.rst:5062 msgid "Test *x* for membership in *s*." msgstr "" -#: ../../library/stdtypes.rst:5032 +#: ../../library/stdtypes.rst:5066 msgid "Test *x* for non-membership in *s*." msgstr "" -#: ../../library/stdtypes.rst:5037 +#: ../../library/stdtypes.rst:5071 msgid "" "Return ``True`` if the set has no elements in common with *other*. Sets are " "disjoint if and only if their intersection is the empty set." msgstr "" -#: ../../library/stdtypes.rst:5044 +#: ../../library/stdtypes.rst:5078 msgid "Test whether every element in the set is in *other*." msgstr "" -#: ../../library/stdtypes.rst:5048 +#: ../../library/stdtypes.rst:5082 msgid "" "Test whether the set is a proper subset of *other*, that is, ``set <= other " "and set != other``." msgstr "" -#: ../../library/stdtypes.rst:5055 +#: ../../library/stdtypes.rst:5089 msgid "Test whether every element in *other* is in the set." msgstr "" -#: ../../library/stdtypes.rst:5059 +#: ../../library/stdtypes.rst:5093 msgid "" "Test whether the set is a proper superset of *other*, that is, ``set >= " "other and set != other``." msgstr "" -#: ../../library/stdtypes.rst:5066 +#: ../../library/stdtypes.rst:5100 msgid "Return a new set with elements from the set and all others." msgstr "" -#: ../../library/stdtypes.rst:5072 +#: ../../library/stdtypes.rst:5106 msgid "Return a new set with elements common to the set and all others." msgstr "" -#: ../../library/stdtypes.rst:5078 +#: ../../library/stdtypes.rst:5112 msgid "Return a new set with elements in the set that are not in the others." msgstr "" -#: ../../library/stdtypes.rst:5084 +#: ../../library/stdtypes.rst:5118 msgid "" "Return a new set with elements in either the set or *other* but not both." msgstr "" -#: ../../library/stdtypes.rst:5089 +#: ../../library/stdtypes.rst:5123 msgid "Return a shallow copy of the set." msgstr "" -#: ../../library/stdtypes.rst:5092 +#: ../../library/stdtypes.rst:5126 msgid "" "Note, the non-operator versions of :meth:`~frozenset.union`, :meth:" "`~frozenset.intersection`, :meth:`~frozenset.difference`, :meth:`~frozenset." @@ -7354,7 +7410,7 @@ msgid "" "the more readable ``set('abc').intersection('cbs')``." msgstr "" -#: ../../library/stdtypes.rst:5099 +#: ../../library/stdtypes.rst:5133 msgid "" "Both :class:`set` and :class:`frozenset` support set to set comparisons. Two " "sets are equal if and only if every element of each set is contained in the " @@ -7364,14 +7420,14 @@ msgid "" "set is a proper superset of the second set (is a superset, but is not equal)." msgstr "" -#: ../../library/stdtypes.rst:5106 +#: ../../library/stdtypes.rst:5140 msgid "" "Instances of :class:`set` are compared to instances of :class:`frozenset` " "based on their members. For example, ``set('abc') == frozenset('abc')`` " "returns ``True`` and so does ``set('abc') in set([frozenset('abc')])``." msgstr "" -#: ../../library/stdtypes.rst:5110 +#: ../../library/stdtypes.rst:5144 msgid "" "The subset and equality comparisons do not generalize to a total ordering " "function. For example, any two nonempty disjoint sets are not equal and are " @@ -7379,78 +7435,78 @@ msgid "" "``ab``." msgstr "" -#: ../../library/stdtypes.rst:5115 +#: ../../library/stdtypes.rst:5149 msgid "" "Since sets only define partial ordering (subset relationships), the output " "of the :meth:`list.sort` method is undefined for lists of sets." msgstr "" -#: ../../library/stdtypes.rst:5118 +#: ../../library/stdtypes.rst:5152 msgid "Set elements, like dictionary keys, must be :term:`hashable`." msgstr "" -#: ../../library/stdtypes.rst:5120 +#: ../../library/stdtypes.rst:5154 msgid "" "Binary operations that mix :class:`set` instances with :class:`frozenset` " "return the type of the first operand. For example: ``frozenset('ab') | " "set('bc')`` returns an instance of :class:`frozenset`." msgstr "" -#: ../../library/stdtypes.rst:5124 +#: ../../library/stdtypes.rst:5158 msgid "" "The following table lists operations available for :class:`set` that do not " "apply to immutable instances of :class:`frozenset`:" msgstr "" -#: ../../library/stdtypes.rst:5130 +#: ../../library/stdtypes.rst:5164 msgid "Update the set, adding elements from all others." msgstr "" -#: ../../library/stdtypes.rst:5135 +#: ../../library/stdtypes.rst:5169 msgid "Update the set, keeping only elements found in it and all others." msgstr "" -#: ../../library/stdtypes.rst:5140 +#: ../../library/stdtypes.rst:5174 msgid "Update the set, removing elements found in others." msgstr "" -#: ../../library/stdtypes.rst:5145 +#: ../../library/stdtypes.rst:5179 msgid "" "Update the set, keeping only elements found in either set, but not in both." msgstr "" -#: ../../library/stdtypes.rst:5149 +#: ../../library/stdtypes.rst:5183 msgid "Add element *elem* to the set." msgstr "將元素 *elem* 加入集合。" -#: ../../library/stdtypes.rst:5153 +#: ../../library/stdtypes.rst:5187 msgid "" "Remove element *elem* from the set. Raises :exc:`KeyError` if *elem* is not " "contained in the set." msgstr "" -#: ../../library/stdtypes.rst:5158 +#: ../../library/stdtypes.rst:5192 msgid "Remove element *elem* from the set if it is present." msgstr "如果 *elem* 存在於集合中則將其移除。" -#: ../../library/stdtypes.rst:5162 +#: ../../library/stdtypes.rst:5196 msgid "" "Remove and return an arbitrary element from the set. Raises :exc:`KeyError` " "if the set is empty." msgstr "" -#: ../../library/stdtypes.rst:5167 +#: ../../library/stdtypes.rst:5201 msgid "Remove all elements from the set." msgstr "從集合中移除所有元素。" -#: ../../library/stdtypes.rst:5170 +#: ../../library/stdtypes.rst:5204 msgid "" "Note, the non-operator versions of the :meth:`~set.update`, :meth:`~set." "intersection_update`, :meth:`~set.difference_update`, and :meth:`~set." "symmetric_difference_update` methods will accept any iterable as an argument." msgstr "" -#: ../../library/stdtypes.rst:5175 +#: ../../library/stdtypes.rst:5209 msgid "" "Note, the *elem* argument to the :meth:`~object.__contains__`, :meth:`~set." "remove`, and :meth:`~set.discard` methods may be a set. To support " @@ -7458,11 +7514,11 @@ msgid "" "*elem*." msgstr "" -#: ../../library/stdtypes.rst:5184 +#: ../../library/stdtypes.rst:5218 msgid "Mapping Types --- :class:`dict`" msgstr "" -#: ../../library/stdtypes.rst:5194 +#: ../../library/stdtypes.rst:5228 msgid "" "A :term:`mapping` object maps :term:`hashable` values to arbitrary objects. " "Mappings are mutable objects. There is currently only one standard mapping " @@ -7471,7 +7527,7 @@ msgid "" "module.)" msgstr "" -#: ../../library/stdtypes.rst:5200 +#: ../../library/stdtypes.rst:5234 msgid "" "A dictionary's keys are *almost* arbitrary values. Values that are not :" "term:`hashable`, that is, values containing lists, dictionaries or other " @@ -7480,33 +7536,33 @@ msgid "" "and ``True``) can be used interchangeably to index the same dictionary entry." msgstr "" -#: ../../library/stdtypes.rst:5211 +#: ../../library/stdtypes.rst:5245 msgid "" "Return a new dictionary initialized from an optional positional argument and " "a possibly empty set of keyword arguments." msgstr "" -#: ../../library/stdtypes.rst:5214 +#: ../../library/stdtypes.rst:5248 msgid "Dictionaries can be created by several means:" msgstr "字典可以用數種方式建立:" -#: ../../library/stdtypes.rst:5216 +#: ../../library/stdtypes.rst:5250 msgid "" "Use a comma-separated list of ``key: value`` pairs within braces: ``{'jack': " "4098, 'sjoerd': 4127}`` or ``{4098: 'jack', 4127: 'sjoerd'}``" msgstr "" -#: ../../library/stdtypes.rst:5218 +#: ../../library/stdtypes.rst:5252 msgid "Use a dict comprehension: ``{}``, ``{x: x ** 2 for x in range(10)}``" msgstr "" -#: ../../library/stdtypes.rst:5219 +#: ../../library/stdtypes.rst:5253 msgid "" "Use the type constructor: ``dict()``, ``dict([('foo', 100), ('bar', " "200)])``, ``dict(foo=100, bar=200)``" msgstr "" -#: ../../library/stdtypes.rst:5222 +#: ../../library/stdtypes.rst:5256 msgid "" "If no positional argument is given, an empty dictionary is created. If a " "positional argument is given and it defines a ``keys()`` method, a " @@ -7519,7 +7575,7 @@ msgid "" "that key becomes the corresponding value in the new dictionary." msgstr "" -#: ../../library/stdtypes.rst:5232 +#: ../../library/stdtypes.rst:5266 msgid "" "If keyword arguments are given, the keyword arguments and their values are " "added to the dictionary created from the positional argument. If a key " @@ -7527,7 +7583,7 @@ msgid "" "the value from the positional argument." msgstr "" -#: ../../library/stdtypes.rst:5237 +#: ../../library/stdtypes.rst:5271 msgid "" "Dictionaries compare equal if and only if they have the same ``(key, " "value)`` pairs (regardless of ordering). Order comparisons ('<', '<=', '>=', " @@ -7536,7 +7592,7 @@ msgid "" "``{\"one\": 1, \"two\": 2, \"three\": 3}``::" msgstr "" -#: ../../library/stdtypes.rst:5243 +#: ../../library/stdtypes.rst:5277 msgid "" ">>> a = dict(one=1, two=2, three=3)\n" ">>> b = {'one': 1, 'two': 2, 'three': 3}\n" @@ -7556,19 +7612,19 @@ msgstr "" ">>> a == b == c == d == e == f\n" "True" -#: ../../library/stdtypes.rst:5252 +#: ../../library/stdtypes.rst:5286 msgid "" "Providing keyword arguments as in the first example only works for keys that " "are valid Python identifiers. Otherwise, any valid keys can be used." msgstr "" -#: ../../library/stdtypes.rst:5255 +#: ../../library/stdtypes.rst:5289 msgid "" "Dictionaries preserve insertion order. Note that updating a key does not " "affect the order. Keys added after deletion are inserted at the end. ::" msgstr "" -#: ../../library/stdtypes.rst:5258 +#: ../../library/stdtypes.rst:5292 msgid "" ">>> d = {\"one\": 1, \"two\": 2, \"three\": 3, \"four\": 4}\n" ">>> d\n" @@ -7600,33 +7656,33 @@ msgstr "" ">>> d\n" "{'one': 42, 'three': 3, 'four': 4, 'two': None}" -#: ../../library/stdtypes.rst:5273 +#: ../../library/stdtypes.rst:5307 msgid "" "Dictionary order is guaranteed to be insertion order. This behavior was an " "implementation detail of CPython from 3.6." msgstr "" -#: ../../library/stdtypes.rst:5277 +#: ../../library/stdtypes.rst:5311 msgid "" "These are the operations that dictionaries support (and therefore, custom " "mapping types should support too):" msgstr "" -#: ../../library/stdtypes.rst:5282 +#: ../../library/stdtypes.rst:5316 msgid "Return a list of all the keys used in the dictionary *d*." msgstr "" -#: ../../library/stdtypes.rst:5286 +#: ../../library/stdtypes.rst:5320 msgid "Return the number of items in the dictionary *d*." msgstr "" -#: ../../library/stdtypes.rst:5290 +#: ../../library/stdtypes.rst:5324 msgid "" "Return the item of *d* with key *key*. Raises a :exc:`KeyError` if *key* is " "not in the map." msgstr "" -#: ../../library/stdtypes.rst:5295 +#: ../../library/stdtypes.rst:5329 msgid "" "If a subclass of dict defines a method :meth:`~object.__missing__` and *key* " "is not present, the ``d[key]`` operation calls that method with the key " @@ -7637,7 +7693,7 @@ msgid "" "__missing__` must be a method; it cannot be an instance variable::" msgstr "" -#: ../../library/stdtypes.rst:5303 +#: ../../library/stdtypes.rst:5337 msgid "" ">>> class Counter(dict):\n" "... def __missing__(self, key):\n" @@ -7661,51 +7717,51 @@ msgstr "" ">>> c['red']\n" "1" -#: ../../library/stdtypes.rst:5314 +#: ../../library/stdtypes.rst:5348 msgid "" "The example above shows part of the implementation of :class:`collections." "Counter`. A different :meth:`!__missing__` method is used by :class:" "`collections.defaultdict`." msgstr "" -#: ../../library/stdtypes.rst:5321 +#: ../../library/stdtypes.rst:5355 msgid "Set ``d[key]`` to *value*." msgstr "將 ``d[key]`` 設為 *value*。" -#: ../../library/stdtypes.rst:5325 +#: ../../library/stdtypes.rst:5359 msgid "" "Remove ``d[key]`` from *d*. Raises a :exc:`KeyError` if *key* is not in the " "map." msgstr "從 *d* 中移除 ``d[key]``。若 *key* 不在對映中則引發 :exc:`KeyError`。" -#: ../../library/stdtypes.rst:5330 +#: ../../library/stdtypes.rst:5364 msgid "Return ``True`` if *d* has a key *key*, else ``False``." msgstr "若 *d* 有鍵 *key* 則回傳 ``True``,否則回傳 ``False``。" -#: ../../library/stdtypes.rst:5334 +#: ../../library/stdtypes.rst:5368 msgid "Equivalent to ``not key in d``." msgstr "等價於 ``not key in d``。" -#: ../../library/stdtypes.rst:5338 +#: ../../library/stdtypes.rst:5372 msgid "" "Return an iterator over the keys of the dictionary. This is a shortcut for " "``iter(d.keys())``." msgstr "" -#: ../../library/stdtypes.rst:5343 +#: ../../library/stdtypes.rst:5377 msgid "Remove all items from the dictionary." msgstr "從字典中移除所有項目。" -#: ../../library/stdtypes.rst:5347 +#: ../../library/stdtypes.rst:5381 msgid "Return a shallow copy of the dictionary." msgstr "" -#: ../../library/stdtypes.rst:5351 +#: ../../library/stdtypes.rst:5385 msgid "" "Create a new dictionary with keys from *iterable* and values set to *value*." msgstr "" -#: ../../library/stdtypes.rst:5353 +#: ../../library/stdtypes.rst:5387 msgid "" ":meth:`fromkeys` is a class method that returns a new dictionary. *value* " "defaults to ``None``. All of the values refer to just a single instance, so " @@ -7714,70 +7770,70 @@ msgid "" "` instead." msgstr "" -#: ../../library/stdtypes.rst:5361 +#: ../../library/stdtypes.rst:5395 msgid "" "Return the value for *key* if *key* is in the dictionary, else *default*. If " "*default* is not given, it defaults to ``None``, so that this method never " "raises a :exc:`KeyError`." msgstr "" -#: ../../library/stdtypes.rst:5367 +#: ../../library/stdtypes.rst:5401 msgid "" "Return a new view of the dictionary's items (``(key, value)`` pairs). See " "the :ref:`documentation of view objects `." msgstr "" -#: ../../library/stdtypes.rst:5372 +#: ../../library/stdtypes.rst:5406 msgid "" "Return a new view of the dictionary's keys. See the :ref:`documentation of " "view objects `." msgstr "" -#: ../../library/stdtypes.rst:5378 +#: ../../library/stdtypes.rst:5412 msgid "" "If *key* is in the dictionary, remove it and return its value, else return " "*default*. If *default* is not given and *key* is not in the dictionary, a :" "exc:`KeyError` is raised." msgstr "" -#: ../../library/stdtypes.rst:5384 +#: ../../library/stdtypes.rst:5418 msgid "" "Remove and return a ``(key, value)`` pair from the dictionary. Pairs are " "returned in :abbr:`LIFO (last-in, first-out)` order." msgstr "" -#: ../../library/stdtypes.rst:5387 +#: ../../library/stdtypes.rst:5421 msgid "" ":meth:`popitem` is useful to destructively iterate over a dictionary, as " "often used in set algorithms. If the dictionary is empty, calling :meth:" "`popitem` raises a :exc:`KeyError`." msgstr "" -#: ../../library/stdtypes.rst:5391 +#: ../../library/stdtypes.rst:5425 msgid "" "LIFO order is now guaranteed. In prior versions, :meth:`popitem` would " "return an arbitrary key/value pair." msgstr "" -#: ../../library/stdtypes.rst:5397 +#: ../../library/stdtypes.rst:5431 msgid "" "Return a reverse iterator over the keys of the dictionary. This is a " "shortcut for ``reversed(d.keys())``." msgstr "" -#: ../../library/stdtypes.rst:5404 +#: ../../library/stdtypes.rst:5438 msgid "" "If *key* is in the dictionary, return its value. If not, insert *key* with " "a value of *default* and return *default*. *default* defaults to ``None``." msgstr "" -#: ../../library/stdtypes.rst:5412 +#: ../../library/stdtypes.rst:5446 msgid "" "Update the dictionary with the key/value pairs from *mapping* or *iterable* " "and *kwargs*, overwriting existing keys. Return ``None``." msgstr "" -#: ../../library/stdtypes.rst:5415 +#: ../../library/stdtypes.rst:5449 msgid "" ":meth:`update` accepts either another object with a ``keys()`` method (in " "which case :meth:`~object.__getitem__` is called with every key returned " @@ -7786,20 +7842,20 @@ msgid "" "is then updated with those key/value pairs: ``d.update(red=1, blue=2)``." msgstr "" -#: ../../library/stdtypes.rst:5423 +#: ../../library/stdtypes.rst:5457 msgid "" "Return a new view of the dictionary's values. See the :ref:`documentation " "of view objects `." msgstr "" -#: ../../library/stdtypes.rst:5426 +#: ../../library/stdtypes.rst:5460 msgid "" "An equality comparison between one ``dict.values()`` view and another will " "always return ``False``. This also applies when comparing ``dict.values()`` " "to itself::" msgstr "" -#: ../../library/stdtypes.rst:5430 +#: ../../library/stdtypes.rst:5464 msgid "" ">>> d = {'a': 1}\n" ">>> d.values() == d.values()\n" @@ -7809,25 +7865,25 @@ msgstr "" ">>> d.values() == d.values()\n" "False" -#: ../../library/stdtypes.rst:5436 +#: ../../library/stdtypes.rst:5470 msgid "" "Create a new dictionary with the merged keys and values of *d* and *other*, " "which must both be dictionaries. The values of *other* take priority when " "*d* and *other* share keys." msgstr "" -#: ../../library/stdtypes.rst:5444 +#: ../../library/stdtypes.rst:5478 msgid "" "Update the dictionary *d* with keys and values from *other*, which may be " "either a :term:`mapping` or an :term:`iterable` of key/value pairs. The " "values of *other* take priority when *d* and *other* share keys." msgstr "" -#: ../../library/stdtypes.rst:5450 +#: ../../library/stdtypes.rst:5484 msgid "Dictionaries and dictionary views are reversible. ::" msgstr "" -#: ../../library/stdtypes.rst:5452 +#: ../../library/stdtypes.rst:5486 msgid "" ">>> d = {\"one\": 1, \"two\": 2, \"three\": 3, \"four\": 4}\n" ">>> d\n" @@ -7849,27 +7905,27 @@ msgstr "" ">>> list(reversed(d.items()))\n" "[('four', 4), ('three', 3), ('two', 2), ('one', 1)]" -#: ../../library/stdtypes.rst:5462 +#: ../../library/stdtypes.rst:5496 msgid "Dictionaries are now reversible." msgstr "" -#: ../../library/stdtypes.rst:5467 +#: ../../library/stdtypes.rst:5501 msgid "" ":class:`types.MappingProxyType` can be used to create a read-only view of a :" "class:`dict`." msgstr "" -#: ../../library/stdtypes.rst:5473 +#: ../../library/stdtypes.rst:5507 msgid "" "For detailed information on thread-safety guarantees for :class:`dict` " "objects, see :ref:`thread-safety-dict`." msgstr "" -#: ../../library/stdtypes.rst:5480 +#: ../../library/stdtypes.rst:5514 msgid "Dictionary view objects" msgstr "字典視圖物件" -#: ../../library/stdtypes.rst:5482 +#: ../../library/stdtypes.rst:5516 msgid "" "The objects returned by :meth:`dict.keys`, :meth:`dict.values` and :meth:" "`dict.items` are *view objects*. They provide a dynamic view on the " @@ -7877,23 +7933,23 @@ msgid "" "reflects these changes." msgstr "" -#: ../../library/stdtypes.rst:5487 +#: ../../library/stdtypes.rst:5521 msgid "" "Dictionary views can be iterated over to yield their respective data, and " "support membership tests:" msgstr "" -#: ../../library/stdtypes.rst:5492 +#: ../../library/stdtypes.rst:5526 msgid "Return the number of entries in the dictionary." msgstr "" -#: ../../library/stdtypes.rst:5496 +#: ../../library/stdtypes.rst:5530 msgid "" "Return an iterator over the keys, values or items (represented as tuples of " "``(key, value)``) in the dictionary." msgstr "" -#: ../../library/stdtypes.rst:5499 +#: ../../library/stdtypes.rst:5533 msgid "" "Keys and values are iterated over in insertion order. This allows the " "creation of ``(value, key)`` pairs using :func:`zip`: ``pairs = zip(d." @@ -7901,39 +7957,39 @@ msgid "" "[(v, k) for (k, v) in d.items()]``." msgstr "" -#: ../../library/stdtypes.rst:5504 +#: ../../library/stdtypes.rst:5538 msgid "" "Iterating views while adding or deleting entries in the dictionary may raise " "a :exc:`RuntimeError` or fail to iterate over all entries." msgstr "" -#: ../../library/stdtypes.rst:5507 +#: ../../library/stdtypes.rst:5541 msgid "Dictionary order is guaranteed to be insertion order." msgstr "" -#: ../../library/stdtypes.rst:5512 +#: ../../library/stdtypes.rst:5546 msgid "" "Return ``True`` if *x* is in the underlying dictionary's keys, values or " "items (in the latter case, *x* should be a ``(key, value)`` tuple)." msgstr "" -#: ../../library/stdtypes.rst:5517 +#: ../../library/stdtypes.rst:5551 msgid "" "Return a reverse iterator over the keys, values or items of the dictionary. " "The view will be iterated in reverse order of the insertion." msgstr "" -#: ../../library/stdtypes.rst:5520 +#: ../../library/stdtypes.rst:5554 msgid "Dictionary views are now reversible." msgstr "" -#: ../../library/stdtypes.rst:5525 +#: ../../library/stdtypes.rst:5559 msgid "" "Return a :class:`types.MappingProxyType` that wraps the original dictionary " "to which the view refers." msgstr "" -#: ../../library/stdtypes.rst:5530 +#: ../../library/stdtypes.rst:5564 msgid "" "Keys views are set-like since their entries are unique and :term:`hashable`. " "Items views also have set-like operations since the (key, value) pairs are " @@ -7947,11 +8003,11 @@ msgid "" "input." msgstr "" -#: ../../library/stdtypes.rst:5542 +#: ../../library/stdtypes.rst:5576 msgid "An example of dictionary view usage::" msgstr "" -#: ../../library/stdtypes.rst:5544 +#: ../../library/stdtypes.rst:5578 msgid "" ">>> dishes = {'eggs': 2, 'sausage': 1, 'bacon': 1, 'spam': 500}\n" ">>> keys = dishes.keys()\n" @@ -7992,11 +8048,11 @@ msgid "" "500" msgstr "" -#: ../../library/stdtypes.rst:5586 +#: ../../library/stdtypes.rst:5620 msgid "Context Manager Types" msgstr "情境管理器型別" -#: ../../library/stdtypes.rst:5593 +#: ../../library/stdtypes.rst:5627 msgid "" "Python's :keyword:`with` statement supports the concept of a runtime context " "defined by a context manager. This is implemented using a pair of methods " @@ -8007,7 +8063,7 @@ msgstr "" "要使用兩個方法來實作,該方法讓使用者定義類別能夠去定義 runtime 情境,且該情境" "在執行陳述式主體 (statement body) 之前進入、在陳述式結束時退出:" -#: ../../library/stdtypes.rst:5601 +#: ../../library/stdtypes.rst:5635 msgid "" "Enter the runtime context and return either this object or another object " "related to the runtime context. The value returned by this method is bound " @@ -8018,7 +8074,7 @@ msgstr "" "的值有被綁定到使用此情境管理器的 :keyword:`with` 陳述式的 :keyword:`!as` 子句" "中的識別字。" -#: ../../library/stdtypes.rst:5606 +#: ../../library/stdtypes.rst:5640 msgid "" "An example of a context manager that returns itself is a :term:`file " "object`. File objects return themselves from __enter__() to allow :func:" @@ -8027,7 +8083,7 @@ msgstr "" "一個會回傳自己的情境管理器範例是 :term:`file object`。檔案物件從 __enter__() " "回傳自己,以允許將 :func:`open` 用作 :keyword:`with` 陳述式中的情境運算式。" -#: ../../library/stdtypes.rst:5610 +#: ../../library/stdtypes.rst:5644 msgid "" "An example of a context manager that returns a related object is the one " "returned by :func:`decimal.localcontext`. These managers set the active " @@ -8041,7 +8097,7 @@ msgstr "" "本。這允許對 :keyword:`with` 陳述式主體中的目前十進位情境進行更改,而不會影" "響 :keyword:`!with` 陳述式外部的程式碼。" -#: ../../library/stdtypes.rst:5620 +#: ../../library/stdtypes.rst:5654 msgid "" "Exit the runtime context and return a Boolean flag indicating if any " "exception that occurred should be suppressed. If an exception occurred while " @@ -8053,7 +8109,7 @@ msgstr "" "keyword:`with` 陳述式主體時發生例外,則引數包含例外型別、值和回溯 " "(traceback) 資訊。否則,所有三個引數都是 ``None``。" -#: ../../library/stdtypes.rst:5625 +#: ../../library/stdtypes.rst:5659 msgid "" "Returning a true value from this method will cause the :keyword:`with` " "statement to suppress the exception and continue execution with the " @@ -8064,14 +8120,14 @@ msgstr "" "keyword:`!with` 陳述式之後的陳述式。否則,該例外將在該方法執行完畢後繼續傳播 " "(propagate)。" -#: ../../library/stdtypes.rst:5630 +#: ../../library/stdtypes.rst:5664 msgid "" "If this method raises an exception while handling an earlier exception from " "the :keyword:`with` block, the new exception is raised, and the original " "exception is stored in its :attr:`~BaseException.__context__` attribute." msgstr "" -#: ../../library/stdtypes.rst:5634 +#: ../../library/stdtypes.rst:5668 msgid "" "The exception passed in should never be reraised explicitly - instead, this " "method should return a false value to indicate that the method completed " @@ -8083,7 +8139,7 @@ msgstr "" "已成功完成且不希望抑制引發的例外。這讓情境管理程式碼能輕鬆檢測 :meth:" "`~object.__exit__` 方法是否曾實際失敗過。" -#: ../../library/stdtypes.rst:5640 +#: ../../library/stdtypes.rst:5674 msgid "" "Python defines several context managers to support easy thread " "synchronisation, prompt closure of files or other objects, and simpler " @@ -8095,7 +8151,7 @@ msgstr "" "及對有效十進位算術情境的更簡單操作。除了情境管理協定的實作之外,不會對特定型" "別進行特殊處理。更多範例請參閱 :mod:`contextlib` 模組。" -#: ../../library/stdtypes.rst:5646 +#: ../../library/stdtypes.rst:5680 msgid "" "Python's :term:`generator`\\s and the :class:`contextlib.contextmanager` " "decorator provide a convenient way to implement these protocols. If a " @@ -8110,7 +8166,7 @@ msgstr "" "`~contextmanager.__enter__` 和 :meth:`~contextmanager.__exit__` 方法的情境管" "理器,而不是由未裝飾產生器函式產生的疊代器。" -#: ../../library/stdtypes.rst:5653 +#: ../../library/stdtypes.rst:5687 msgid "" "Note that there is no specific slot for any of these methods in the type " "structure for Python objects in the Python/C API. Extension types wanting to " @@ -8122,7 +8178,7 @@ msgstr "" "定義這些方法的擴充型別必須將它們作為普通的 Python 可存取方法提供。與設定 " "runtime 情境的開銷相比,單一類別字典查找的開銷可以忽略不計。" -#: ../../library/stdtypes.rst:5661 +#: ../../library/stdtypes.rst:5695 msgid "" "Type Annotation Types --- :ref:`Generic Alias `, :ref:" "`Union `" @@ -8130,7 +8186,7 @@ msgstr "" "型別註釋的型別 --- :ref:`泛型別名 (Generic Alias) `、:" "ref:`聯合 (Union) `" -#: ../../library/stdtypes.rst:5666 +#: ../../library/stdtypes.rst:5700 msgid "" "The core built-in types for :term:`type annotations ` are :ref:" "`Generic Alias ` and :ref:`Union `." @@ -8138,11 +8194,11 @@ msgstr "" ":term:`型別註釋 ` 的核心內建型別是\\ :ref:`泛型別名 `\\ 和\\ :ref:`聯合 `。" -#: ../../library/stdtypes.rst:5673 +#: ../../library/stdtypes.rst:5707 msgid "Generic Alias Type" msgstr "泛型別名型別" -#: ../../library/stdtypes.rst:5679 +#: ../../library/stdtypes.rst:5713 msgid "" "``GenericAlias`` objects are generally created by :ref:`subscripting " "` a class. They are most often used with :ref:`container " @@ -8158,7 +8214,7 @@ msgstr "" "立的。``GenericAlias`` 物件主要會與\\ :term:`型別註釋 ` 一起使" "用。" -#: ../../library/stdtypes.rst:5689 +#: ../../library/stdtypes.rst:5723 msgid "" "It is generally only possible to subscript a class if the class implements " "the special method :meth:`~object.__class_getitem__`." @@ -8166,7 +8222,7 @@ msgstr "" "通常只有當類別有實作特殊方法 :meth:`~object.__class_getitem__` 時才可以去下標" "該類別。" -#: ../../library/stdtypes.rst:5692 +#: ../../library/stdtypes.rst:5726 msgid "" "A ``GenericAlias`` object acts as a proxy for a :term:`generic type`, " "implementing *parameterized generics*." @@ -8174,7 +8230,7 @@ msgstr "" "將一個 ``GenericAlias`` 物件用作 :term:`generic type` 的代理,實作\\ *參數化" "泛型 (parameterized generics)*。" -#: ../../library/stdtypes.rst:5695 +#: ../../library/stdtypes.rst:5729 msgid "" "For a container class, the argument(s) supplied to a :ref:`subscription " "` of the class may indicate the type(s) of the elements an " @@ -8186,7 +8242,7 @@ msgstr "" "物件所包含元素的型別。例如 ``set[bytes]`` 可以用於型別註釋來表示一個 :class:" "`set`,其中所有元素的型別都是 :class:`bytes`。" -#: ../../library/stdtypes.rst:5701 +#: ../../library/stdtypes.rst:5735 msgid "" "For a class which defines :meth:`~object.__class_getitem__` but is not a " "container, the argument(s) supplied to a subscription of the class will " @@ -8198,7 +8254,7 @@ msgstr "" "標引數通常會指示物件上有定義的一個或多個方法的回傳型別。例如\\ :mod:`正規表示" "式 `\\ 可以用於 :class:`str` 和 :class:`bytes` 資料型別:" -#: ../../library/stdtypes.rst:5707 +#: ../../library/stdtypes.rst:5741 msgid "" "If ``x = re.search('foo', 'foo')``, ``x`` will be a :ref:`re.Match ` object where the return values of ``x.group(0)`` and ``x[0]`` will " @@ -8210,7 +8266,7 @@ msgstr "" "別。我們就可以用 ``GenericAlias`` ``re.Match[str]`` 在型別註釋中表示這種物" "件。" -#: ../../library/stdtypes.rst:5713 +#: ../../library/stdtypes.rst:5747 msgid "" "If ``y = re.search(b'bar', b'bar')``, (note the ``b`` for :class:`bytes`), " "``y`` will also be an instance of ``re.Match``, but the return values of ``y." @@ -8223,7 +8279,7 @@ msgstr "" "別都是 :class:`bytes`。在型別註釋中,我們將用 ``re.Match[bytes]`` 來表示各" "種 :ref:`re.Match ` 物件。" -#: ../../library/stdtypes.rst:5719 +#: ../../library/stdtypes.rst:5753 msgid "" "``GenericAlias`` objects are instances of the class :class:`types." "GenericAlias`, which can also be used to create ``GenericAlias`` objects " @@ -8232,7 +8288,7 @@ msgstr "" "``GenericAlias`` 物件是 :class:`types.GenericAlias` 類別的實例,也可以用來直" "接建立 ``GenericAlias`` 物件。" -#: ../../library/stdtypes.rst:5725 +#: ../../library/stdtypes.rst:5759 msgid "" "Creates a ``GenericAlias`` representing a type ``T`` parameterized by types " "*X*, *Y*, and more depending on the ``T`` used. For example, a function " @@ -8242,7 +8298,7 @@ msgstr "" "所使用的 ``T``)來參數化。例如,一個函式需要一個包含 :class:`float` 元素的 :" "class:`list`: ::" -#: ../../library/stdtypes.rst:5730 +#: ../../library/stdtypes.rst:5764 msgid "" "def average(values: list[float]) -> float:\n" " return sum(values) / len(values)" @@ -8250,7 +8306,7 @@ msgstr "" "def average(values: list[float]) -> float:\n" " return sum(values) / len(values)" -#: ../../library/stdtypes.rst:5733 +#: ../../library/stdtypes.rst:5767 msgid "" "Another example for :term:`mapping` objects, using a :class:`dict`, which is " "a generic type expecting two type parameters representing the key type and " @@ -8261,7 +8317,7 @@ msgstr "" "別,需要兩個型別參數,分別表示鍵型別和值型別。在此範例中,函式需要一個 " "``dict``,其帶有 :class:`str` 型別的鍵和 :class:`int` 型別的值: ::" -#: ../../library/stdtypes.rst:5738 +#: ../../library/stdtypes.rst:5772 msgid "" "def send_post_request(url: str, body: dict[str, int]) -> None:\n" " ..." @@ -8269,7 +8325,7 @@ msgstr "" "def send_post_request(url: str, body: dict[str, int]) -> None:\n" " ..." -#: ../../library/stdtypes.rst:5741 +#: ../../library/stdtypes.rst:5775 msgid "" "The builtin functions :func:`isinstance` and :func:`issubclass` do not " "accept ``GenericAlias`` types for their second argument::" @@ -8277,7 +8333,7 @@ msgstr "" "內建函式 :func:`isinstance` 和 :func:`issubclass` 不接受 ``GenericAlias`` 型" "別作為第二個引數: ::" -#: ../../library/stdtypes.rst:5744 +#: ../../library/stdtypes.rst:5778 msgid "" ">>> isinstance([1, 2], list[str])\n" "Traceback (most recent call last):\n" @@ -8289,7 +8345,7 @@ msgstr "" " File \"\", line 1, in \n" "TypeError: isinstance() argument 2 cannot be a parameterized generic" -#: ../../library/stdtypes.rst:5749 +#: ../../library/stdtypes.rst:5783 msgid "" "The Python runtime does not enforce :term:`type annotations `. " "This extends to generic types and their type parameters. When creating a " @@ -8301,7 +8357,7 @@ msgstr "" "及其型別參數。當從 ``GenericAlias`` 建立容器物件時,不會檢查容器中元素的型" "別。例如,不鼓勵使用以下程式碼,但 runtime 不會出現錯誤: ::" -#: ../../library/stdtypes.rst:5755 +#: ../../library/stdtypes.rst:5789 msgid "" ">>> t = list[str]\n" ">>> t([1, 2, 3])\n" @@ -8311,13 +8367,13 @@ msgstr "" ">>> t([1, 2, 3])\n" "[1, 2, 3]" -#: ../../library/stdtypes.rst:5759 +#: ../../library/stdtypes.rst:5793 msgid "" "Furthermore, parameterized generics erase type parameters during object " "creation::" msgstr "此外,參數化泛型在物件建立期間會擦除 (erase) 型別參數: ::" -#: ../../library/stdtypes.rst:5762 +#: ../../library/stdtypes.rst:5796 msgid "" ">>> t = list[str]\n" ">>> type(t)\n" @@ -8335,13 +8391,13 @@ msgstr "" ">>> type(l)\n" "" -#: ../../library/stdtypes.rst:5770 +#: ../../library/stdtypes.rst:5804 msgid "" "Calling :func:`repr` or :func:`str` on a generic shows the parameterized " "type::" msgstr "在泛型上呼叫 :func:`repr` 或 :func:`str` 會顯示參數化型別: ::" -#: ../../library/stdtypes.rst:5772 +#: ../../library/stdtypes.rst:5806 msgid "" ">>> repr(list[int])\n" "'list[int]'\n" @@ -8355,7 +8411,7 @@ msgstr "" ">>> str(list[int])\n" "'list[int]'" -#: ../../library/stdtypes.rst:5778 +#: ../../library/stdtypes.rst:5812 msgid "" "The :meth:`~object.__getitem__` method of generic containers will raise an " "exception to disallow mistakes like ``dict[str][str]``::" @@ -8363,7 +8419,7 @@ msgstr "" "為防止像是 ``dict[str][str]`` 的錯誤出現,泛型容器的 :meth:`~object." "__getitem__` 方法會在這種情況下引發例外: ::" -#: ../../library/stdtypes.rst:5781 +#: ../../library/stdtypes.rst:5815 msgid "" ">>> dict[str][str]\n" "Traceback (most recent call last):\n" @@ -8375,7 +8431,7 @@ msgstr "" " ...\n" "TypeError: dict[str] is not a generic class" -#: ../../library/stdtypes.rst:5786 +#: ../../library/stdtypes.rst:5820 msgid "" "However, such expressions are valid when :ref:`type variables ` " "are used. The index must have as many elements as there are type variable " @@ -8385,7 +8441,7 @@ msgstr "" "的。索引的元素數量必須與 ``GenericAlias`` 物件的 :attr:`~genericalias." "__args__` 中的型別變數項目一樣多: ::" -#: ../../library/stdtypes.rst:5790 +#: ../../library/stdtypes.rst:5824 msgid "" ">>> from typing import TypeVar\n" ">>> Y = TypeVar('Y')\n" @@ -8397,253 +8453,253 @@ msgstr "" ">>> dict[str, Y][int]\n" "dict[str, int]" -#: ../../library/stdtypes.rst:5797 +#: ../../library/stdtypes.rst:5831 msgid "Standard Generic Classes" msgstr "標準泛型類別" -#: ../../library/stdtypes.rst:5799 +#: ../../library/stdtypes.rst:5833 msgid "" "The following standard library classes support parameterized generics. This " "list is non-exhaustive." msgstr "以下標準函式庫類別有支援參數化泛型。此列表並非詳盡無遺。" -#: ../../library/stdtypes.rst:5802 +#: ../../library/stdtypes.rst:5836 msgid ":class:`tuple`" msgstr ":class:`tuple`" -#: ../../library/stdtypes.rst:5803 +#: ../../library/stdtypes.rst:5837 msgid ":class:`list`" msgstr ":class:`list`" -#: ../../library/stdtypes.rst:5804 +#: ../../library/stdtypes.rst:5838 msgid ":class:`dict`" msgstr ":class:`dict`" -#: ../../library/stdtypes.rst:5805 +#: ../../library/stdtypes.rst:5839 msgid ":class:`set`" msgstr ":class:`set`" -#: ../../library/stdtypes.rst:5806 +#: ../../library/stdtypes.rst:5840 msgid ":class:`frozenset`" msgstr ":class:`frozenset`" -#: ../../library/stdtypes.rst:5807 +#: ../../library/stdtypes.rst:5841 msgid ":class:`type`" msgstr ":class:`type`" -#: ../../library/stdtypes.rst:5808 +#: ../../library/stdtypes.rst:5842 msgid ":class:`asyncio.Future`" msgstr ":class:`asyncio.Future`" -#: ../../library/stdtypes.rst:5809 +#: ../../library/stdtypes.rst:5843 msgid ":class:`asyncio.Task`" msgstr ":class:`asyncio.Task`" -#: ../../library/stdtypes.rst:5810 +#: ../../library/stdtypes.rst:5844 msgid ":class:`collections.deque`" msgstr ":class:`collections.deque`" -#: ../../library/stdtypes.rst:5811 +#: ../../library/stdtypes.rst:5845 msgid ":class:`collections.defaultdict`" msgstr ":class:`collections.defaultdict`" -#: ../../library/stdtypes.rst:5812 +#: ../../library/stdtypes.rst:5846 msgid ":class:`collections.OrderedDict`" msgstr ":class:`collections.OrderedDict`" -#: ../../library/stdtypes.rst:5813 +#: ../../library/stdtypes.rst:5847 msgid ":class:`collections.Counter`" msgstr ":class:`collections.Counter`" -#: ../../library/stdtypes.rst:5814 +#: ../../library/stdtypes.rst:5848 msgid ":class:`collections.ChainMap`" msgstr ":class:`collections.ChainMap`" -#: ../../library/stdtypes.rst:5815 +#: ../../library/stdtypes.rst:5849 msgid ":class:`collections.abc.Awaitable`" msgstr ":class:`collections.abc.Awaitable`" -#: ../../library/stdtypes.rst:5816 +#: ../../library/stdtypes.rst:5850 msgid ":class:`collections.abc.Coroutine`" msgstr ":class:`collections.abc.Coroutine`" -#: ../../library/stdtypes.rst:5817 +#: ../../library/stdtypes.rst:5851 msgid ":class:`collections.abc.AsyncIterable`" msgstr ":class:`collections.abc.AsyncIterable`" -#: ../../library/stdtypes.rst:5818 +#: ../../library/stdtypes.rst:5852 msgid ":class:`collections.abc.AsyncIterator`" msgstr ":class:`collections.abc.AsyncIterator`" -#: ../../library/stdtypes.rst:5819 +#: ../../library/stdtypes.rst:5853 msgid ":class:`collections.abc.AsyncGenerator`" msgstr ":class:`collections.abc.AsyncGenerator`" -#: ../../library/stdtypes.rst:5820 +#: ../../library/stdtypes.rst:5854 msgid ":class:`collections.abc.Iterable`" msgstr ":class:`collections.abc.Iterable`" -#: ../../library/stdtypes.rst:5821 +#: ../../library/stdtypes.rst:5855 msgid ":class:`collections.abc.Iterator`" msgstr ":class:`collections.abc.Iterator`" -#: ../../library/stdtypes.rst:5822 +#: ../../library/stdtypes.rst:5856 msgid ":class:`collections.abc.Generator`" msgstr ":class:`collections.abc.Generator`" -#: ../../library/stdtypes.rst:5823 +#: ../../library/stdtypes.rst:5857 msgid ":class:`collections.abc.Reversible`" msgstr ":class:`collections.abc.Reversible`" -#: ../../library/stdtypes.rst:5824 +#: ../../library/stdtypes.rst:5858 msgid ":class:`collections.abc.Container`" msgstr ":class:`collections.abc.Container`" -#: ../../library/stdtypes.rst:5825 +#: ../../library/stdtypes.rst:5859 msgid ":class:`collections.abc.Collection`" msgstr ":class:`collections.abc.Collection`" -#: ../../library/stdtypes.rst:5826 +#: ../../library/stdtypes.rst:5860 msgid ":class:`collections.abc.Callable`" msgstr ":class:`collections.abc.Callable`" -#: ../../library/stdtypes.rst:5827 +#: ../../library/stdtypes.rst:5861 msgid ":class:`collections.abc.Set`" msgstr ":class:`collections.abc.Set`" -#: ../../library/stdtypes.rst:5828 +#: ../../library/stdtypes.rst:5862 msgid ":class:`collections.abc.MutableSet`" msgstr ":class:`collections.abc.MutableSet`" -#: ../../library/stdtypes.rst:5829 +#: ../../library/stdtypes.rst:5863 msgid ":class:`collections.abc.Mapping`" msgstr ":class:`collections.abc.Mapping`" -#: ../../library/stdtypes.rst:5830 +#: ../../library/stdtypes.rst:5864 msgid ":class:`collections.abc.MutableMapping`" msgstr ":class:`collections.abc.MutableMapping`" -#: ../../library/stdtypes.rst:5831 +#: ../../library/stdtypes.rst:5865 msgid ":class:`collections.abc.Sequence`" msgstr ":class:`collections.abc.Sequence`" -#: ../../library/stdtypes.rst:5832 +#: ../../library/stdtypes.rst:5866 msgid ":class:`collections.abc.MutableSequence`" msgstr ":class:`collections.abc.MutableSequence`" -#: ../../library/stdtypes.rst:5833 +#: ../../library/stdtypes.rst:5867 msgid ":class:`collections.abc.ByteString`" msgstr ":class:`collections.abc.ByteString`" -#: ../../library/stdtypes.rst:5834 +#: ../../library/stdtypes.rst:5868 msgid ":class:`collections.abc.MappingView`" msgstr ":class:`collections.abc.MappingView`" -#: ../../library/stdtypes.rst:5835 +#: ../../library/stdtypes.rst:5869 msgid ":class:`collections.abc.KeysView`" msgstr ":class:`collections.abc.KeysView`" -#: ../../library/stdtypes.rst:5836 +#: ../../library/stdtypes.rst:5870 msgid ":class:`collections.abc.ItemsView`" msgstr ":class:`collections.abc.ItemsView`" -#: ../../library/stdtypes.rst:5837 +#: ../../library/stdtypes.rst:5871 msgid ":class:`collections.abc.ValuesView`" msgstr ":class:`collections.abc.ValuesView`" -#: ../../library/stdtypes.rst:5838 +#: ../../library/stdtypes.rst:5872 msgid ":class:`contextlib.AbstractContextManager`" msgstr ":class:`contextlib.AbstractContextManager`" -#: ../../library/stdtypes.rst:5839 +#: ../../library/stdtypes.rst:5873 msgid ":class:`contextlib.AbstractAsyncContextManager`" msgstr ":class:`contextlib.AbstractAsyncContextManager`" -#: ../../library/stdtypes.rst:5840 +#: ../../library/stdtypes.rst:5874 msgid ":class:`dataclasses.Field`" msgstr ":class:`dataclasses.Field`" -#: ../../library/stdtypes.rst:5841 +#: ../../library/stdtypes.rst:5875 msgid ":class:`functools.cached_property`" msgstr ":class:`functools.cached_property`" -#: ../../library/stdtypes.rst:5842 +#: ../../library/stdtypes.rst:5876 msgid ":class:`functools.partialmethod`" msgstr ":class:`functools.partialmethod`" -#: ../../library/stdtypes.rst:5843 +#: ../../library/stdtypes.rst:5877 msgid ":class:`os.PathLike`" msgstr ":class:`os.PathLike`" -#: ../../library/stdtypes.rst:5844 +#: ../../library/stdtypes.rst:5878 msgid ":class:`queue.LifoQueue`" msgstr ":class:`queue.LifoQueue`" -#: ../../library/stdtypes.rst:5845 +#: ../../library/stdtypes.rst:5879 msgid ":class:`queue.Queue`" msgstr ":class:`queue.Queue`" -#: ../../library/stdtypes.rst:5846 +#: ../../library/stdtypes.rst:5880 msgid ":class:`queue.PriorityQueue`" msgstr ":class:`queue.PriorityQueue`" -#: ../../library/stdtypes.rst:5847 +#: ../../library/stdtypes.rst:5881 msgid ":class:`queue.SimpleQueue`" msgstr ":class:`queue.SimpleQueue`" -#: ../../library/stdtypes.rst:5848 +#: ../../library/stdtypes.rst:5882 msgid ":ref:`re.Pattern `" msgstr ":ref:`re.Pattern `" -#: ../../library/stdtypes.rst:5849 +#: ../../library/stdtypes.rst:5883 msgid ":ref:`re.Match `" msgstr ":ref:`re.Match `" -#: ../../library/stdtypes.rst:5850 +#: ../../library/stdtypes.rst:5884 msgid ":class:`shelve.BsdDbShelf`" msgstr ":class:`shelve.BsdDbShelf`" -#: ../../library/stdtypes.rst:5851 +#: ../../library/stdtypes.rst:5885 msgid ":class:`shelve.DbfilenameShelf`" msgstr ":class:`shelve.DbfilenameShelf`" -#: ../../library/stdtypes.rst:5852 +#: ../../library/stdtypes.rst:5886 msgid ":class:`shelve.Shelf`" msgstr ":class:`shelve.Shelf`" -#: ../../library/stdtypes.rst:5853 +#: ../../library/stdtypes.rst:5887 msgid ":class:`types.MappingProxyType`" msgstr ":class:`types.MappingProxyType`" -#: ../../library/stdtypes.rst:5854 +#: ../../library/stdtypes.rst:5888 msgid ":class:`weakref.WeakKeyDictionary`" msgstr ":class:`weakref.WeakKeyDictionary`" -#: ../../library/stdtypes.rst:5855 +#: ../../library/stdtypes.rst:5889 msgid ":class:`weakref.WeakMethod`" msgstr ":class:`weakref.WeakMethod`" -#: ../../library/stdtypes.rst:5856 +#: ../../library/stdtypes.rst:5890 msgid ":class:`weakref.WeakSet`" msgstr ":class:`weakref.WeakSet`" -#: ../../library/stdtypes.rst:5857 +#: ../../library/stdtypes.rst:5891 msgid ":class:`weakref.WeakValueDictionary`" msgstr ":class:`weakref.WeakValueDictionary`" -#: ../../library/stdtypes.rst:5862 +#: ../../library/stdtypes.rst:5896 msgid "Special Attributes of ``GenericAlias`` objects" msgstr "``GenericAlias`` 物件的特殊屬性" -#: ../../library/stdtypes.rst:5864 +#: ../../library/stdtypes.rst:5898 msgid "All parameterized generics implement special read-only attributes." msgstr "所有參數化泛型都有實作特殊的唯讀屬性。" -#: ../../library/stdtypes.rst:5868 +#: ../../library/stdtypes.rst:5902 msgid "This attribute points at the non-parameterized generic class::" msgstr "此屬性指向非參數化泛型類別: ::" -#: ../../library/stdtypes.rst:5870 +#: ../../library/stdtypes.rst:5904 msgid "" ">>> list[int].__origin__\n" "" @@ -8651,7 +8707,7 @@ msgstr "" ">>> list[int].__origin__\n" "" -#: ../../library/stdtypes.rst:5876 +#: ../../library/stdtypes.rst:5910 msgid "" "This attribute is a :class:`tuple` (possibly of length 1) of generic types " "passed to the original :meth:`~object.__class_getitem__` of the generic " @@ -8660,7 +8716,7 @@ msgstr "" "此屬性是傳遞給泛型類別之原始 :meth:`~object.__class_getitem__` 的泛型型別 :" "class:`tuple`\\ (長度可以為 1): ::" -#: ../../library/stdtypes.rst:5880 +#: ../../library/stdtypes.rst:5914 msgid "" ">>> dict[str, list[int]].__args__\n" "(, list[int])" @@ -8668,7 +8724,7 @@ msgstr "" ">>> dict[str, list[int]].__args__\n" "(, list[int])" -#: ../../library/stdtypes.rst:5886 +#: ../../library/stdtypes.rst:5920 msgid "" "This attribute is a lazily computed tuple (possibly empty) of unique type " "variables found in ``__args__``::" @@ -8676,7 +8732,7 @@ msgstr "" "此屬性是個會被延遲計算 (lazily computed) 的元組(可能為空),包含了在 " "``__args__`` 中找得到的不重複型別變數: ::" -#: ../../library/stdtypes.rst:5889 +#: ../../library/stdtypes.rst:5923 msgid "" ">>> from typing import TypeVar\n" "\n" @@ -8690,7 +8746,7 @@ msgstr "" ">>> list[T].__parameters__\n" "(~T,)" -#: ../../library/stdtypes.rst:5897 +#: ../../library/stdtypes.rst:5931 msgid "" "A ``GenericAlias`` object with :class:`typing.ParamSpec` parameters may not " "have correct ``__parameters__`` after substitution because :class:`typing." @@ -8700,7 +8756,7 @@ msgstr "" "有正確的 ``__parameters__``,因為 :class:`typing.ParamSpec` 主要用於靜態型別" "檢查。" -#: ../../library/stdtypes.rst:5904 +#: ../../library/stdtypes.rst:5938 msgid "" "A boolean that is true if the alias has been unpacked using the ``*`` " "operator (see :data:`~typing.TypeVarTuple`)." @@ -8708,19 +8764,19 @@ msgstr "" "如果別名已使用 ``*`` 運算子解包 (unpack) 則為 true 的布林值(請參閱 :data:" "`~typing.TypeVarTuple`\\ )。" -#: ../../library/stdtypes.rst:5912 +#: ../../library/stdtypes.rst:5946 msgid ":pep:`484` - Type Hints" msgstr ":pep:`484` - 型別提示" -#: ../../library/stdtypes.rst:5913 +#: ../../library/stdtypes.rst:5947 msgid "Introducing Python's framework for type annotations." msgstr "引入 Python 的型別註釋框架。" -#: ../../library/stdtypes.rst:5915 +#: ../../library/stdtypes.rst:5949 msgid ":pep:`585` - Type Hinting Generics In Standard Collections" msgstr ":pep:`585` - 標準集合 (Standard Collections) 中的型別提示泛型" -#: ../../library/stdtypes.rst:5916 +#: ../../library/stdtypes.rst:5950 msgid "" "Introducing the ability to natively parameterize standard-library classes, " "provided they implement the special class method :meth:`~object." @@ -8729,7 +8785,7 @@ msgstr "" "引入原生參數化標準函式庫類別的能力,前提是它們有實作特殊的類別方法 :meth:" "`~object.__class_getitem__`。" -#: ../../library/stdtypes.rst:5920 +#: ../../library/stdtypes.rst:5954 msgid "" ":ref:`Generics`, :ref:`user-defined generics ` and :" "class:`typing.Generic`" @@ -8737,18 +8793,18 @@ msgstr "" ":ref:`Generics`、:ref:`使用者定義泛型 `\\ 和 :class:" "`typing.Generic`" -#: ../../library/stdtypes.rst:5921 +#: ../../library/stdtypes.rst:5955 msgid "" "Documentation on how to implement generic classes that can be parameterized " "at runtime and understood by static type-checkers." msgstr "" "有關如何實作可以在 runtime 參數化並能被靜態型別檢查器理解的泛型類別的文件。" -#: ../../library/stdtypes.rst:5930 +#: ../../library/stdtypes.rst:5964 msgid "Union Type" msgstr "聯合型別 (Union Type)" -#: ../../library/stdtypes.rst:5936 +#: ../../library/stdtypes.rst:5970 msgid "" "A union object holds the value of the ``|`` (bitwise or) operation on " "multiple :ref:`type objects `. These types are intended " @@ -8761,7 +8817,7 @@ msgstr "" "釋 (type annotation) `。與下標 :data:`typing.Union` 相比,聯合型" "別運算式可以讓型別提示語法更清晰簡潔。" -#: ../../library/stdtypes.rst:5943 +#: ../../library/stdtypes.rst:5977 msgid "" "Defines a union object which holds types *X*, *Y*, and so forth. ``X | Y`` " "means either X or Y. It is equivalent to ``typing.Union[X, Y]``. For " @@ -8772,7 +8828,7 @@ msgstr "" "``typing.Union[X, Y]``。舉例來說,下列函式需要一個型別為 :class:`int` 或 :" "class:`float` 的引數: ::" -#: ../../library/stdtypes.rst:5948 +#: ../../library/stdtypes.rst:5982 msgid "" "def square(number: int | float) -> int | float:\n" " return number ** 2" @@ -8780,7 +8836,7 @@ msgstr "" "def square(number: int | float) -> int | float:\n" " return number ** 2" -#: ../../library/stdtypes.rst:5953 +#: ../../library/stdtypes.rst:5987 msgid "" "The ``|`` operand cannot be used at runtime to define unions where one or " "more members is a forward reference. For example, ``int | \"Foo\"``, where " @@ -8793,40 +8849,40 @@ msgstr "" "義類別的參照,將在 runtime 失敗。對於包含向前參照的聯合,請將整個運算式以字串" "呈現,例如 ``\"int | Foo\"``。" -#: ../../library/stdtypes.rst:5961 +#: ../../library/stdtypes.rst:5995 msgid "" "Union objects can be tested for equality with other union objects. Details:" msgstr "聯合物件可以與其他聯合物件一起進行相等性測試。細節如下:" -#: ../../library/stdtypes.rst:5963 +#: ../../library/stdtypes.rst:5997 msgid "Unions of unions are flattened::" msgstr "聯合的聯合會被扁平化: ::" -#: ../../library/stdtypes.rst:5965 +#: ../../library/stdtypes.rst:5999 msgid "(int | str) | float == int | str | float" msgstr "(int | str) | float == int | str | float" -#: ../../library/stdtypes.rst:5967 +#: ../../library/stdtypes.rst:6001 msgid "Redundant types are removed::" msgstr "冗餘型別會被刪除: ::" -#: ../../library/stdtypes.rst:5969 +#: ../../library/stdtypes.rst:6003 msgid "int | str | int == int | str" msgstr "int | str | int == int | str" -#: ../../library/stdtypes.rst:5971 +#: ../../library/stdtypes.rst:6005 msgid "When comparing unions, the order is ignored::" msgstr "比較聯合時,順序會被忽略: ::" -#: ../../library/stdtypes.rst:5973 +#: ../../library/stdtypes.rst:6007 msgid "int | str == str | int" msgstr "int | str == str | int" -#: ../../library/stdtypes.rst:5975 +#: ../../library/stdtypes.rst:6009 msgid "It creates instances of :class:`typing.Union`::" msgstr "它會建立 :class:`typing.Union` 的實例: ::" -#: ../../library/stdtypes.rst:5977 +#: ../../library/stdtypes.rst:6011 msgid "" "int | str == typing.Union[int, str]\n" "type(int | str) is typing.Union" @@ -8834,21 +8890,21 @@ msgstr "" "int | str == typing.Union[int, str]\n" "type(int | str) is typing.Union" -#: ../../library/stdtypes.rst:5980 +#: ../../library/stdtypes.rst:6014 msgid "Optional types can be spelled as a union with ``None``::" msgstr "可選型別可以表示為與 ``None`` 的聯合: ::" -#: ../../library/stdtypes.rst:5982 +#: ../../library/stdtypes.rst:6016 msgid "str | None == typing.Optional[str]" msgstr "str | None == typing.Optional[str]" -#: ../../library/stdtypes.rst:5987 +#: ../../library/stdtypes.rst:6021 msgid "" "Calls to :func:`isinstance` and :func:`issubclass` are also supported with a " "union object::" msgstr "聯合物件也支援 :func:`isinstance` 和 :func:`issubclass` 的呼叫: ::" -#: ../../library/stdtypes.rst:5990 +#: ../../library/stdtypes.rst:6024 msgid "" ">>> isinstance(\"\", int | str)\n" "True" @@ -8856,14 +8912,14 @@ msgstr "" ">>> isinstance(\"\", int | str)\n" "True" -#: ../../library/stdtypes.rst:5993 +#: ../../library/stdtypes.rst:6027 msgid "" "However, :ref:`parameterized generics ` in union objects " "cannot be checked::" msgstr "" "然而聯合物件中的\\ :ref:`參數化泛型 `\\ 則無法被檢查: ::" -#: ../../library/stdtypes.rst:5996 +#: ../../library/stdtypes.rst:6030 msgid "" ">>> isinstance(1, int | list[int]) # short-circuit evaluation\n" "True\n" @@ -8873,7 +8929,7 @@ msgid "" "TypeError: isinstance() argument 2 cannot be a parameterized generic" msgstr "" -#: ../../library/stdtypes.rst:6003 +#: ../../library/stdtypes.rst:6037 msgid "" "The user-exposed type for the union object can be accessed from :class:" "`typing.Union` and used for :func:`isinstance` checks::" @@ -8881,7 +8937,7 @@ msgstr "" "構成聯合物件的對使用者公開型別 (user-exposed type) 可以透過 :data:`typing." "Union` 存取並用於 :func:`isinstance` 檢查: ::" -#: ../../library/stdtypes.rst:6006 +#: ../../library/stdtypes.rst:6040 msgid "" ">>> import typing\n" ">>> isinstance(int | str, typing.Union)\n" @@ -8899,7 +8955,7 @@ msgstr "" " File \"\", line 1, in \n" "TypeError: cannot create 'typing.Union' instances" -#: ../../library/stdtypes.rst:6015 +#: ../../library/stdtypes.rst:6049 msgid "" "The :meth:`!__or__` method for type objects was added to support the syntax " "``X | Y``. If a metaclass implements :meth:`!__or__`, the Union may " @@ -8908,7 +8964,7 @@ msgstr "" "新增了型別物件的 :meth:`!__or__` 方法來支援 ``X | Y`` 語法。如果元類別有實" "作 :meth:`!__or__`,則 Union 可以覆寫 (override) 它: ::" -#: ../../library/stdtypes.rst:6019 +#: ../../library/stdtypes.rst:6053 msgid "" ">>> class M(type):\n" "... def __or__(self, other):\n" @@ -8934,32 +8990,32 @@ msgstr "" ">>> int | C\n" "int | C" -#: ../../library/stdtypes.rst:6035 +#: ../../library/stdtypes.rst:6069 msgid ":pep:`604` -- PEP proposing the ``X | Y`` syntax and the Union type." msgstr ":pep:`604` -- PEP 提出 ``X | Y`` 語法和聯合型別。" -#: ../../library/stdtypes.rst:6041 +#: ../../library/stdtypes.rst:6075 msgid "" "Union objects are now instances of :class:`typing.Union`. Previously, they " "were instances of :class:`types.UnionType`, which remains an alias for :" "class:`typing.Union`." msgstr "" -#: ../../library/stdtypes.rst:6048 +#: ../../library/stdtypes.rst:6082 msgid "Other Built-in Types" msgstr "其他內建型別" -#: ../../library/stdtypes.rst:6050 +#: ../../library/stdtypes.rst:6084 msgid "" "The interpreter supports several other kinds of objects. Most of these " "support only one or two operations." msgstr "" -#: ../../library/stdtypes.rst:6057 +#: ../../library/stdtypes.rst:6091 msgid "Modules" msgstr "模組" -#: ../../library/stdtypes.rst:6059 +#: ../../library/stdtypes.rst:6093 msgid "" "The only special operation on a module is attribute access: ``m.name``, " "where *m* is a module and *name* accesses a name defined in *m*'s symbol " @@ -8970,7 +9026,7 @@ msgid "" "*foo* somewhere.)" msgstr "" -#: ../../library/stdtypes.rst:6066 +#: ../../library/stdtypes.rst:6100 msgid "" "A special attribute of every module is :attr:`~object.__dict__`. This is the " "dictionary containing the module's symbol table. Modifying this dictionary " @@ -8981,32 +9037,32 @@ msgid "" "recommended." msgstr "" -#: ../../library/stdtypes.rst:6074 +#: ../../library/stdtypes.rst:6108 msgid "" "Modules built into the interpreter are written like this: ````. If loaded from a file, they are written as ````." msgstr "" -#: ../../library/stdtypes.rst:6082 +#: ../../library/stdtypes.rst:6116 msgid "Classes and Class Instances" msgstr "類別與類別實例" -#: ../../library/stdtypes.rst:6084 +#: ../../library/stdtypes.rst:6118 msgid "See :ref:`objects` and :ref:`class` for these." msgstr "請見 :ref:`objects` 和 :ref:`class`。" -#: ../../library/stdtypes.rst:6090 +#: ../../library/stdtypes.rst:6124 msgid "Functions" msgstr "函式" -#: ../../library/stdtypes.rst:6092 +#: ../../library/stdtypes.rst:6126 msgid "" "Function objects are created by function definitions. The only operation on " "a function object is to call it: ``func(argument-list)``." msgstr "" -#: ../../library/stdtypes.rst:6095 +#: ../../library/stdtypes.rst:6129 msgid "" "There are really two flavors of function objects: built-in functions and " "user-defined functions. Both support the same operation (to call the " @@ -9014,15 +9070,15 @@ msgid "" "types." msgstr "" -#: ../../library/stdtypes.rst:6099 +#: ../../library/stdtypes.rst:6133 msgid "See :ref:`function` for more information." msgstr "更多資訊請見 :ref:`function`。" -#: ../../library/stdtypes.rst:6105 +#: ../../library/stdtypes.rst:6139 msgid "Methods" msgstr "方法" -#: ../../library/stdtypes.rst:6109 +#: ../../library/stdtypes.rst:6143 msgid "" "Methods are functions that are called using the attribute notation. There " "are two flavors: :ref:`built-in methods ` (such as :meth:" @@ -9030,7 +9086,7 @@ msgid "" "methods>`. Built-in methods are described with the types that support them." msgstr "" -#: ../../library/stdtypes.rst:6115 +#: ../../library/stdtypes.rst:6149 msgid "" "If you access a method (a function defined in a class namespace) through an " "instance, you get a special object: a :dfn:`bound method` (also called :ref:" @@ -9043,7 +9099,7 @@ msgid "" "arg-2, ..., arg-n)``." msgstr "" -#: ../../library/stdtypes.rst:6126 +#: ../../library/stdtypes.rst:6160 msgid "" "Like :ref:`function objects `, bound method objects " "support getting arbitrary attributes. However, since method attributes are " @@ -9054,7 +9110,7 @@ msgid "" "underlying function object:" msgstr "" -#: ../../library/stdtypes.rst:6134 +#: ../../library/stdtypes.rst:6168 msgid "" ">>> class C:\n" "... def method(self):\n" @@ -9082,15 +9138,15 @@ msgstr "" ">>> c.method.whoami\n" "'my name is method'" -#: ../../library/stdtypes.rst:6149 +#: ../../library/stdtypes.rst:6183 msgid "See :ref:`instance-methods` for more information." msgstr "更多資訊請見 :ref:`instance-methods`。" -#: ../../library/stdtypes.rst:6157 +#: ../../library/stdtypes.rst:6191 msgid "Code Objects" msgstr "程式碼物件" -#: ../../library/stdtypes.rst:6163 +#: ../../library/stdtypes.rst:6197 msgid "" "Code objects are used by the implementation to represent \"pseudo-compiled\" " "executable Python code such as a function body. They differ from function " @@ -9100,7 +9156,7 @@ msgid "" "`~function.__code__` attribute. See also the :mod:`code` module." msgstr "" -#: ../../library/stdtypes.rst:6170 +#: ../../library/stdtypes.rst:6204 msgid "" "Accessing :attr:`~function.__code__` raises an :ref:`auditing event " "` ``object.__getattr__`` with arguments ``obj`` and " @@ -9109,21 +9165,21 @@ msgstr "" "存取 :attr:`~function.__code__` 會引發一個附帶引數 ``obj`` 與 " "``\"__code__\"`` 的\\ :ref:`稽核事件 ` ``object.__getattr__``。" -#: ../../library/stdtypes.rst:6177 +#: ../../library/stdtypes.rst:6211 msgid "" "A code object can be executed or evaluated by passing it (instead of a " "source string) to the :func:`exec` or :func:`eval` built-in functions." msgstr "" -#: ../../library/stdtypes.rst:6180 +#: ../../library/stdtypes.rst:6214 msgid "See :ref:`types` for more information." msgstr "更多資訊請見 :ref:`types`。" -#: ../../library/stdtypes.rst:6186 +#: ../../library/stdtypes.rst:6220 msgid "Type Objects" msgstr "" -#: ../../library/stdtypes.rst:6192 +#: ../../library/stdtypes.rst:6226 msgid "" "Type objects represent the various object types. An object's type is " "accessed by the built-in function :func:`type`. There are no special " @@ -9131,30 +9187,30 @@ msgid "" "standard built-in types." msgstr "" -#: ../../library/stdtypes.rst:6197 +#: ../../library/stdtypes.rst:6231 msgid "Types are written like this: ````." msgstr "" -#: ../../library/stdtypes.rst:6203 +#: ../../library/stdtypes.rst:6237 msgid "The Null Object" msgstr "Null 物件" -#: ../../library/stdtypes.rst:6205 +#: ../../library/stdtypes.rst:6239 msgid "" "This object is returned by functions that don't explicitly return a value. " "It supports no special operations. There is exactly one null object, named " "``None`` (a built-in name). ``type(None)()`` produces the same singleton." msgstr "" -#: ../../library/stdtypes.rst:6209 +#: ../../library/stdtypes.rst:6243 msgid "It is written as ``None``." msgstr "它被寫為 ``None``。" -#: ../../library/stdtypes.rst:6216 +#: ../../library/stdtypes.rst:6250 msgid "The Ellipsis Object" msgstr "Ellipsis 物件" -#: ../../library/stdtypes.rst:6218 +#: ../../library/stdtypes.rst:6252 msgid "" "This object is commonly used to indicate that something is omitted. It " "supports no special operations. There is exactly one ellipsis object, " @@ -9162,63 +9218,63 @@ msgid "" "the :const:`Ellipsis` singleton." msgstr "" -#: ../../library/stdtypes.rst:6223 +#: ../../library/stdtypes.rst:6257 msgid "It is written as ``Ellipsis`` or ``...``." msgstr "它被寫為 ``Ellipsis`` 或 ``...``。" -#: ../../library/stdtypes.rst:6225 +#: ../../library/stdtypes.rst:6259 msgid "" "In typical use, ``...`` as the ``Ellipsis`` object appears in a few " "different places, for instance:" msgstr "" -#: ../../library/stdtypes.rst:6228 +#: ../../library/stdtypes.rst:6262 msgid "" "In type annotations, such as :ref:`callable arguments ` or :ref:`tuple elements `." msgstr "" -#: ../../library/stdtypes.rst:6231 +#: ../../library/stdtypes.rst:6265 msgid "" "As the body of a function instead of a :ref:`pass statement `." msgstr "" -#: ../../library/stdtypes.rst:6233 +#: ../../library/stdtypes.rst:6267 msgid "" "In third-party libraries, such as `Numpy's slicing and striding `_." msgstr "" -#: ../../library/stdtypes.rst:6236 +#: ../../library/stdtypes.rst:6270 msgid "" "Python also uses three dots in ways that are not ``Ellipsis`` objects, for " "instance:" msgstr "" -#: ../../library/stdtypes.rst:6238 +#: ../../library/stdtypes.rst:6272 msgid "" "Doctest's :const:`ELLIPSIS `, as a pattern for missing " "content." msgstr "" -#: ../../library/stdtypes.rst:6240 +#: ../../library/stdtypes.rst:6274 msgid "" "The default Python prompt of the :term:`interactive` shell when partial " "input is incomplete." msgstr "" -#: ../../library/stdtypes.rst:6242 +#: ../../library/stdtypes.rst:6276 msgid "" "Lastly, the Python documentation often uses three dots in conventional " "English usage to mean omitted content, even in code examples that also use " "them as the ``Ellipsis``." msgstr "" -#: ../../library/stdtypes.rst:6250 +#: ../../library/stdtypes.rst:6284 msgid "The NotImplemented Object" msgstr "NotImplemented 物件" -#: ../../library/stdtypes.rst:6252 +#: ../../library/stdtypes.rst:6286 msgid "" "This object is returned from comparisons and binary operations when they are " "asked to operate on types they don't support. See :ref:`comparisons` for " @@ -9226,64 +9282,64 @@ msgid "" "`type(NotImplemented)()` produces the singleton instance." msgstr "" -#: ../../library/stdtypes.rst:6257 +#: ../../library/stdtypes.rst:6291 msgid "It is written as :code:`NotImplemented`." msgstr "它被寫為 :code:`NotImplemented`。" -#: ../../library/stdtypes.rst:6263 +#: ../../library/stdtypes.rst:6297 msgid "Internal Objects" msgstr "內部物件" -#: ../../library/stdtypes.rst:6265 +#: ../../library/stdtypes.rst:6299 msgid "" "See :ref:`types` for this information. It describes :ref:`stack frame " "objects `, :ref:`traceback objects `, and " "slice objects." msgstr "" -#: ../../library/stdtypes.rst:6273 +#: ../../library/stdtypes.rst:6307 msgid "Special Attributes" msgstr "特殊屬性" -#: ../../library/stdtypes.rst:6275 +#: ../../library/stdtypes.rst:6309 msgid "" "The implementation adds a few special read-only attributes to several object " "types, where they are relevant. Some of these are not reported by the :func:" "`dir` built-in function." msgstr "" -#: ../../library/stdtypes.rst:6282 +#: ../../library/stdtypes.rst:6316 msgid "" "The name of the class, function, method, descriptor, or generator instance." msgstr "" -#: ../../library/stdtypes.rst:6288 +#: ../../library/stdtypes.rst:6322 msgid "" "The :term:`qualified name` of the class, function, method, descriptor, or " "generator instance." msgstr "" -#: ../../library/stdtypes.rst:6296 +#: ../../library/stdtypes.rst:6330 msgid "The name of the module in which a class or function was defined." msgstr "" -#: ../../library/stdtypes.rst:6301 +#: ../../library/stdtypes.rst:6335 msgid "" "The documentation string of a class or function, or ``None`` if undefined." msgstr "" -#: ../../library/stdtypes.rst:6306 +#: ../../library/stdtypes.rst:6340 msgid "" "The :ref:`type parameters ` of generic classes, functions, and :" "ref:`type aliases `. For classes and functions that are not " "generic, this will be an empty tuple." msgstr "" -#: ../../library/stdtypes.rst:6316 +#: ../../library/stdtypes.rst:6350 msgid "Integer string conversion length limitation" msgstr "整數字串轉換長度限制" -#: ../../library/stdtypes.rst:6318 +#: ../../library/stdtypes.rst:6352 msgid "" "CPython has a global limit for converting between :class:`int` and :class:" "`str` to mitigate denial of service attacks. This limit *only* applies to " @@ -9295,7 +9351,7 @@ msgstr "" "進位的數值。十六進位、八進位,還有二進位的轉換則沒有長度限制。此限制值可以被" "調整。" -#: ../../library/stdtypes.rst:6323 +#: ../../library/stdtypes.rst:6357 msgid "" "The :class:`int` type in CPython is an arbitrary length number stored in " "binary form (commonly known as a \"bignum\"). There exists no algorithm that " @@ -9305,24 +9361,24 @@ msgid "" "value such as ``int('1' * 500_000)`` can take over a second on a fast CPU." msgstr "" -#: ../../library/stdtypes.rst:6330 +#: ../../library/stdtypes.rst:6364 msgid "" "Limiting conversion size offers a practical way to avoid :cve:`2020-10735`." msgstr "" -#: ../../library/stdtypes.rst:6332 +#: ../../library/stdtypes.rst:6366 msgid "" "The limit is applied to the number of digit characters in the input or " "output string when a non-linear conversion algorithm would be involved. " "Underscores and the sign are not counted towards the limit." msgstr "" -#: ../../library/stdtypes.rst:6336 +#: ../../library/stdtypes.rst:6370 msgid "" "When an operation would exceed the limit, a :exc:`ValueError` is raised:" msgstr "" -#: ../../library/stdtypes.rst:6338 +#: ../../library/stdtypes.rst:6372 msgid "" ">>> import sys\n" ">>> sys.set_int_max_str_digits(4300) # Illustrative, this is the default.\n" @@ -9346,7 +9402,7 @@ msgid "" ">>> assert int(hex(i_squared), base=16) == i*i # Hexadecimal is unlimited." msgstr "" -#: ../../library/stdtypes.rst:6358 +#: ../../library/stdtypes.rst:6392 msgid "" "The default limit is 4300 digits as provided in :data:`sys.int_info." "default_max_str_digits `. The lowest limit that can be " @@ -9354,11 +9410,11 @@ msgid "" "str_digits_check_threshold `." msgstr "" -#: ../../library/stdtypes.rst:6363 +#: ../../library/stdtypes.rst:6397 msgid "Verification:" msgstr "" -#: ../../library/stdtypes.rst:6365 +#: ../../library/stdtypes.rst:6399 msgid "" ">>> import sys\n" ">>> assert sys.int_info.default_max_str_digits == 4300, sys.int_info\n" @@ -9376,11 +9432,11 @@ msgstr "" "... '571186405732').to_bytes(53, 'big')\n" "..." -#: ../../library/stdtypes.rst:6378 +#: ../../library/stdtypes.rst:6412 msgid "Affected APIs" msgstr "受影響的 API" -#: ../../library/stdtypes.rst:6380 +#: ../../library/stdtypes.rst:6414 msgid "" "The limitation only applies to potentially slow conversions between :class:" "`int` and :class:`str` or :class:`bytes`:" @@ -9388,74 +9444,74 @@ msgstr "" "此限制僅適用於 :class:`int` 與 :class:`str` 或 :class:`bytes` 之間可能較慢的" "轉換:" -#: ../../library/stdtypes.rst:6383 +#: ../../library/stdtypes.rst:6417 msgid "``int(string)`` with default base 10." msgstr "``int(string)`` 以預設的 10 為底。" -#: ../../library/stdtypes.rst:6384 +#: ../../library/stdtypes.rst:6418 msgid "``int(string, base)`` for all bases that are not a power of 2." msgstr "``int(string, base)`` 用於所有非 2 冪次方的底。" -#: ../../library/stdtypes.rst:6385 +#: ../../library/stdtypes.rst:6419 msgid "``str(integer)``." msgstr "``str(integer)``。" -#: ../../library/stdtypes.rst:6386 +#: ../../library/stdtypes.rst:6420 msgid "``repr(integer)``." msgstr "``repr(integer)``。" -#: ../../library/stdtypes.rst:6387 +#: ../../library/stdtypes.rst:6421 msgid "" "any other string conversion to base 10, for example ``f\"{integer}\"``, " "``\"{}\".format(integer)``, or ``b\"%d\" % integer``." msgstr "" -#: ../../library/stdtypes.rst:6390 +#: ../../library/stdtypes.rst:6424 msgid "The limitations do not apply to functions with a linear algorithm:" msgstr "" -#: ../../library/stdtypes.rst:6392 +#: ../../library/stdtypes.rst:6426 msgid "``int(string, base)`` with base 2, 4, 8, 16, or 32." msgstr "``int(string, base)`` 以 2、4、8、16 或 32 為底。" -#: ../../library/stdtypes.rst:6393 +#: ../../library/stdtypes.rst:6427 msgid ":func:`int.from_bytes` and :func:`int.to_bytes`." msgstr ":func:`int.from_bytes` 和 :func:`int.to_bytes`。" -#: ../../library/stdtypes.rst:6394 +#: ../../library/stdtypes.rst:6428 msgid ":func:`hex`, :func:`oct`, :func:`bin`." msgstr ":func:`hex`、:func:`oct`、:func:`bin`。" -#: ../../library/stdtypes.rst:6395 +#: ../../library/stdtypes.rst:6429 msgid ":ref:`formatspec` for hex, octal, and binary numbers." msgstr ":ref:`formatspec` 用於十六進位、八進位和二進位數字。" -#: ../../library/stdtypes.rst:6396 +#: ../../library/stdtypes.rst:6430 msgid ":class:`str` to :class:`float`." msgstr ":class:`str` 轉換為 :class:`float`。" -#: ../../library/stdtypes.rst:6397 +#: ../../library/stdtypes.rst:6431 msgid ":class:`str` to :class:`decimal.Decimal`." msgstr ":class:`str` 轉換為 :class:`decimal.Decimal`。" -#: ../../library/stdtypes.rst:6400 +#: ../../library/stdtypes.rst:6434 msgid "Configuring the limit" msgstr "設定限制" -#: ../../library/stdtypes.rst:6402 +#: ../../library/stdtypes.rst:6436 msgid "" "Before Python starts up you can use an environment variable or an " "interpreter command line flag to configure the limit:" msgstr "" -#: ../../library/stdtypes.rst:6405 +#: ../../library/stdtypes.rst:6439 msgid "" ":envvar:`PYTHONINTMAXSTRDIGITS`, e.g. ``PYTHONINTMAXSTRDIGITS=640 python3`` " "to set the limit to 640 or ``PYTHONINTMAXSTRDIGITS=0 python3`` to disable " "the limitation." msgstr "" -#: ../../library/stdtypes.rst:6408 +#: ../../library/stdtypes.rst:6442 msgid "" ":option:`-X int_max_str_digits <-X>`, e.g. ``python3 -X " "int_max_str_digits=640``" @@ -9463,7 +9519,7 @@ msgstr "" ":option:`-X int_max_str_digits <-X>`,例如 ``python3 -X " "int_max_str_digits=640``" -#: ../../library/stdtypes.rst:6410 +#: ../../library/stdtypes.rst:6444 msgid "" ":data:`sys.flags.int_max_str_digits` contains the value of :envvar:" "`PYTHONINTMAXSTRDIGITS` or :option:`-X int_max_str_digits <-X>`. If both the " @@ -9472,38 +9528,38 @@ msgid "" "int_info.default_max_str_digits` was used during initialization." msgstr "" -#: ../../library/stdtypes.rst:6416 +#: ../../library/stdtypes.rst:6450 msgid "" "From code, you can inspect the current limit and set a new one using these :" "mod:`sys` APIs:" msgstr "" -#: ../../library/stdtypes.rst:6419 +#: ../../library/stdtypes.rst:6453 msgid "" ":func:`sys.get_int_max_str_digits` and :func:`sys.set_int_max_str_digits` " "are a getter and setter for the interpreter-wide limit. Subinterpreters have " "their own limit." msgstr "" -#: ../../library/stdtypes.rst:6423 +#: ../../library/stdtypes.rst:6457 msgid "" "Information about the default and minimum can be found in :data:`sys." "int_info`:" msgstr "" -#: ../../library/stdtypes.rst:6425 +#: ../../library/stdtypes.rst:6459 msgid "" ":data:`sys.int_info.default_max_str_digits ` is the compiled-" "in default limit." msgstr "" -#: ../../library/stdtypes.rst:6427 +#: ../../library/stdtypes.rst:6461 msgid "" ":data:`sys.int_info.str_digits_check_threshold ` is the lowest " "accepted value for the limit (other than 0 which disables it)." msgstr "" -#: ../../library/stdtypes.rst:6434 +#: ../../library/stdtypes.rst:6468 msgid "" "Setting a low limit *can* lead to problems. While rare, code exists that " "contains integer constants in decimal in their source that exceed the " @@ -9515,7 +9571,7 @@ msgid "" "constants is to convert them to ``0x`` hexadecimal form as it has no limit." msgstr "" -#: ../../library/stdtypes.rst:6443 +#: ../../library/stdtypes.rst:6477 msgid "" "Test your application thoroughly if you use a low limit. Ensure your tests " "run with the limit set early via the environment or flag so that it applies " @@ -9523,11 +9579,11 @@ msgid "" "to precompile ``.py`` sources to ``.pyc`` files." msgstr "" -#: ../../library/stdtypes.rst:6449 +#: ../../library/stdtypes.rst:6483 msgid "Recommended configuration" msgstr "建議的配置" -#: ../../library/stdtypes.rst:6451 +#: ../../library/stdtypes.rst:6485 msgid "" "The default :data:`sys.int_info.default_max_str_digits` is expected to be " "reasonable for most applications. If your application requires a different " @@ -9535,11 +9591,11 @@ msgid "" "as these APIs were added in security patch releases in versions before 3.12." msgstr "" -#: ../../library/stdtypes.rst:6456 +#: ../../library/stdtypes.rst:6490 msgid "Example::" msgstr "範例: ::" -#: ../../library/stdtypes.rst:6458 +#: ../../library/stdtypes.rst:6492 msgid "" ">>> import sys\n" ">>> if hasattr(sys, \"set_int_max_str_digits\"):\n" @@ -9561,38 +9617,38 @@ msgstr "" "... elif current_limit < lower_bound:\n" "... sys.set_int_max_str_digits(lower_bound)" -#: ../../library/stdtypes.rst:6468 +#: ../../library/stdtypes.rst:6502 msgid "If you need to disable it entirely, set it to ``0``." msgstr "" -#: ../../library/stdtypes.rst:6472 +#: ../../library/stdtypes.rst:6506 msgid "Footnotes" msgstr "註腳" -#: ../../library/stdtypes.rst:6473 +#: ../../library/stdtypes.rst:6507 msgid "" "Additional information on these special methods may be found in the Python " "Reference Manual (:ref:`customization`)." msgstr "" -#: ../../library/stdtypes.rst:6476 +#: ../../library/stdtypes.rst:6510 msgid "" "As a consequence, the list ``[1, 2]`` is considered equal to ``[1.0, 2.0]``, " "and similarly for tuples." msgstr "" -#: ../../library/stdtypes.rst:6479 +#: ../../library/stdtypes.rst:6513 msgid "They must have since the parser can't tell the type of the operands." msgstr "" -#: ../../library/stdtypes.rst:6481 +#: ../../library/stdtypes.rst:6515 msgid "" "Cased characters are those with general category property being one of " "\"Lu\" (Letter, uppercase), \"Ll\" (Letter, lowercase), or \"Lt\" (Letter, " "titlecase)." msgstr "" -#: ../../library/stdtypes.rst:6484 +#: ../../library/stdtypes.rst:6518 msgid "" "To format only a tuple you should therefore provide a singleton tuple whose " "only element is the tuple to be formatted." @@ -9605,13 +9661,13 @@ msgstr "built-in(內建)" #: ../../library/stdtypes.rst:13 ../../library/stdtypes.rst:332 #: ../../library/stdtypes.rst:409 ../../library/stdtypes.rst:1002 #: ../../library/stdtypes.rst:1192 ../../library/stdtypes.rst:1214 -#: ../../library/stdtypes.rst:1229 ../../library/stdtypes.rst:5186 -#: ../../library/stdtypes.rst:6188 +#: ../../library/stdtypes.rst:1229 ../../library/stdtypes.rst:5220 +#: ../../library/stdtypes.rst:6222 msgid "types" msgstr "type(型別)" #: ../../library/stdtypes.rst:34 ../../library/stdtypes.rst:1229 -#: ../../library/stdtypes.rst:5186 +#: ../../library/stdtypes.rst:5220 msgid "statement" msgstr "statement(陳述式)" @@ -9733,11 +9789,11 @@ msgstr "is not" #: ../../library/stdtypes.rst:1214 ../../library/stdtypes.rst:1379 #: ../../library/stdtypes.rst:1463 ../../library/stdtypes.rst:1507 #: ../../library/stdtypes.rst:1628 ../../library/stdtypes.rst:1758 -#: ../../library/stdtypes.rst:3207 ../../library/stdtypes.rst:3226 -#: ../../library/stdtypes.rst:3339 ../../library/stdtypes.rst:4975 -#: ../../library/stdtypes.rst:5186 ../../library/stdtypes.rst:5675 -#: ../../library/stdtypes.rst:5932 ../../library/stdtypes.rst:6107 -#: ../../library/stdtypes.rst:6152 +#: ../../library/stdtypes.rst:3241 ../../library/stdtypes.rst:3260 +#: ../../library/stdtypes.rst:3373 ../../library/stdtypes.rst:5009 +#: ../../library/stdtypes.rst:5220 ../../library/stdtypes.rst:5709 +#: ../../library/stdtypes.rst:5966 ../../library/stdtypes.rst:6141 +#: ../../library/stdtypes.rst:6186 msgid "object" msgstr "object(物件)" @@ -9829,9 +9885,9 @@ msgid "arithmetic" msgstr "arithmetic(算術)" #: ../../library/stdtypes.rst:251 ../../library/stdtypes.rst:1002 -#: ../../library/stdtypes.rst:1192 ../../library/stdtypes.rst:5186 -#: ../../library/stdtypes.rst:6159 ../../library/stdtypes.rst:6173 -#: ../../library/stdtypes.rst:6188 +#: ../../library/stdtypes.rst:1192 ../../library/stdtypes.rst:5220 +#: ../../library/stdtypes.rst:6193 ../../library/stdtypes.rst:6207 +#: ../../library/stdtypes.rst:6222 msgid "built-in function" msgstr "built-in function(內建函式)" @@ -9847,8 +9903,8 @@ msgstr "float" msgid "complex" msgstr "complex(複數)" -#: ../../library/stdtypes.rst:251 ../../library/stdtypes.rst:3083 -#: ../../library/stdtypes.rst:4343 +#: ../../library/stdtypes.rst:251 ../../library/stdtypes.rst:3117 +#: ../../library/stdtypes.rst:4377 msgid "+ (plus)" msgstr "+ (加號)" @@ -9860,13 +9916,13 @@ msgstr "unary operator(一元運算子)" msgid "binary operator" msgstr "binary operator(二元運算子)" -#: ../../library/stdtypes.rst:251 ../../library/stdtypes.rst:3083 -#: ../../library/stdtypes.rst:4343 +#: ../../library/stdtypes.rst:251 ../../library/stdtypes.rst:3117 +#: ../../library/stdtypes.rst:4377 msgid "- (minus)" msgstr "- (減號)" -#: ../../library/stdtypes.rst:251 ../../library/stdtypes.rst:3040 -#: ../../library/stdtypes.rst:4300 +#: ../../library/stdtypes.rst:251 ../../library/stdtypes.rst:3074 +#: ../../library/stdtypes.rst:4334 msgid "* (asterisk)" msgstr "* (星號)" @@ -9878,8 +9934,8 @@ msgstr "/ (斜線)" msgid "//" msgstr "//" -#: ../../library/stdtypes.rst:251 ../../library/stdtypes.rst:3003 -#: ../../library/stdtypes.rst:4268 +#: ../../library/stdtypes.rst:251 ../../library/stdtypes.rst:3037 +#: ../../library/stdtypes.rst:4302 msgid "% (percent)" msgstr "% (百分號)" @@ -9889,7 +9945,7 @@ msgstr "**" #: ../../library/stdtypes.rst:332 ../../library/stdtypes.rst:409 #: ../../library/stdtypes.rst:1002 ../../library/stdtypes.rst:1229 -#: ../../library/stdtypes.rst:5186 +#: ../../library/stdtypes.rst:5220 msgid "operations on" msgstr "operations on(操作於)" @@ -9898,7 +9954,7 @@ msgid "conjugate() (complex number method)" msgstr "conjugate()(複數方法)" #: ../../library/stdtypes.rst:351 ../../library/stdtypes.rst:1826 -#: ../../library/stdtypes.rst:3207 ../../library/stdtypes.rst:6188 +#: ../../library/stdtypes.rst:3241 ../../library/stdtypes.rst:6222 msgid "module" msgstr "模組" @@ -9966,7 +10022,7 @@ msgstr "values" msgid "iterator protocol" msgstr "iterator protocol(疊代器協定)" -#: ../../library/stdtypes.rst:899 ../../library/stdtypes.rst:5588 +#: ../../library/stdtypes.rst:899 ../../library/stdtypes.rst:5622 msgid "protocol" msgstr "protocol(協定)" @@ -9992,7 +10048,7 @@ msgstr "container(容器)" msgid "iteration over" msgstr "iteration over(疊代於)" -#: ../../library/stdtypes.rst:1002 ../../library/stdtypes.rst:5186 +#: ../../library/stdtypes.rst:1002 ../../library/stdtypes.rst:5220 msgid "len" msgstr "len" @@ -10061,14 +10117,14 @@ msgstr "mutable(可變)" msgid "list" msgstr "list(串列)" -#: ../../library/stdtypes.rst:1214 ../../library/stdtypes.rst:3207 -#: ../../library/stdtypes.rst:3339 ../../library/stdtypes.rst:3449 -#: ../../library/stdtypes.rst:4268 +#: ../../library/stdtypes.rst:1214 ../../library/stdtypes.rst:3241 +#: ../../library/stdtypes.rst:3373 ../../library/stdtypes.rst:3483 +#: ../../library/stdtypes.rst:4302 msgid "bytearray" msgstr "bytearray(位元組陣列)" -#: ../../library/stdtypes.rst:1229 ../../library/stdtypes.rst:5186 -#: ../../library/stdtypes.rst:5932 ../../library/stdtypes.rst:6188 +#: ../../library/stdtypes.rst:1229 ../../library/stdtypes.rst:5220 +#: ../../library/stdtypes.rst:5966 ../../library/stdtypes.rst:6222 msgid "type" msgstr "type(型別)" @@ -10076,7 +10132,7 @@ msgstr "type(型別)" msgid "assignment" msgstr "assignment(賦值)" -#: ../../library/stdtypes.rst:1229 ../../library/stdtypes.rst:5186 +#: ../../library/stdtypes.rst:1229 ../../library/stdtypes.rst:5220 msgid "del" msgstr "del" @@ -10085,8 +10141,8 @@ msgid "range" msgstr "range" #: ../../library/stdtypes.rst:1628 ../../library/stdtypes.rst:1771 -#: ../../library/stdtypes.rst:1818 ../../library/stdtypes.rst:2831 -#: ../../library/stdtypes.rst:3003 +#: ../../library/stdtypes.rst:1818 ../../library/stdtypes.rst:2865 +#: ../../library/stdtypes.rst:3037 msgid "string" msgstr "string(字串)" @@ -10107,17 +10163,17 @@ msgstr "(亦請見 string)" msgid "io.StringIO" msgstr "io.StringIO" -#: ../../library/stdtypes.rst:1791 ../../library/stdtypes.rst:3199 +#: ../../library/stdtypes.rst:1791 ../../library/stdtypes.rst:3233 msgid "buffer protocol" msgstr "buffer protocol(緩衝區協定)" -#: ../../library/stdtypes.rst:1791 ../../library/stdtypes.rst:3207 -#: ../../library/stdtypes.rst:3226 ../../library/stdtypes.rst:3449 -#: ../../library/stdtypes.rst:4268 +#: ../../library/stdtypes.rst:1791 ../../library/stdtypes.rst:3241 +#: ../../library/stdtypes.rst:3260 ../../library/stdtypes.rst:3483 +#: ../../library/stdtypes.rst:4302 msgid "bytes" msgstr "bytes(位元組)" -#: ../../library/stdtypes.rst:1818 ../../library/stdtypes.rst:3449 +#: ../../library/stdtypes.rst:1818 ../../library/stdtypes.rst:3483 msgid "methods" msgstr "methods(方法)" @@ -10125,239 +10181,239 @@ msgstr "methods(方法)" msgid "re" msgstr "re" -#: ../../library/stdtypes.rst:2621 ../../library/stdtypes.rst:4122 +#: ../../library/stdtypes.rst:2651 ../../library/stdtypes.rst:4156 msgid "universal newlines" msgstr "universal newlines" -#: ../../library/stdtypes.rst:2621 +#: ../../library/stdtypes.rst:2651 msgid "str.splitlines method" msgstr "str.splitlines 方法" -#: ../../library/stdtypes.rst:2831 +#: ../../library/stdtypes.rst:2865 msgid "! formatted string literal" msgstr "! formatted string literals(! 格式化字串常數)" -#: ../../library/stdtypes.rst:2831 +#: ../../library/stdtypes.rst:2865 msgid "formatted string literals" msgstr "formatted string literals(格式化字串常數)" -#: ../../library/stdtypes.rst:2831 +#: ../../library/stdtypes.rst:2865 msgid "! f-string" msgstr "! f-string(! f 字串)" -#: ../../library/stdtypes.rst:2831 +#: ../../library/stdtypes.rst:2865 msgid "f-strings" msgstr "f-string(f 字串)" -#: ../../library/stdtypes.rst:2831 +#: ../../library/stdtypes.rst:2865 msgid "fstring" msgstr "fstring(f 字串)" -#: ../../library/stdtypes.rst:2831 +#: ../../library/stdtypes.rst:2865 msgid "interpolated string literal" msgstr "interpolated string literal(插值字串常數)" -#: ../../library/stdtypes.rst:2831 +#: ../../library/stdtypes.rst:2865 msgid "formatted literal" msgstr "formatted literal(格式化常數)" -#: ../../library/stdtypes.rst:2831 +#: ../../library/stdtypes.rst:2865 msgid "interpolated literal" msgstr "interpolated literal(插值常數)" -#: ../../library/stdtypes.rst:2831 +#: ../../library/stdtypes.rst:2865 msgid "{} (curly brackets)" msgstr "{} (花括號)" -#: ../../library/stdtypes.rst:2831 +#: ../../library/stdtypes.rst:2865 msgid "in formatted string literal" msgstr "於格式化字串常數中" -#: ../../library/stdtypes.rst:2831 +#: ../../library/stdtypes.rst:2865 msgid "! (exclamation mark)" msgstr "! (驚嘆號)" -#: ../../library/stdtypes.rst:2831 +#: ../../library/stdtypes.rst:2865 msgid ": (colon)" msgstr ": (冒號)" -#: ../../library/stdtypes.rst:2831 +#: ../../library/stdtypes.rst:2865 msgid "= (equals)" msgstr "= (等號)" -#: ../../library/stdtypes.rst:2831 +#: ../../library/stdtypes.rst:2865 msgid "for help in debugging using string literals" msgstr "" -#: ../../library/stdtypes.rst:3003 +#: ../../library/stdtypes.rst:3037 msgid "formatting, string (%)" msgstr "formatting(格式化)、字串 (%)" -#: ../../library/stdtypes.rst:3003 +#: ../../library/stdtypes.rst:3037 msgid "interpolation, string (%)" msgstr "interpolation(插值)、字串 (%)" -#: ../../library/stdtypes.rst:3003 +#: ../../library/stdtypes.rst:3037 msgid "formatting, printf" msgstr "formatting(格式化)、printf" -#: ../../library/stdtypes.rst:3003 +#: ../../library/stdtypes.rst:3037 msgid "interpolation, printf" msgstr "interpolation(插值)、printf" -#: ../../library/stdtypes.rst:3003 ../../library/stdtypes.rst:4268 +#: ../../library/stdtypes.rst:3037 ../../library/stdtypes.rst:4302 msgid "printf-style formatting" msgstr "printf 風格格式化" -#: ../../library/stdtypes.rst:3003 ../../library/stdtypes.rst:4268 +#: ../../library/stdtypes.rst:3037 ../../library/stdtypes.rst:4302 msgid "sprintf-style formatting" msgstr "sprintf 風格格式化" -#: ../../library/stdtypes.rst:3040 ../../library/stdtypes.rst:4300 +#: ../../library/stdtypes.rst:3074 ../../library/stdtypes.rst:4334 msgid "() (parentheses)" msgstr "() (圓括號)" -#: ../../library/stdtypes.rst:3040 ../../library/stdtypes.rst:3083 -#: ../../library/stdtypes.rst:4300 ../../library/stdtypes.rst:4343 +#: ../../library/stdtypes.rst:3074 ../../library/stdtypes.rst:3117 +#: ../../library/stdtypes.rst:4334 ../../library/stdtypes.rst:4377 msgid "in printf-style formatting" msgstr "於 printf 風格格式化" -#: ../../library/stdtypes.rst:3040 ../../library/stdtypes.rst:4300 +#: ../../library/stdtypes.rst:3074 ../../library/stdtypes.rst:4334 msgid ". (dot)" msgstr ". (點)" -#: ../../library/stdtypes.rst:3083 ../../library/stdtypes.rst:4343 +#: ../../library/stdtypes.rst:3117 ../../library/stdtypes.rst:4377 msgid "# (hash)" msgstr "# (井字號)" -#: ../../library/stdtypes.rst:3083 ../../library/stdtypes.rst:4343 +#: ../../library/stdtypes.rst:3117 ../../library/stdtypes.rst:4377 msgid "space" msgstr "space(空白)" -#: ../../library/stdtypes.rst:3199 +#: ../../library/stdtypes.rst:3233 msgid "binary sequence types" msgstr "binary sequence types(二進位序列型別)" -#: ../../library/stdtypes.rst:3207 +#: ../../library/stdtypes.rst:3241 msgid "memoryview" msgstr "memoryview(記憶體視圖)" -#: ../../library/stdtypes.rst:3207 +#: ../../library/stdtypes.rst:3241 msgid "array" msgstr "array(陣列)" -#: ../../library/stdtypes.rst:4122 +#: ../../library/stdtypes.rst:4156 msgid "bytes.splitlines method" msgstr "bytes.splitlines 方法" -#: ../../library/stdtypes.rst:4122 +#: ../../library/stdtypes.rst:4156 msgid "bytearray.splitlines method" msgstr "bytearray.splitlines 方法" -#: ../../library/stdtypes.rst:4268 +#: ../../library/stdtypes.rst:4302 msgid "formatting" msgstr "formatting(格式化)" -#: ../../library/stdtypes.rst:4268 +#: ../../library/stdtypes.rst:4302 msgid "bytes (%)" msgstr "bytes (%)" -#: ../../library/stdtypes.rst:4268 +#: ../../library/stdtypes.rst:4302 msgid "bytearray (%)" msgstr "bytearray (%)" -#: ../../library/stdtypes.rst:4268 +#: ../../library/stdtypes.rst:4302 msgid "interpolation" msgstr "interpolation(插值)" -#: ../../library/stdtypes.rst:4975 +#: ../../library/stdtypes.rst:5009 msgid "set" msgstr "set(集合)" -#: ../../library/stdtypes.rst:5186 +#: ../../library/stdtypes.rst:5220 msgid "mapping" msgstr "mapping(對映)" -#: ../../library/stdtypes.rst:5186 +#: ../../library/stdtypes.rst:5220 msgid "dictionary" msgstr "dictionary(字典)" -#: ../../library/stdtypes.rst:5293 +#: ../../library/stdtypes.rst:5327 msgid "__missing__()" msgstr "__missing__()" -#: ../../library/stdtypes.rst:5588 +#: ../../library/stdtypes.rst:5622 msgid "context manager" msgstr "context manager(情境管理器)" -#: ../../library/stdtypes.rst:5588 +#: ../../library/stdtypes.rst:5622 msgid "context management protocol" msgstr "context management protocol(情境管理協定)" -#: ../../library/stdtypes.rst:5588 +#: ../../library/stdtypes.rst:5622 msgid "context management" msgstr "context management(情境管理)" -#: ../../library/stdtypes.rst:5663 +#: ../../library/stdtypes.rst:5697 msgid "annotation" msgstr "annotation(註記)" -#: ../../library/stdtypes.rst:5663 +#: ../../library/stdtypes.rst:5697 msgid "type annotation; type hint" msgstr "type annotation(型別註記);type hint(型別提示)" -#: ../../library/stdtypes.rst:5675 +#: ../../library/stdtypes.rst:5709 msgid "GenericAlias" msgstr "GenericAlias(泛型別名)" -#: ../../library/stdtypes.rst:5675 +#: ../../library/stdtypes.rst:5709 msgid "Generic" msgstr "Generic(泛型)" -#: ../../library/stdtypes.rst:5675 +#: ../../library/stdtypes.rst:5709 msgid "Alias" msgstr "Alias(別名)" -#: ../../library/stdtypes.rst:5932 +#: ../../library/stdtypes.rst:5966 msgid "Union" msgstr "Union(聯合)" -#: ../../library/stdtypes.rst:5932 +#: ../../library/stdtypes.rst:5966 msgid "union" msgstr "union(聯集)" -#: ../../library/stdtypes.rst:6107 +#: ../../library/stdtypes.rst:6141 msgid "method" msgstr "method(方法)" -#: ../../library/stdtypes.rst:6152 +#: ../../library/stdtypes.rst:6186 msgid "code" msgstr "code(程式碼)" -#: ../../library/stdtypes.rst:6152 +#: ../../library/stdtypes.rst:6186 msgid "code object" msgstr "code object(程式碼物件)" -#: ../../library/stdtypes.rst:6159 +#: ../../library/stdtypes.rst:6193 msgid "compile" msgstr "compile(編譯)" -#: ../../library/stdtypes.rst:6159 +#: ../../library/stdtypes.rst:6193 msgid "__code__ (function object attribute)" msgstr "__code__(函式物件屬性)" -#: ../../library/stdtypes.rst:6173 +#: ../../library/stdtypes.rst:6207 msgid "exec" msgstr "exec" -#: ../../library/stdtypes.rst:6173 +#: ../../library/stdtypes.rst:6207 msgid "eval" msgstr "eval" -#: ../../library/stdtypes.rst:6212 +#: ../../library/stdtypes.rst:6246 msgid "..." msgstr "..." -#: ../../library/stdtypes.rst:6212 +#: ../../library/stdtypes.rst:6246 msgid "ellipsis literal" msgstr "ellipsis literal(刪節號字面值)" diff --git a/library/typing.po b/library/typing.po index eb4aec48d98..08b1e84550f 100644 --- a/library/typing.po +++ b/library/typing.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-18 00:20+0000\n" +"POT-Creation-Date: 2026-02-26 18:22+0000\n" "PO-Revision-Date: 2024-07-11 11:12+0800\n" "Last-Translator: Li-Hung Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -390,7 +390,7 @@ msgstr "" "class:`str`。" #: ../../library/typing.rst:215 ../../library/typing.rst:3296 -#: ../../library/typing.rst:3482 +#: ../../library/typing.rst:3494 msgid "For example:" msgstr "舉例來說:" @@ -513,7 +513,7 @@ msgstr "" "``Callable[Concatenate[Arg1Type, Arg2Type, ..., ParamSpecVariable], " "ReturnType]`` 的形式。" -#: ../../library/typing.rst:287 ../../library/typing.rst:4013 +#: ../../library/typing.rst:287 ../../library/typing.rst:4025 msgid "" "``Callable`` now supports :class:`ParamSpec` and :data:`Concatenate`. See :" "pep:`612` for more details." @@ -1476,8 +1476,8 @@ msgid "" "``Iterable[int]`` by static type checkers. This is known as *structural " "subtyping* (or static duck-typing)::" msgstr "" -":pep:`544` 讓使用者可以撰寫上方的程式碼,且不用在類別定義中寫基底類別來解決這個問" -"題,讓 ``Bucket`` 被靜態型別檢查器隱性認為是 ``Sized`` 以及 " +":pep:`544` 讓使用者可以撰寫上方的程式碼,且不用在類別定義中寫基底類別來解決這" +"個問題,讓 ``Bucket`` 被靜態型別檢查器隱性認為是 ``Sized`` 以及 " "``Iterable[int]`` 兩者的子型別。這就是眾所周知的\\ *結構子型別*\\ (或是靜態" "鴨子型別): ::" @@ -1581,7 +1581,7 @@ msgstr "" #: ../../library/typing.rst:1048 ../../library/typing.rst:1230 #: ../../library/typing.rst:1317 ../../library/typing.rst:1359 #: ../../library/typing.rst:1568 ../../library/typing.rst:1629 -#: ../../library/typing.rst:3233 ../../library/typing.rst:3467 +#: ../../library/typing.rst:3233 ../../library/typing.rst:3479 msgid "For example::" msgstr "舉例來說: ::" @@ -3832,7 +3832,7 @@ msgid "Typed version of :func:`collections.namedtuple`." msgstr "" #: ../../library/typing.rst:2362 ../../library/typing.rst:2462 -#: ../../library/typing.rst:3571 +#: ../../library/typing.rst:3583 msgid "Usage::" msgstr "用法: ::" @@ -5358,8 +5358,8 @@ msgstr "" #: ../../library/typing.rst:3350 msgid "" -"Return a dictionary containing type hints for a function, method, module or " -"class object." +"Return a dictionary containing type hints for a function, method, module, " +"class object, or other callable object." msgstr "" #: ../../library/typing.rst:3353 @@ -5411,7 +5411,7 @@ msgid "" "returns annotations more directly." msgstr "" -#: ../../library/typing.rst:3381 ../../library/typing.rst:3532 +#: ../../library/typing.rst:3381 ../../library/typing.rst:3544 msgid "" "This function may execute arbitrary code contained in annotations. See :ref:" "`annotationlib-security` for more information." @@ -5426,7 +5426,14 @@ msgid "" "imported under :data:`if TYPE_CHECKING `." msgstr "" -#: ../../library/typing.rst:3392 +#: ../../library/typing.rst:3394 +msgid "" +"Calling :func:`get_type_hints` on an instance is not supported. To retrieve " +"annotations for an instance, call :func:`get_type_hints` on the instance's " +"class instead (for example, ``get_type_hints(type(obj))``)." +msgstr "" + +#: ../../library/typing.rst:3399 msgid "" "Added ``include_extras`` parameter as part of :pep:`593`. See the " "documentation on :data:`Annotated` for more information." @@ -5434,20 +5441,27 @@ msgstr "" "新增 ``include_extras`` 參數(如 :pep:`593` 中所述)。更多資訊請見 :data:" "`Annotated` 的文件。" -#: ../../library/typing.rst:3396 +#: ../../library/typing.rst:3403 msgid "" "Previously, ``Optional[t]`` was added for function and method annotations if " "a default value equal to ``None`` was set. Now the annotation is returned " "unchanged." msgstr "" -#: ../../library/typing.rst:3403 +#: ../../library/typing.rst:3408 +msgid "" +"Calling :func:`get_type_hints` on instances is no longer supported. Some " +"instances were accepted in earlier versions as an undocumented " +"implementation detail." +msgstr "" + +#: ../../library/typing.rst:3415 msgid "" "Get the unsubscripted version of a type: for a typing object of the form " "``X[Y, Z, ...]`` return ``X``." msgstr "" -#: ../../library/typing.rst:3406 +#: ../../library/typing.rst:3418 msgid "" "If ``X`` is a typing-module alias for a builtin or :mod:`collections` class, " "it will be normalized to the original class. If ``X`` is an instance of :" @@ -5455,11 +5469,11 @@ msgid "" "class:`ParamSpec`. Return ``None`` for unsupported objects." msgstr "" -#: ../../library/typing.rst:3412 ../../library/typing.rst:3436 +#: ../../library/typing.rst:3424 ../../library/typing.rst:3448 msgid "Examples:" msgstr "舉例:" -#: ../../library/typing.rst:3414 +#: ../../library/typing.rst:3426 msgid "" "assert get_origin(str) is None\n" "assert get_origin(Dict[str, int]) is dict\n" @@ -5477,13 +5491,13 @@ msgstr "" "assert get_origin(P.args) is P\n" "assert get_origin(P.kwargs) is P" -#: ../../library/typing.rst:3428 +#: ../../library/typing.rst:3440 msgid "" "Get type arguments with all substitutions performed: for a typing object of " "the form ``X[Y, Z, ...]`` return ``(Y, Z, ...)``." msgstr "" -#: ../../library/typing.rst:3431 +#: ../../library/typing.rst:3443 msgid "" "If ``X`` is a union or :class:`Literal` contained in another generic type, " "the order of ``(Y, Z, ...)`` may be different from the order of the original " @@ -5491,7 +5505,7 @@ msgid "" "objects." msgstr "" -#: ../../library/typing.rst:3438 +#: ../../library/typing.rst:3450 msgid "" "assert get_args(int) == ()\n" "assert get_args(Dict[int, str]) == (int, str)\n" @@ -5501,11 +5515,11 @@ msgstr "" "assert get_args(Dict[int, str]) == (int, str)\n" "assert get_args(Union[int, str]) == (int, str)" -#: ../../library/typing.rst:3448 +#: ../../library/typing.rst:3460 msgid "Return the set of members defined in a :class:`Protocol`." msgstr "" -#: ../../library/typing.rst:3450 +#: ../../library/typing.rst:3462 msgid "" ">>> from typing import Protocol, get_protocol_members\n" ">>> class P(Protocol):\n" @@ -5521,15 +5535,15 @@ msgstr "" ">>> get_protocol_members(P) == frozenset({'a', 'b'})\n" "True" -#: ../../library/typing.rst:3459 +#: ../../library/typing.rst:3471 msgid "Raise :exc:`TypeError` for arguments that are not Protocols." msgstr "" -#: ../../library/typing.rst:3465 +#: ../../library/typing.rst:3477 msgid "Determine if a type is a :class:`Protocol`." msgstr "確定一個型別是否 :class:`Protocol`。" -#: ../../library/typing.rst:3469 +#: ../../library/typing.rst:3481 msgid "" "class P(Protocol):\n" " def a(self) -> str: ...\n" @@ -5545,11 +5559,11 @@ msgstr "" "is_protocol(P) # => True\n" "is_protocol(int) # => False" -#: ../../library/typing.rst:3480 +#: ../../library/typing.rst:3492 msgid "Check if a type is a :class:`TypedDict`." msgstr "" -#: ../../library/typing.rst:3484 +#: ../../library/typing.rst:3496 msgid "" "class Film(TypedDict):\n" " title: str\n" @@ -5563,57 +5577,57 @@ msgid "" "assert not is_typeddict(TypedDict)" msgstr "" -#: ../../library/typing.rst:3501 +#: ../../library/typing.rst:3513 msgid "" "Class used for internal typing representation of string forward references." msgstr "" -#: ../../library/typing.rst:3503 +#: ../../library/typing.rst:3515 msgid "" "For example, ``List[\"SomeClass\"]`` is implicitly transformed into " "``List[ForwardRef(\"SomeClass\")]``. :class:`!ForwardRef` should not be " "instantiated by a user, but may be used by introspection tools." msgstr "" -#: ../../library/typing.rst:3508 +#: ../../library/typing.rst:3520 msgid "" ":pep:`585` generic types such as ``list[\"SomeClass\"]`` will not be " "implicitly transformed into ``list[ForwardRef(\"SomeClass\")]`` and thus " "will not automatically resolve to ``list[SomeClass]``." msgstr "" -#: ../../library/typing.rst:3514 +#: ../../library/typing.rst:3526 msgid "" "This is now an alias for :class:`annotationlib.ForwardRef`. Several " "undocumented behaviors of this class have been changed; for example, after a " "``ForwardRef`` has been evaluated, the evaluated value is no longer cached." msgstr "" -#: ../../library/typing.rst:3521 +#: ../../library/typing.rst:3533 msgid "Evaluate an :class:`annotationlib.ForwardRef` as a :term:`type hint`." msgstr "" -#: ../../library/typing.rst:3523 +#: ../../library/typing.rst:3535 msgid "" "This is similar to calling :meth:`annotationlib.ForwardRef.evaluate`, but " "unlike that method, :func:`!evaluate_forward_ref` also recursively evaluates " "forward references nested within the type hint." msgstr "" -#: ../../library/typing.rst:3527 +#: ../../library/typing.rst:3539 msgid "" "See the documentation for :meth:`annotationlib.ForwardRef.evaluate` for the " "meaning of the *owner*, *globals*, *locals*, *type_params*, and *format* " "parameters." msgstr "" -#: ../../library/typing.rst:3539 +#: ../../library/typing.rst:3551 msgid "" "A sentinel object used to indicate that a type parameter has no default " "value. For example:" msgstr "" -#: ../../library/typing.rst:3542 +#: ../../library/typing.rst:3554 msgid "" ">>> T = TypeVar(\"T\")\n" ">>> T.__default__ is typing.NoDefault\n" @@ -5629,17 +5643,17 @@ msgstr "" ">>> S.__default__ is None\n" "True" -#: ../../library/typing.rst:3554 +#: ../../library/typing.rst:3566 msgid "Constant" msgstr "常數" -#: ../../library/typing.rst:3558 +#: ../../library/typing.rst:3570 msgid "" "A special constant that is assumed to be ``True`` by 3rd party static type " "checkers. It's ``False`` at runtime." msgstr "" -#: ../../library/typing.rst:3561 +#: ../../library/typing.rst:3573 msgid "" "A module which is expensive to import, and which only contain types used for " "typing annotations, can be safely imported inside an ``if TYPE_CHECKING:`` " @@ -5651,7 +5665,7 @@ msgid "" "will be checked properly during such analysis." msgstr "" -#: ../../library/typing.rst:3573 +#: ../../library/typing.rst:3585 msgid "" "if TYPE_CHECKING:\n" " import expensive_mod\n" @@ -5665,7 +5679,7 @@ msgstr "" "def fun(arg: expensive_mod.SomeType) -> None:\n" " local_var: expensive_mod.AnotherType = other_fun()" -#: ../../library/typing.rst:3579 +#: ../../library/typing.rst:3591 msgid "" "If you occasionally need to examine type annotations at runtime which may " "contain undefined symbols, use :meth:`annotationlib.get_annotations` with a " @@ -5674,11 +5688,11 @@ msgid "" "raising :exc:`NameError`." msgstr "" -#: ../../library/typing.rst:3592 +#: ../../library/typing.rst:3604 msgid "Deprecated aliases" msgstr "棄用的別名" -#: ../../library/typing.rst:3594 +#: ../../library/typing.rst:3606 msgid "" "This module defines several deprecated aliases to pre-existing standard " "library classes. These were originally included in the :mod:`!typing` module " @@ -5687,7 +5701,7 @@ msgid "" "pre-existing classes were enhanced to support ``[]`` (see :pep:`585`)." msgstr "" -#: ../../library/typing.rst:3601 +#: ../../library/typing.rst:3613 msgid "" "The redundant types are deprecated as of Python 3.9. However, while the " "aliases may be removed at some point, removal of these aliases is not " @@ -5695,7 +5709,7 @@ msgid "" "the interpreter for these aliases." msgstr "" -#: ../../library/typing.rst:3606 +#: ../../library/typing.rst:3618 msgid "" "If at some point it is decided to remove these deprecated aliases, a " "deprecation warning will be issued by the interpreter for at least two " @@ -5703,38 +5717,38 @@ msgid "" "`!typing` module without deprecation warnings until at least Python 3.14." msgstr "" -#: ../../library/typing.rst:3611 +#: ../../library/typing.rst:3623 msgid "" "Type checkers are encouraged to flag uses of the deprecated types if the " "program they are checking targets a minimum Python version of 3.9 or newer." msgstr "" -#: ../../library/typing.rst:3617 +#: ../../library/typing.rst:3629 msgid "Aliases to built-in types" msgstr "內建型別的別名" -#: ../../library/typing.rst:3621 +#: ../../library/typing.rst:3633 msgid "Deprecated alias to :class:`dict`." msgstr "棄用 :class:`dict` 的別名。" -#: ../../library/typing.rst:3623 +#: ../../library/typing.rst:3635 msgid "" "Note that to annotate arguments, it is preferred to use an abstract " "collection type such as :class:`~collections.abc.Mapping` rather than to " "use :class:`dict` or :class:`!typing.Dict`." msgstr "" -#: ../../library/typing.rst:3627 +#: ../../library/typing.rst:3639 msgid "" ":class:`builtins.dict ` now supports subscripting (``[]``). See :pep:" "`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3633 +#: ../../library/typing.rst:3645 msgid "Deprecated alias to :class:`list`." msgstr "棄用 :class:`list` 的別名。" -#: ../../library/typing.rst:3635 +#: ../../library/typing.rst:3647 msgid "" "Note that to annotate arguments, it is preferred to use an abstract " "collection type such as :class:`~collections.abc.Sequence` or :class:" @@ -5742,136 +5756,136 @@ msgid "" "typing.List`." msgstr "" -#: ../../library/typing.rst:3640 +#: ../../library/typing.rst:3652 msgid "" ":class:`builtins.list ` now supports subscripting (``[]``). See :pep:" "`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3646 +#: ../../library/typing.rst:3658 msgid "Deprecated alias to :class:`builtins.set `." msgstr "棄用 :class:`builtins.set ` 的別名。" -#: ../../library/typing.rst:3648 +#: ../../library/typing.rst:3660 msgid "" "Note that to annotate arguments, it is preferred to use an abstract " "collection type such as :class:`collections.abc.Set` rather than to use :" "class:`set` or :class:`typing.Set`." msgstr "" -#: ../../library/typing.rst:3652 +#: ../../library/typing.rst:3664 msgid "" ":class:`builtins.set ` now supports subscripting (``[]``). See :pep:" "`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3658 +#: ../../library/typing.rst:3670 msgid "Deprecated alias to :class:`builtins.frozenset `." msgstr "棄用 :class:`builtins.frozenset ` 的別名。" -#: ../../library/typing.rst:3660 +#: ../../library/typing.rst:3672 msgid "" ":class:`builtins.frozenset ` now supports subscripting (``[]``). " "See :pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3667 +#: ../../library/typing.rst:3679 msgid "Deprecated alias for :class:`tuple`." msgstr "棄用 :class:`tuple` 的別名。" -#: ../../library/typing.rst:3669 +#: ../../library/typing.rst:3681 msgid "" ":class:`tuple` and ``Tuple`` are special-cased in the type system; see :ref:" "`annotating-tuples` for more details." msgstr "" -#: ../../library/typing.rst:3672 +#: ../../library/typing.rst:3684 msgid "" ":class:`builtins.tuple ` now supports subscripting (``[]``). See :pep:" "`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3678 +#: ../../library/typing.rst:3690 msgid "Deprecated alias to :class:`type`." msgstr "棄用 :class:`type` 的別名。" -#: ../../library/typing.rst:3680 +#: ../../library/typing.rst:3692 msgid "" "See :ref:`type-of-class-objects` for details on using :class:`type` or " "``typing.Type`` in type annotations." msgstr "" -#: ../../library/typing.rst:3685 +#: ../../library/typing.rst:3697 msgid "" ":class:`builtins.type ` now supports subscripting (``[]``). See :pep:" "`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3692 +#: ../../library/typing.rst:3704 msgid "Aliases to types in :mod:`collections`" msgstr ":mod:`collections` 中型別的別名" -#: ../../library/typing.rst:3696 +#: ../../library/typing.rst:3708 msgid "Deprecated alias to :class:`collections.defaultdict`." msgstr "棄用 :class:`collections.defaultdict` 的別名。" -#: ../../library/typing.rst:3700 +#: ../../library/typing.rst:3712 msgid "" ":class:`collections.defaultdict` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3706 +#: ../../library/typing.rst:3718 msgid "Deprecated alias to :class:`collections.OrderedDict`." msgstr "棄用 :class:`collections.OrderedDict` 的別名。" -#: ../../library/typing.rst:3710 +#: ../../library/typing.rst:3722 msgid "" ":class:`collections.OrderedDict` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3716 +#: ../../library/typing.rst:3728 msgid "Deprecated alias to :class:`collections.ChainMap`." msgstr "棄用 :class:`collections.ChainMap` 的別名。" -#: ../../library/typing.rst:3720 +#: ../../library/typing.rst:3732 msgid "" ":class:`collections.ChainMap` now supports subscripting (``[]``). See :pep:" "`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3726 +#: ../../library/typing.rst:3738 msgid "Deprecated alias to :class:`collections.Counter`." msgstr "棄用 :class:`collections.Counter` 的別名。" -#: ../../library/typing.rst:3730 +#: ../../library/typing.rst:3742 msgid "" ":class:`collections.Counter` now supports subscripting (``[]``). See :pep:" "`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3736 +#: ../../library/typing.rst:3748 msgid "Deprecated alias to :class:`collections.deque`." msgstr "棄用 :class:`collections.deque` 的別名。" -#: ../../library/typing.rst:3740 +#: ../../library/typing.rst:3752 msgid "" ":class:`collections.deque` now supports subscripting (``[]``). See :pep:" "`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3747 +#: ../../library/typing.rst:3759 msgid "Aliases to other concrete types" msgstr "" -#: ../../library/typing.rst:3752 +#: ../../library/typing.rst:3764 msgid "" "Deprecated aliases corresponding to the return types from :func:`re.compile` " "and :func:`re.match`." msgstr "" -#: ../../library/typing.rst:3755 +#: ../../library/typing.rst:3767 msgid "" "These types (and the corresponding functions) are generic over :data:" "`AnyStr`. ``Pattern`` can be specialised as ``Pattern[str]`` or " @@ -5879,29 +5893,29 @@ msgid "" "``Match[bytes]``." msgstr "" -#: ../../library/typing.rst:3760 +#: ../../library/typing.rst:3772 msgid "" "Classes ``Pattern`` and ``Match`` from :mod:`re` now support ``[]``. See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3766 +#: ../../library/typing.rst:3778 msgid "Deprecated alias for :class:`str`." msgstr "棄用 :class:`str` 的別名。" -#: ../../library/typing.rst:3768 +#: ../../library/typing.rst:3780 msgid "" "``Text`` is provided to supply a forward compatible path for Python 2 code: " "in Python 2, ``Text`` is an alias for ``unicode``." msgstr "" -#: ../../library/typing.rst:3772 +#: ../../library/typing.rst:3784 msgid "" "Use ``Text`` to indicate that a value must contain a unicode string in a " "manner that is compatible with both Python 2 and Python 3::" msgstr "" -#: ../../library/typing.rst:3775 +#: ../../library/typing.rst:3787 msgid "" "def add_unicode_checkmark(text: Text) -> Text:\n" " return text + u' \\u2713'" @@ -5909,32 +5923,32 @@ msgstr "" "def add_unicode_checkmark(text: Text) -> Text:\n" " return text + u' \\u2713'" -#: ../../library/typing.rst:3780 +#: ../../library/typing.rst:3792 msgid "" "Python 2 is no longer supported, and most type checkers also no longer " "support type checking Python 2 code. Removal of the alias is not currently " "planned, but users are encouraged to use :class:`str` instead of ``Text``." msgstr "" -#: ../../library/typing.rst:3790 +#: ../../library/typing.rst:3802 msgid "Aliases to container ABCs in :mod:`collections.abc`" msgstr ":mod:`collections.abc` 中容器 ABC 的別名" -#: ../../library/typing.rst:3794 +#: ../../library/typing.rst:3806 msgid "Deprecated alias to :class:`collections.abc.Set`." msgstr "棄用 :class:`collections.abc.Set` 的別名。" -#: ../../library/typing.rst:3796 +#: ../../library/typing.rst:3808 msgid "" ":class:`collections.abc.Set` now supports subscripting (``[]``). See :pep:" "`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3802 +#: ../../library/typing.rst:3814 msgid "Deprecated alias to :class:`collections.abc.ByteString`." msgstr "棄用 :class:`collections.abc.ByteString` 的別名。" -#: ../../library/typing.rst:3804 +#: ../../library/typing.rst:3816 msgid "" "Use ``isinstance(obj, collections.abc.Buffer)`` to test if ``obj`` " "implements the :ref:`buffer protocol ` at runtime. For use in " @@ -5947,7 +5961,7 @@ msgstr "" "用 :class:`~collections.abc.Buffer` 或明確指定你的程式碼所支援型別的聯集(例" "如 ``bytes | bytearray | memoryview``)。" -#: ../../library/typing.rst:3810 +#: ../../library/typing.rst:3822 msgid "" ":class:`!ByteString` was originally intended to be an abstract class that " "would serve as a supertype of both :class:`bytes` and :class:`bytearray`. " @@ -5963,286 +5977,286 @@ msgstr "" "其他常見的緩衝區型別如 :class:`memoryview` 也從未被理解為 :class:`!" "ByteString` 的子型別(無論是在 runtime 還是由靜態型別檢查器)。" -#: ../../library/typing.rst:3818 +#: ../../library/typing.rst:3830 msgid "See :pep:`PEP 688 <688#current-options>` for more details." msgstr "更多細節請見 :pep:`PEP 688 <688#current-options>`。" -#: ../../library/typing.rst:3824 +#: ../../library/typing.rst:3836 msgid "Deprecated alias to :class:`collections.abc.Collection`." msgstr "棄用 :class:`collections.abc.Collection` 的別名。" -#: ../../library/typing.rst:3828 +#: ../../library/typing.rst:3840 msgid "" ":class:`collections.abc.Collection` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3834 +#: ../../library/typing.rst:3846 msgid "Deprecated alias to :class:`collections.abc.Container`." msgstr "棄用 :class:`collections.abc.Container` 的別名。" -#: ../../library/typing.rst:3836 +#: ../../library/typing.rst:3848 msgid "" ":class:`collections.abc.Container` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3842 +#: ../../library/typing.rst:3854 msgid "Deprecated alias to :class:`collections.abc.ItemsView`." msgstr "棄用 :class:`collections.abc.ItemsView` 的別名。" -#: ../../library/typing.rst:3844 +#: ../../library/typing.rst:3856 msgid "" ":class:`collections.abc.ItemsView` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3850 +#: ../../library/typing.rst:3862 msgid "Deprecated alias to :class:`collections.abc.KeysView`." msgstr "棄用 :class:`collections.abc.KeysView` 的別名。" -#: ../../library/typing.rst:3852 +#: ../../library/typing.rst:3864 msgid "" ":class:`collections.abc.KeysView` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3858 +#: ../../library/typing.rst:3870 msgid "Deprecated alias to :class:`collections.abc.Mapping`." msgstr "棄用 :class:`collections.abc.Mapping` 的別名。" -#: ../../library/typing.rst:3860 +#: ../../library/typing.rst:3872 msgid "" ":class:`collections.abc.Mapping` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3866 +#: ../../library/typing.rst:3878 msgid "Deprecated alias to :class:`collections.abc.MappingView`." msgstr "棄用 :class:`collections.abc.MappingView` 的別名。" -#: ../../library/typing.rst:3868 +#: ../../library/typing.rst:3880 msgid "" ":class:`collections.abc.MappingView` now supports subscripting (``[]``). " "See :pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3874 +#: ../../library/typing.rst:3886 msgid "Deprecated alias to :class:`collections.abc.MutableMapping`." msgstr "棄用 :class:`collections.abc.MutableMapping` 的別名。" -#: ../../library/typing.rst:3876 +#: ../../library/typing.rst:3888 msgid "" ":class:`collections.abc.MutableMapping` now supports subscripting (``[]``). " "See :pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3883 +#: ../../library/typing.rst:3895 msgid "Deprecated alias to :class:`collections.abc.MutableSequence`." msgstr "棄用 :class:`collections.abc.MutableSequence` 的別名。" -#: ../../library/typing.rst:3885 +#: ../../library/typing.rst:3897 msgid "" ":class:`collections.abc.MutableSequence` now supports subscripting (``[]``). " "See :pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3892 +#: ../../library/typing.rst:3904 msgid "Deprecated alias to :class:`collections.abc.MutableSet`." msgstr "棄用 :class:`collections.abc.MutableSet` 的別名。" -#: ../../library/typing.rst:3894 +#: ../../library/typing.rst:3906 msgid "" ":class:`collections.abc.MutableSet` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3900 +#: ../../library/typing.rst:3912 msgid "Deprecated alias to :class:`collections.abc.Sequence`." msgstr "棄用 :class:`collections.abc.Sequence` 的別名。" -#: ../../library/typing.rst:3902 +#: ../../library/typing.rst:3914 msgid "" ":class:`collections.abc.Sequence` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3908 +#: ../../library/typing.rst:3920 msgid "Deprecated alias to :class:`collections.abc.ValuesView`." msgstr "棄用 :class:`collections.abc.ValuesView` 的別名。" -#: ../../library/typing.rst:3910 +#: ../../library/typing.rst:3922 msgid "" ":class:`collections.abc.ValuesView` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3917 +#: ../../library/typing.rst:3929 msgid "Aliases to asynchronous ABCs in :mod:`collections.abc`" msgstr ":mod:`collections.abc` 中非同步 ABC 的別名" -#: ../../library/typing.rst:3921 +#: ../../library/typing.rst:3933 msgid "Deprecated alias to :class:`collections.abc.Coroutine`." msgstr "棄用 :class:`collections.abc.Coroutine` 的別名。" -#: ../../library/typing.rst:3923 +#: ../../library/typing.rst:3935 msgid "" "See :ref:`annotating-generators-and-coroutines` for details on using :class:" "`collections.abc.Coroutine` and ``typing.Coroutine`` in type annotations." msgstr "" -#: ../../library/typing.rst:3929 +#: ../../library/typing.rst:3941 msgid "" ":class:`collections.abc.Coroutine` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3935 +#: ../../library/typing.rst:3947 msgid "Deprecated alias to :class:`collections.abc.AsyncGenerator`." msgstr "棄用 :class:`collections.abc.AsyncGenerator` 的別名。" -#: ../../library/typing.rst:3937 +#: ../../library/typing.rst:3949 msgid "" "See :ref:`annotating-generators-and-coroutines` for details on using :class:" "`collections.abc.AsyncGenerator` and ``typing.AsyncGenerator`` in type " "annotations." msgstr "" -#: ../../library/typing.rst:3943 +#: ../../library/typing.rst:3955 msgid "" ":class:`collections.abc.AsyncGenerator` now supports subscripting (``[]``). " "See :pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3948 +#: ../../library/typing.rst:3960 msgid "The ``SendType`` parameter now has a default." msgstr "``SendType`` 參數現在有預設值。" -#: ../../library/typing.rst:3953 +#: ../../library/typing.rst:3965 msgid "Deprecated alias to :class:`collections.abc.AsyncIterable`." msgstr "棄用 :class:`collections.abc.AsyncIterable` 的別名。" -#: ../../library/typing.rst:3957 +#: ../../library/typing.rst:3969 msgid "" ":class:`collections.abc.AsyncIterable` now supports subscripting (``[]``). " "See :pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3963 +#: ../../library/typing.rst:3975 msgid "Deprecated alias to :class:`collections.abc.AsyncIterator`." msgstr "棄用 :class:`collections.abc.AsyncIterator` 的別名。" -#: ../../library/typing.rst:3967 +#: ../../library/typing.rst:3979 msgid "" ":class:`collections.abc.AsyncIterator` now supports subscripting (``[]``). " "See :pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3973 +#: ../../library/typing.rst:3985 msgid "Deprecated alias to :class:`collections.abc.Awaitable`." msgstr "棄用 :class:`collections.abc.Awaitable` 的別名。" -#: ../../library/typing.rst:3977 +#: ../../library/typing.rst:3989 msgid "" ":class:`collections.abc.Awaitable` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3984 +#: ../../library/typing.rst:3996 msgid "Aliases to other ABCs in :mod:`collections.abc`" msgstr "" -#: ../../library/typing.rst:3988 +#: ../../library/typing.rst:4000 msgid "Deprecated alias to :class:`collections.abc.Iterable`." msgstr "棄用 :class:`collections.abc.Iterable` 的別名。" -#: ../../library/typing.rst:3990 +#: ../../library/typing.rst:4002 msgid "" ":class:`collections.abc.Iterable` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:3996 +#: ../../library/typing.rst:4008 msgid "Deprecated alias to :class:`collections.abc.Iterator`." msgstr "棄用 :class:`collections.abc.Iterator` 的別名。" -#: ../../library/typing.rst:3998 +#: ../../library/typing.rst:4010 msgid "" ":class:`collections.abc.Iterator` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:4004 +#: ../../library/typing.rst:4016 msgid "Deprecated alias to :class:`collections.abc.Callable`." msgstr "棄用 :class:`collections.abc.Callable` 的別名。" -#: ../../library/typing.rst:4006 +#: ../../library/typing.rst:4018 msgid "" "See :ref:`annotating-callables` for details on how to use :class:" "`collections.abc.Callable` and ``typing.Callable`` in type annotations." msgstr "" -#: ../../library/typing.rst:4009 +#: ../../library/typing.rst:4021 msgid "" ":class:`collections.abc.Callable` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:4019 +#: ../../library/typing.rst:4031 msgid "Deprecated alias to :class:`collections.abc.Generator`." msgstr "棄用 :class:`collections.abc.Generator` 的別名。" -#: ../../library/typing.rst:4021 +#: ../../library/typing.rst:4033 msgid "" "See :ref:`annotating-generators-and-coroutines` for details on using :class:" "`collections.abc.Generator` and ``typing.Generator`` in type annotations." msgstr "" -#: ../../library/typing.rst:4025 +#: ../../library/typing.rst:4037 msgid "" ":class:`collections.abc.Generator` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:4029 +#: ../../library/typing.rst:4041 msgid "Default values for the send and return types were added." msgstr "" -#: ../../library/typing.rst:4034 +#: ../../library/typing.rst:4046 msgid "Deprecated alias to :class:`collections.abc.Hashable`." msgstr "棄用 :class:`collections.abc.Hashable` 的別名。" -#: ../../library/typing.rst:4036 +#: ../../library/typing.rst:4048 msgid "Use :class:`collections.abc.Hashable` directly instead." msgstr "改為直接使用 :class:`collections.abc.Hashable`。" -#: ../../library/typing.rst:4041 +#: ../../library/typing.rst:4053 msgid "Deprecated alias to :class:`collections.abc.Reversible`." msgstr "棄用 :class:`collections.abc.Reversible` 的別名。" -#: ../../library/typing.rst:4043 +#: ../../library/typing.rst:4055 msgid "" ":class:`collections.abc.Reversible` now supports subscripting (``[]``). See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:4049 +#: ../../library/typing.rst:4061 msgid "Deprecated alias to :class:`collections.abc.Sized`." msgstr "棄用 :class:`collections.abc.Sized` 的別名。" -#: ../../library/typing.rst:4051 +#: ../../library/typing.rst:4063 msgid "Use :class:`collections.abc.Sized` directly instead." msgstr "改為直接使用 :class:`collections.abc.Sized`。" -#: ../../library/typing.rst:4057 +#: ../../library/typing.rst:4069 msgid "Aliases to :mod:`contextlib` ABCs" msgstr ":mod:`contextlib` ABC 的別名" -#: ../../library/typing.rst:4061 +#: ../../library/typing.rst:4073 msgid "Deprecated alias to :class:`contextlib.AbstractContextManager`." msgstr "" -#: ../../library/typing.rst:4063 +#: ../../library/typing.rst:4075 msgid "" "The first type parameter, ``T_co``, represents the type returned by the :" "meth:`~object.__enter__` method. The optional second type parameter, " @@ -6250,21 +6264,21 @@ msgid "" "returned by the :meth:`~object.__exit__` method." msgstr "" -#: ../../library/typing.rst:4070 +#: ../../library/typing.rst:4082 msgid "" ":class:`contextlib.AbstractContextManager` now supports subscripting " "(``[]``). See :pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:4075 +#: ../../library/typing.rst:4087 msgid "Added the optional second type parameter, ``ExitT_co``." msgstr "" -#: ../../library/typing.rst:4080 +#: ../../library/typing.rst:4092 msgid "Deprecated alias to :class:`contextlib.AbstractAsyncContextManager`." msgstr "" -#: ../../library/typing.rst:4082 +#: ../../library/typing.rst:4094 msgid "" "The first type parameter, ``T_co``, represents the type returned by the :" "meth:`~object.__aenter__` method. The optional second type parameter, " @@ -6272,21 +6286,21 @@ msgid "" "returned by the :meth:`~object.__aexit__` method." msgstr "" -#: ../../library/typing.rst:4089 +#: ../../library/typing.rst:4101 msgid "" ":class:`contextlib.AbstractAsyncContextManager` now supports subscripting " "(``[]``). See :pep:`585` and :ref:`types-genericalias`." msgstr "" -#: ../../library/typing.rst:4094 +#: ../../library/typing.rst:4106 msgid "Added the optional second type parameter, ``AExitT_co``." msgstr "" -#: ../../library/typing.rst:4098 +#: ../../library/typing.rst:4110 msgid "Deprecation Timeline of Major Features" msgstr "主要功能的棄用時程表" -#: ../../library/typing.rst:4100 +#: ../../library/typing.rst:4112 msgid "" "Certain features in ``typing`` are deprecated and may be removed in a future " "version of Python. The following table summarizes major deprecations for " @@ -6294,112 +6308,112 @@ msgid "" "listed." msgstr "" -#: ../../library/typing.rst:4107 +#: ../../library/typing.rst:4119 msgid "Feature" msgstr "" -#: ../../library/typing.rst:4108 +#: ../../library/typing.rst:4120 msgid "Deprecated in" msgstr "棄用於" -#: ../../library/typing.rst:4109 +#: ../../library/typing.rst:4121 msgid "Projected removal" msgstr "" -#: ../../library/typing.rst:4110 +#: ../../library/typing.rst:4122 msgid "PEP/issue" msgstr "" -#: ../../library/typing.rst:4111 +#: ../../library/typing.rst:4123 msgid "``typing`` versions of standard collections" msgstr "" -#: ../../library/typing.rst:4112 ../../library/typing.rst:4116 +#: ../../library/typing.rst:4124 ../../library/typing.rst:4128 msgid "3.9" msgstr "3.9" -#: ../../library/typing.rst:4113 +#: ../../library/typing.rst:4125 msgid "Undecided (see :ref:`deprecated-aliases` for more information)" msgstr "" -#: ../../library/typing.rst:4114 +#: ../../library/typing.rst:4126 msgid ":pep:`585`" msgstr ":pep:`585`" -#: ../../library/typing.rst:4115 +#: ../../library/typing.rst:4127 msgid ":class:`typing.ByteString`" msgstr ":class:`typing.ByteString`" -#: ../../library/typing.rst:4117 +#: ../../library/typing.rst:4129 msgid "3.17" msgstr "3.17" -#: ../../library/typing.rst:4118 +#: ../../library/typing.rst:4130 msgid ":gh:`91896`" msgstr ":gh:`91896`" -#: ../../library/typing.rst:4119 +#: ../../library/typing.rst:4131 msgid ":data:`typing.Text`" msgstr ":data:`typing.Text`" -#: ../../library/typing.rst:4120 +#: ../../library/typing.rst:4132 msgid "3.11" msgstr "3.11" -#: ../../library/typing.rst:4121 ../../library/typing.rst:4125 -#: ../../library/typing.rst:4129 +#: ../../library/typing.rst:4133 ../../library/typing.rst:4137 +#: ../../library/typing.rst:4141 msgid "Undecided" msgstr "" -#: ../../library/typing.rst:4122 +#: ../../library/typing.rst:4134 msgid ":gh:`92332`" msgstr ":gh:`92332`" -#: ../../library/typing.rst:4123 +#: ../../library/typing.rst:4135 msgid ":class:`typing.Hashable` and :class:`typing.Sized`" msgstr ":class:`typing.Hashable` 和 :class:`typing.Sized`" -#: ../../library/typing.rst:4124 ../../library/typing.rst:4128 +#: ../../library/typing.rst:4136 ../../library/typing.rst:4140 msgid "3.12" msgstr "3.12" -#: ../../library/typing.rst:4126 +#: ../../library/typing.rst:4138 msgid ":gh:`94309`" msgstr ":gh:`94309`" -#: ../../library/typing.rst:4127 +#: ../../library/typing.rst:4139 msgid ":data:`typing.TypeAlias`" msgstr ":data:`typing.TypeAlias`" -#: ../../library/typing.rst:4130 +#: ../../library/typing.rst:4142 msgid ":pep:`695`" msgstr ":pep:`695`" -#: ../../library/typing.rst:4131 +#: ../../library/typing.rst:4143 msgid ":func:`@typing.no_type_check_decorator `" msgstr ":func:`@typing.no_type_check_decorator `" -#: ../../library/typing.rst:4132 ../../library/typing.rst:4136 +#: ../../library/typing.rst:4144 ../../library/typing.rst:4148 msgid "3.13" msgstr "3.13" -#: ../../library/typing.rst:4133 +#: ../../library/typing.rst:4145 msgid "3.15" msgstr "3.15" -#: ../../library/typing.rst:4134 +#: ../../library/typing.rst:4146 msgid ":gh:`106309`" msgstr ":gh:`106309`" -#: ../../library/typing.rst:4135 +#: ../../library/typing.rst:4147 msgid ":data:`typing.AnyStr`" msgstr ":data:`typing.AnyStr`" -#: ../../library/typing.rst:4137 +#: ../../library/typing.rst:4149 msgid "3.18" msgstr "3.18" -#: ../../library/typing.rst:4138 +#: ../../library/typing.rst:4150 msgid ":gh:`105578`" msgstr ":gh:`105578`" diff --git a/library/wave.po b/library/wave.po index 8b08558bc0e..d7b4fd0d3ed 100644 --- a/library/wave.po +++ b/library/wave.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-07 00:19+0000\n" +"POT-Creation-Date: 2026-03-04 00:19+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-" @@ -31,8 +31,8 @@ msgid "" "Audio \"WAVE\" (or \"WAV\") file format. Only uncompressed PCM encoded wave " "files are supported." msgstr "" -":mod:`!wave` 模組為波形音訊檔案格式「WAVE」(或稱「WAV」)提供了便捷的介面。僅" -"支援未壓縮的 PCM 編碼波形檔。" +":mod:`!wave` 模組為波形音訊檔案格式「WAVE」(或稱「WAV」)提供了便捷的介面。" +"僅支援未壓縮的 PCM 編碼波形檔。" #: ../../library/wave.rst:20 msgid "" @@ -271,18 +271,33 @@ msgid "Set the number of channels." msgstr "設定音訊的通道數量。" #: ../../library/wave.rst:204 +#, fuzzy +msgid "Return the number of channels." +msgstr "設定音訊的通道數量。" + +#: ../../library/wave.rst:209 msgid "Set the sample width to *n* bytes." msgstr "設定取樣寬度為 *n* 個位元組。" -#: ../../library/wave.rst:209 +#: ../../library/wave.rst:214 +#, fuzzy +msgid "Return the sample width in bytes." +msgstr "回傳以位元組表示的取樣寬度 (sample width)。" + +#: ../../library/wave.rst:219 msgid "Set the frame rate to *n*." msgstr "設定取樣頻率為 *n*。" -#: ../../library/wave.rst:211 +#: ../../library/wave.rst:221 msgid "A non-integral input to this method is rounded to the nearest integer." msgstr "此方法的非整數輸入會被將四捨五入到最接近的整數。" -#: ../../library/wave.rst:218 +#: ../../library/wave.rst:228 +#, fuzzy +msgid "Return the frame rate." +msgstr "設定取樣頻率為 *n*。" + +#: ../../library/wave.rst:233 msgid "" "Set the number of frames to *n*. This will be changed later if the number " "of frames actually written is different (this update attempt will raise an " @@ -291,13 +306,27 @@ msgstr "" "設定幀數為 *n*。如果實際寫入的幀數不同,則稍後將進行更改(如果輸出串流不可搜" "尋,則此嘗試將引發錯誤)。" -#: ../../library/wave.rst:225 +#: ../../library/wave.rst:240 +#, fuzzy +msgid "Return the number of audio frames written so far." +msgstr "回傳音訊幀數。" + +#: ../../library/wave.rst:245 msgid "" "Set the compression type and description. At the moment, only compression " "type ``NONE`` is supported, meaning no compression." msgstr "設定壓縮類型和描述。目前只支援壓縮類型為 ``NONE``,表示無壓縮。" -#: ../../library/wave.rst:231 +#: ../../library/wave.rst:251 +#, fuzzy +msgid "Return the compression type (``'NONE'``)." +msgstr "回傳壓縮類型(僅支援 ``'NONE'`` 類型)。" + +#: ../../library/wave.rst:256 +msgid "Return the human-readable compression type name." +msgstr "" + +#: ../../library/wave.rst:261 msgid "" "The *tuple* should be ``(nchannels, sampwidth, framerate, nframes, comptype, " "compname)``, with values valid for the ``set*()`` methods. Sets all " @@ -306,7 +335,16 @@ msgstr "" "這個 *tuple* 應該是 ``(nchannels, sampwidth, framerate, nframes, comptype, " "compname)``,值需要是符合 ``set*()`` 方法的參數。設定所有參數。" -#: ../../library/wave.rst:238 +#: ../../library/wave.rst:268 +#, fuzzy +msgid "" +"Return a :func:`~collections.namedtuple` ``(nchannels, sampwidth, framerate, " +"nframes, comptype, compname)`` containing the current output parameters." +msgstr "" +"回傳一個 :func:`~collections.namedtuple` ``(nchannels, sampwidth, framerate, " +"nframes, comptype, compname)``,等同於 ``get*()`` 方法的輸出。" + +#: ../../library/wave.rst:275 msgid "" "Return current position in the file, with the same disclaimer for the :meth:" "`Wave_read.tell` and :meth:`Wave_read.setpos` methods." @@ -314,15 +352,15 @@ msgstr "" "回傳檔案中的指標位置,其指標位置含意與 :meth:`Wave_read.tell` 和 :meth:" "`Wave_read.setpos` 是一致的。" -#: ../../library/wave.rst:244 +#: ../../library/wave.rst:281 msgid "Write audio frames, without correcting *nframes*." msgstr "寫入音訊幀,不修正 *nframes*。" -#: ../../library/wave.rst:246 ../../library/wave.rst:257 +#: ../../library/wave.rst:283 ../../library/wave.rst:294 msgid "Any :term:`bytes-like object` is now accepted." msgstr "現在可接受任何 :term:`bytes-like object`。" -#: ../../library/wave.rst:252 +#: ../../library/wave.rst:289 msgid "" "Write audio frames and make sure *nframes* is correct. It will raise an " "error if the output stream is not seekable and the total number of frames " @@ -332,7 +370,7 @@ msgstr "" "寫入音訊幀並確保 *nframes* 正確。如果輸出串流不可搜尋,並且在寫入 *data* 後已" "寫入的總幀數與先前設定的 *nframes* 值不符,則會引發錯誤。" -#: ../../library/wave.rst:260 +#: ../../library/wave.rst:297 msgid "" "Note that it is invalid to set any parameters after calling :meth:" "`writeframes` or :meth:`writeframesraw`, and any attempt to do so will " diff --git a/tutorial/introduction.po b/tutorial/introduction.po index 1c640b4a314..738c9183a90 100644 --- a/tutorial/introduction.po +++ b/tutorial/introduction.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-12-01 00:17+0000\n" +"POT-Creation-Date: 2026-03-09 00:19+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-" @@ -396,12 +396,13 @@ msgstr "" "第一個包圍引號前加上 ``r`` : ::" #: ../../tutorial/introduction.rst:187 +#, fuzzy msgid "" -">>> print('C:\\some\\name') # here \\n means newline!\n" -"C:\\some\n" +">>> print('C:\\this\\name') # here \\t means tab, \\n means newline\n" +"C: his\n" "ame\n" -">>> print(r'C:\\some\\name') # note the r before the quote\n" -"C:\\some\\name" +">>> print(r'C:\\this\\name') # note the r before the quote\n" +"C:\\this\\name" msgstr "" ">>> print('C:\\some\\name') # 這裡 \\n 表示換行!\n" "C:\\some\n"