diff --git a/library/struct.po b/library/struct.po index 5cc4070b77..b05f0e78c5 100644 --- a/library/struct.po +++ b/library/struct.po @@ -1,15 +1,15 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) 2001-2022, Python Software Foundation +# Copyright (C) 2001-2025, Python Software Foundation # This file is distributed under the same license as the Python package. # # Translators: +# Matt Wang , 2025 msgid "" msgstr "" "Project-Id-Version: Python 3.13\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2024-09-23 07:52+0800\n" "PO-Revision-Date: 2018-05-23 16:11+0000\n" -"Last-Translator: Adrian Liaw \n" +"Last-Translator: Matt Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" "Language: zh_TW\n" @@ -24,7 +24,7 @@ msgstr ":mod:`!struct` --- 將位元組直譯為打包起來的二進位資料" #: ../../library/struct.rst:11 msgid "**Source code:** :source:`Lib/struct.py`" -msgstr "**原始碼:**\\ :source:`Lib/struct.py`" +msgstr "**原始碼:**:source:`Lib/struct.py`" #: ../../library/struct.rst:19 msgid "" @@ -36,6 +36,10 @@ msgid "" "connections), or data transfer between the Python application and the C " "layer." msgstr "" +"此模組可在 Python 數值與以 Python :class:`bytes` 物件表示的 C 結構之間進行轉" +"換。簡潔的\\ :ref:`格式字串 `\\ 描述了與 Python 數值之" +"間預期的轉換。此模組的函式和物件可用於兩種截然不同的應用程式:與外部來源(檔" +"案或網路連線)的資料交換,或是 Python 應用程式與 C 層之間的資料傳輸。" #: ../../library/struct.rst:29 msgid "" @@ -48,6 +52,11 @@ msgid "" "for defining byte ordering and padding between elements. See :ref:`struct-" "alignment` for details." msgstr "" +"當未給定前綴字元時會預設為原生模式。它會根據建構 Python 直譯器的平台和編譯器" +"來打包或解包資料。打包給定 C 結構的結果包含填充位元組,以維持相關 C 型別的正" +"確對齊;同樣地,解包時也會考量對齊。相反地,當在外部來源之間傳輸資料時,程式" +"設計師需負責定義位元組順序和元素之間的填充。詳情請參見 :ref:`struct-" +"alignment`。" #: ../../library/struct.rst:39 msgid "" @@ -59,6 +68,11 @@ msgid "" "of bytes implement the buffer protocol, so that they can be read/filled " "without additional copying from a :class:`bytes` object." msgstr "" +"一些 :mod:`struct` 函式(和 :class:`Struct` 的方法)接受一個 *buffer* 引數。" +"這是指實作\\ :ref:`bufferobjects` 並提供可讀或可讀寫緩衝區的物件。最常用於此" +"目的的型別是 :class:`bytes` 和 :class:`bytearray`,但許多其他可以視為位元組陣" +"列的型別都實作了緩衝區協定,因此它們可以從 :class:`bytes` 物件讀取或填入資料" +"而無需額外的複製。" #: ../../library/struct.rst:48 msgid "Functions and Exceptions" @@ -72,7 +86,7 @@ msgstr "此模組定義了以下例外和函式:" msgid "" "Exception raised on various occasions; argument is a string describing what " "is wrong." -msgstr "" +msgstr "在各種情況下都可能觸發的例外;引數是一個描述錯誤內容的字串。" #: ../../library/struct.rst:61 msgid "" @@ -80,6 +94,8 @@ msgid "" "to the format string *format*. The arguments must match the values required " "by the format exactly." msgstr "" +"回傳一個包含依照格式字串 *format* 打包的數值 *v1*、*v2*、... 的位元組物件。引" +"數必須完全符合格式所需的數值。" #: ../../library/struct.rst:68 msgid "" @@ -87,6 +103,8 @@ msgid "" "write the packed bytes into the writable buffer *buffer* starting at " "position *offset*. Note that *offset* is a required argument." msgstr "" +"依照格式字串 *format* 打包數值 *v1*、*v2*、...,並將打包後的位元組寫入可寫緩" +"衝區 *buffer* 中從位置 *offset* 開始的地方。請注意 *offset* 是必要的引數。" #: ../../library/struct.rst:75 msgid "" @@ -95,6 +113,9 @@ msgid "" "contains exactly one item. The buffer's size in bytes must match the size " "required by the format, as reflected by :func:`calcsize`." msgstr "" +"根據格式字串 *format* 從緩衝區 *buffer*\\ (推測是由 ``pack(format, ...)`` 打" +"包的)解包。結果是一個元組,即使它只包含一個項目。緩衝區的位元組大小必須符合" +"格式所需的大小,如 :func:`calcsize` 所示。" #: ../../library/struct.rst:83 msgid "" @@ -103,6 +124,9 @@ msgid "" "item. The buffer's size in bytes, starting at position *offset*, must be at " "least the size required by the format, as reflected by :func:`calcsize`." msgstr "" +"根據格式字串 *format* 從 *buffer* 的 *offset* 位置開始解包。即使它只包含一個" +"項目,結果也都是一個元組。緩衝區從位置 *offset* 開始的位元組大小,必須至少達" +"到格式所需的大小,如 :func:`calcsize` 所示。" #: ../../library/struct.rst:91 msgid "" @@ -112,20 +136,25 @@ msgid "" "buffer's size in bytes must be a multiple of the size required by the " "format, as reflected by :func:`calcsize`." msgstr "" +"根據格式字串 *format* 疊代地從緩衝區 *buffer* 解包。此函式回傳一個疊代器,它" +"會從緩衝區讀取等大小的區塊,直到消耗完所有內容。緩衝區的位元組大小必須是格式" +"所需大小的倍數,如 :func:`calcsize` 所示。" #: ../../library/struct.rst:97 msgid "Each iteration yields a tuple as specified by the format string." -msgstr "" +msgstr "每次疊代都會產生 (yield) 出一個由格式字串指定的元組。" #: ../../library/struct.rst:104 msgid "" "Return the size of the struct (and hence of the bytes object produced by " "``pack(format, ...)``) corresponding to the format string *format*." msgstr "" +"回傳對應於格式字串 *format* 的結構大小(因此也是 ``pack(format, ...)`` 所產生" +"的位元組物件的大小)。" #: ../../library/struct.rst:111 msgid "Format Strings" -msgstr "" +msgstr "格式字串" #: ../../library/struct.rst:113 msgid "" @@ -137,10 +166,15 @@ msgid "" "which describes the overall properties of the data and one or more format " "characters which describe the actual data values and padding." msgstr "" +"格式字串描述了打包和解包資料時的資料配置 (layout)。它們由\\ :ref:`格式字元 " +"`\\ 組成,這些字元指定了要打包或解包的資料型別。此外,特殊" +"字元控制\\ :ref:`位元組順序、大小和對齊 `。每個格式字串由一" +"個可選的前綴字元組成,描述資料的整體屬性,以及一個或多個描述實際資料值和填充" +"的格式字元。" #: ../../library/struct.rst:125 msgid "Byte Order, Size, and Alignment" -msgstr "" +msgstr "位元組順序、大小和對齊" #: ../../library/struct.rst:127 msgid "" @@ -151,6 +185,10 @@ msgid "" "corresponding C struct. Whether to use native byte ordering and padding or " "standard formats depends on the application." msgstr "" +"預設情況下,C 型別以機器的原生格式和位元組順序表示,並在必要時透過跳過填充位" +"元組來正確對齊(根據 C 編譯器所使用的規則)。選擇此行為使得打包結構的位元組完" +"全對應於相對應 C 結構的記憶體配置。是否使用原生位元組順序和填充或標準格式取決" +"於應用程式。" #: ../../library/struct.rst:143 msgid "" @@ -158,22 +196,24 @@ msgid "" "indicate the byte order, size and alignment of the packed data, according to " "the following table:" msgstr "" +"或者,格式字串的第一個字元可以用來指示打包資料的位元組順序、大小和對齊,如下" +"表所示:" #: ../../library/struct.rst:148 msgid "Character" -msgstr "" +msgstr "字元" #: ../../library/struct.rst:148 msgid "Byte order" -msgstr "" +msgstr "位元組順序" #: ../../library/struct.rst:148 msgid "Size" -msgstr "" +msgstr "大小" #: ../../library/struct.rst:148 msgid "Alignment" -msgstr "" +msgstr "對齊" #: ../../library/struct.rst:150 msgid "``@``" @@ -181,7 +221,7 @@ msgstr "``@``" #: ../../library/struct.rst:150 ../../library/struct.rst:152 msgid "native" -msgstr "" +msgstr "原生" #: ../../library/struct.rst:152 msgid "``=``" @@ -190,12 +230,12 @@ msgstr "``=``" #: ../../library/struct.rst:152 ../../library/struct.rst:154 #: ../../library/struct.rst:156 ../../library/struct.rst:158 msgid "standard" -msgstr "" +msgstr "標準" #: ../../library/struct.rst:152 ../../library/struct.rst:154 #: ../../library/struct.rst:156 ../../library/struct.rst:158 msgid "none" -msgstr "" +msgstr "無" #: ../../library/struct.rst:154 msgid "``<``" @@ -203,7 +243,7 @@ msgstr "``<``" #: ../../library/struct.rst:154 msgid "little-endian" -msgstr "" +msgstr "小端序" #: ../../library/struct.rst:156 msgid "``>``" @@ -211,7 +251,7 @@ msgstr "``>``" #: ../../library/struct.rst:156 msgid "big-endian" -msgstr "" +msgstr "大端序" #: ../../library/struct.rst:158 msgid "``!``" @@ -219,29 +259,29 @@ msgstr "``!``" #: ../../library/struct.rst:158 msgid "network (= big-endian)" -msgstr "" +msgstr "網路(= 大端序)" #: ../../library/struct.rst:161 msgid "If the first character is not one of these, ``'@'`` is assumed." -msgstr "" +msgstr "如果第一個字元不是這些字元之一,則假設為 ``'@'``。" #: ../../library/struct.rst:165 msgid "" "The number 1023 (``0x3ff`` in hexadecimal) has the following byte " "representations:" -msgstr "" +msgstr "數字 1023(十六進位為 ``0x3ff``)具有以下位元組表示法:" #: ../../library/struct.rst:167 msgid "``03 ff`` in big-endian (``>``)" -msgstr "" +msgstr "大端序(``>``)為 ``03 ff``" #: ../../library/struct.rst:168 msgid "``ff 03`` in little-endian (``<``)" -msgstr "" +msgstr "小端序(``<``)為 ``ff 03``" #: ../../library/struct.rst:170 msgid "Python example:" -msgstr "" +msgstr "Python 範例:" #: ../../library/struct.rst:178 msgid "" @@ -250,36 +290,48 @@ msgid "" "endian; IBM z and many legacy architectures are big-endian. " "Use :data:`sys.byteorder` to check the endianness of your system." msgstr "" +"原生位元組順序是大端序或小端序,會取決於主機系統。例如,Intel x86、AMD64 " +"(x86-64)和 Apple M1 是小端序;IBM z 和許多舊架構是大端序。可使" +"用 :data:`sys.byteorder` 來檢查你系統的位元組順序。" #: ../../library/struct.rst:183 msgid "" "Native size and alignment are determined using the C compiler's ``sizeof`` " "expression. This is always combined with native byte order." msgstr "" +"原生大小和對齊是使用 C 編譯器的 ``sizeof`` 運算式來決定的。這總是與原生位元組" +"順序結合使用。" #: ../../library/struct.rst:186 msgid "" "Standard size depends only on the format character; see the table in " "the :ref:`format-characters` section." msgstr "" +"標準大小僅取決於格式字元;請參見\\ :ref:`format-characters`\\ 區塊中的表格。" #: ../../library/struct.rst:189 msgid "" "Note the difference between ``'@'`` and ``'='``: both use native byte order, " "but the size and alignment of the latter is standardized." msgstr "" +"請注意 ``'@'`` 和 ``'='`` 之間的差異:兩者都使用原生位元組順序,但後者的大小" +"和對齊是標準化的。" #: ../../library/struct.rst:192 msgid "" "The form ``'!'`` represents the network byte order which is always big-" "endian as defined in `IETF RFC 1700 `_." msgstr "" +"``'!'`` 形式表示網路位元組順序,根據 `IETF RFC 1700 `_ 的定" +"義,它總是大端序。" #: ../../library/struct.rst:195 msgid "" "There is no way to indicate non-native byte order (force byte-swapping); use " "the appropriate choice of ``'<'`` or ``'>'``." msgstr "" +"沒有方法來指示非原生位元組順序(強制位元組交換);請使用適當的 ``'<'`` 或 " +"``'>'`` 選擇。" #: ../../library/struct.rst:198 ../../library/struct.rst:277 msgid "Notes:" @@ -290,12 +342,14 @@ msgid "" "Padding is only automatically added between successive structure members. No " "padding is added at the beginning or the end of the encoded struct." msgstr "" +"填充只會在連續的結構成員之間自動加入。編碼結構的開頭或結尾不會加入填充。" #: ../../library/struct.rst:203 msgid "" "No padding is added when using non-native size and alignment, e.g. with '<', " "'>', '=', and '!'." msgstr "" +"使用非原生大小和對齊時,例如使用 '<'、'>'、'=' 和 '!' 時,不會加入填充。" #: ../../library/struct.rst:206 msgid "" @@ -303,10 +357,12 @@ msgid "" "type, end the format with the code for that type with a repeat count of " "zero. See :ref:`struct-examples`." msgstr "" +"要將結構的結尾對齊到特定型別的對齊需求,請以該型別的碼結束格式,重複次數為" +"零。請參見\\ :ref:`struct-examples`。" #: ../../library/struct.rst:214 msgid "Format Characters" -msgstr "" +msgstr "格式字元" #: ../../library/struct.rst:216 msgid "" @@ -317,10 +373,14 @@ msgid "" "``'!'`` or ``'='``. When using native size, the size of the packed value is " "platform-dependent." msgstr "" +"格式字元具有以下意義;在給定型別的情況下,C 和 Python 數值之間的轉換應該是顯" +"而易見的。「標準大小」欄位指的是使用標準大小時(即當格式字串以 ``'<'``、" +"``'>'``、``'!'`` 或 ``'='`` 其中之一開始時)打包數值的位元組大小。使用原生大" +"小時,打包數值的大小取決於平台。" #: ../../library/struct.rst:224 msgid "Format" -msgstr "" +msgstr "格式" #: ../../library/struct.rst:224 msgid "C Type" @@ -328,11 +388,11 @@ msgstr "C Type" #: ../../library/struct.rst:224 msgid "Python type" -msgstr "" +msgstr "Python 型別" #: ../../library/struct.rst:224 msgid "Standard size" -msgstr "" +msgstr "標準大小" #: ../../library/struct.rst:224 msgid "Notes" @@ -344,11 +404,11 @@ msgstr "``x``" #: ../../library/struct.rst:226 msgid "pad byte" -msgstr "" +msgstr "填充位元組" #: ../../library/struct.rst:226 msgid "no value" -msgstr "" +msgstr "無值" #: ../../library/struct.rst:226 msgid "\\(7)" @@ -364,7 +424,7 @@ msgstr ":c:expr:`char`" #: ../../library/struct.rst:228 msgid "bytes of length 1" -msgstr "" +msgstr "長度為 1 的位元組" #: ../../library/struct.rst:228 ../../library/struct.rst:230 #: ../../library/struct.rst:232 ../../library/struct.rst:234 @@ -387,7 +447,7 @@ msgstr ":c:expr:`signed char`" #: ../../library/struct.rst:253 ../../library/struct.rst:255 #: ../../library/struct.rst:267 msgid "integer" -msgstr "" +msgstr "整數" #: ../../library/struct.rst:230 msgid "\\(1), \\(2)" @@ -569,7 +629,7 @@ msgstr ":c:expr:`char[]`" #: ../../library/struct.rst:263 ../../library/struct.rst:265 msgid "bytes" -msgstr "" +msgstr "位元組" #: ../../library/struct.rst:263 msgid "\\(9)" @@ -608,6 +668,8 @@ msgid "" "The ``'?'`` conversion code corresponds to the :c:expr:`_Bool` type defined " "by C standards since C99. In standard mode, it is represented by one byte." msgstr "" +"``'?'`` 轉換碼對應於自 C99 以來 C 標準定義的 :c:expr:`_Bool` 型別。在標準模式" +"下,它由一個位元組表示。" #: ../../library/struct.rst:287 msgid "" @@ -615,6 +677,8 @@ msgid "" "codes, if the non-integer has a :meth:`~object.__index__` method then that " "method is called to convert the argument to an integer before packing." msgstr "" +"當嘗試使用任何整數轉換碼打包非整數時,如果非整數具" +"有 :meth:`~object.__index__` 方法,則會呼叫該方法在打包之前將引數轉換為整數。" #: ../../library/struct.rst:291 msgid "Added use of the :meth:`~object.__index__` method for non-integers." @@ -627,6 +691,8 @@ msgid "" "the standard size, you can use whichever of the other integer formats fits " "your application." msgstr "" +"``'n'`` 和 ``'N'`` 轉換碼僅適用於原生大小(作為預設選擇或使用 ``'@'`` 位元組" +"順序字元)。對於標準大小,你可以使用適合你應用程式的其他整數格式。" #: ../../library/struct.rst:301 msgid "" @@ -635,6 +701,9 @@ msgid "" "``'f'``, ``'d'`` or ``'e'`` respectively), regardless of the floating-point " "format used by the platform." msgstr "" +"對於 ``'f'``、``'d'`` 和 ``'e'`` 轉換碼,打包表示法使用 IEEE 754 binary32、" +"binary64 或 binary16 格式(分別對應於 ``'f'``、``'d'`` 或 ``'e'``),無論平台" +"使用何種浮點數格式。" #: ../../library/struct.rst:307 msgid "" @@ -644,6 +713,9 @@ msgid "" "on the host system. The struct module does not interpret this as native " "ordering, so the ``'P'`` format is not available." msgstr "" +"``'P'`` 格式字元僅適用於原生位元組順序(作為預設選擇或使用 ``'@'`` 位元組順序" +"字元)。位元組順序字元 ``'='`` 根據主機系統選擇使用小端序或大端序。struct 模" +"組不將其解釋為原生順序,因此 ``'P'`` 格式不可用。" #: ../../library/struct.rst:314 msgid "" @@ -656,10 +728,16 @@ msgid "" "operations. See the Wikipedia page on the `half-precision floating-point " "format `_ for more information." msgstr "" +"IEEE 754 binary16「半精度 (half precision)」型別是在 2008 年的 `IEEE 754 標" +"準 `_\\ 修訂版中引入的。它有一個符號位元 (sign bit)、5 位" +"元指數和 11 位元精度(明確儲存 10 位元),可以全精度表示大約 ``6.1e-05`` 到 " +"``6.5e+04`` 之間的數字。此型別未被 C 編譯器廣泛支援:在典型機器上,unsigned " +"short 可以用於儲存但不能用於數學運算。請參見 Wikipedia 上的\\ `半精度浮點數格" +"式 `_\\ 頁面以取得更多資訊。" #: ../../library/struct.rst:324 msgid "When packing, ``'x'`` inserts one NUL byte." -msgstr "" +msgstr "打包時,``'x'`` 插入一個 NUL 位元組。" #: ../../library/struct.rst:327 msgid "" @@ -674,6 +752,13 @@ msgid "" "character consumes ``count`` bytes, but that the string returned can never " "contain more than 255 bytes." msgstr "" +"``'p'`` 格式字元編碼一個「Pascal 字串」,意思是儲存在\\ *固定位元組數*\\ 中的" +"短、長度可變字串,由計數指定。儲存的第一個位元組是字串的長度,或與 255 間取較" +"小者。字串的位元組在其後。如果傳遞給 :func:`pack` 的字串太長(長於計數減 " +"1),則只儲存字串的前 ``count-1`` 個位元組。如果字串短於 ``count-1``,則用空" +"位元組填充,使得總共使用恰好 count 個位元組。請注意,對於 :func:`unpack`, " +"``'p'`` 格式字元消耗 ``count`` 個位元組,但回傳的字串永遠不能包含超過 255 個" +"位元組。" #: ../../library/struct.rst:339 msgid "" @@ -689,18 +774,27 @@ msgid "" "number of bytes. As a special case, ``'0s'`` means a single, empty string " "(while ``'0c'`` means 0 characters)." msgstr "" +"對於 ``'s'`` 格式字元,計數被直譯為位元組的長度,而不是像其他格式字元那樣的重" +"複次數;例如,``'10s'`` 表示一個 10 位元組字串,對應於單一 Python 位元組字" +"串,而 ``'10c'`` 表示 10 個獨立的單位元組字元元素(例如 ``cccccccccc``),對" +"應於十個不同的 Python 位元組物件。(請參見 :ref:`struct-examples` 以了解具體" +"差異的示範。)如果未給定計數,則預設為 1。打包時,會適當地截斷或用空位元組填" +"充字串以使其適合。解包時,結果位元組物件總是恰好具有指定的位元組數。作為特殊" +"情況,``'0s'`` 表示單一空字串(而 ``'0c'`` 表示 0 個字元)。" #: ../../library/struct.rst:352 msgid "" "A format character may be preceded by an integral repeat count. For " "example, the format string ``'4h'`` means exactly the same as ``'hhhh'``." msgstr "" +"格式字元前面可以加上整數重複次數。例如,格式字串 ``'4h'`` 與 ``'hhhh'`` 意思" +"完全相同。" #: ../../library/struct.rst:355 msgid "" "Whitespace characters between formats are ignored; a count and its format " "must not contain whitespace though." -msgstr "" +msgstr "格式之間的空白字元會被忽略;但是計數和其格式不能包含空白字元。" #: ../../library/struct.rst:358 msgid "" @@ -709,12 +803,17 @@ msgid "" "``'Q'``), if ``x`` is outside the valid range for that format " "then :exc:`struct.error` is raised." msgstr "" +"當使用整數格式之一(``'b'``、``'B'``、``'h'``、``'H'``、``'i'``、``'I'``、" +"``'l'``、``'L'``、``'q'``、``'Q'``)打包數值 ``x`` 時,如果 ``x`` 超出該格式" +"的有效範圍,則會觸發 :exc:`struct.error`。" #: ../../library/struct.rst:363 msgid "" "Previously, some of the integer formats wrapped out-of-range values and " "raised :exc:`DeprecationWarning` instead of :exc:`struct.error`." msgstr "" +"以前一些整數格式會環繞超出範圍的數值並引發 :exc:`DeprecationWarning` 而不" +"是 :exc:`struct.error`。" #: ../../library/struct.rst:369 msgid "" @@ -723,6 +822,9 @@ msgid "" "used. Either 0 or 1 in the native or standard bool representation will be " "packed, and any non-zero value will be ``True`` when unpacking." msgstr "" +"對於 ``'?'`` 格式字元,回傳值是 :const:`True` 或 :const:`False`。打包時,使用" +"引數物件的真值。原生或標準布林值表示法中的 0 或 1 將被打包,解包時任何非零值" +"都將為 ``True``。" #: ../../library/struct.rst:379 msgid "Examples" @@ -734,12 +836,14 @@ msgid "" "of any prefix character) may not match what the reader's machine produces as " "that depends on the platform and compiler." msgstr "" +"原生位元組順序範例(由 ``'@'`` 格式前綴或缺少任何前綴字元指定)可能與讀者機器" +"產生的結果不符,因為這取決於平台和編譯器。" #: ../../library/struct.rst:387 msgid "" "Pack and unpack integers of three different sizes, using big endian " "ordering::" -msgstr "" +msgstr "使用大端序打包和解包三種不同大小的整數: ::" #: ../../library/struct.rst:390 msgid "" @@ -761,7 +865,7 @@ msgstr "" #: ../../library/struct.rst:398 msgid "Attempt to pack an integer which is too large for the defined field::" -msgstr "" +msgstr "嘗試打包對於定義欄位來說太大的整數: ::" #: ../../library/struct.rst:400 msgid "" @@ -778,7 +882,7 @@ msgstr "" #: ../../library/struct.rst:405 msgid "" "Demonstrate the difference between ``'s'`` and ``'c'`` format characters::" -msgstr "" +msgstr "示範 ``'s'`` 和 ``'c'`` 格式字元之間的差異: ::" #: ../../library/struct.rst:408 msgid "" @@ -796,7 +900,7 @@ msgstr "" msgid "" "Unpacked fields can be named by assigning them to variables or by wrapping " "the result in a named tuple::" -msgstr "" +msgstr "解包的欄位可以透過將其指派給變數或將結果包裝在具名元組中來命名: ::" #: ../../library/struct.rst:416 msgid "" @@ -825,6 +929,10 @@ msgid "" "integer on a four-byte boundary. In this example, the output was produced on " "a little endian machine::" msgstr "" +"在原生模式下,格式字元的順序可能會影響大小,因為填充是隱式的。在標準模式下," +"使用者負責插入任何所需的填充。請注意下面第一個 ``pack`` 呼叫中,在打包的 " +"``'#'`` 之後加入了三個 NUL 位元組,以將後續整數對齊到四位元組邊界。在此範例" +"中,輸出是在小端序機器上產生的: ::" #: ../../library/struct.rst:432 msgid "" @@ -851,6 +959,8 @@ msgid "" "The following format ``'llh0l'`` results in two pad bytes being added at the " "end, assuming the platform's longs are aligned on 4-byte boundaries::" msgstr "" +"假設平台的 long 對齊到 4 位元組邊界,以下格式 ``'llh0l'`` 會在結尾加入兩個填" +"充位元組: ::" #: ../../library/struct.rst:444 msgid "" @@ -866,7 +976,7 @@ msgstr ":mod:`array` 模組" #: ../../library/struct.rst:451 msgid "Packed binary storage of homogeneous data." -msgstr "" +msgstr "同質資料的打包二進位儲存。" #: ../../library/struct.rst:453 msgid "Module :mod:`json`" @@ -874,7 +984,7 @@ msgstr ":mod:`json` 模組" #: ../../library/struct.rst:454 msgid "JSON encoder and decoder." -msgstr "" +msgstr "JSON 編碼器和解碼器。" #: ../../library/struct.rst:456 msgid "Module :mod:`pickle`" @@ -882,11 +992,11 @@ msgstr ":mod:`pickle` 模組" #: ../../library/struct.rst:457 msgid "Python object serialization." -msgstr "" +msgstr "Python 物件序列化。" #: ../../library/struct.rst:463 msgid "Applications" -msgstr "" +msgstr "應用" #: ../../library/struct.rst:465 msgid "" @@ -897,10 +1007,15 @@ msgid "" "layout (:ref:`standard formats`). Generally " "speaking, the format strings constructed for these two domains are distinct." msgstr "" +":mod:`struct` 模組有兩種主要應用程式:在應用程式內或使用相同編譯器編譯的另一" +"個應用程式之間進行 Python 和 C 程式碼的資料交換(:ref:`原生格式 `),以及使用約定資料配置的應用程式之間的資料交換(:ref:`標準" +"格式 `)。一般來說,為這兩個領域建構的格式字串是不同" +"的。" #: ../../library/struct.rst:476 msgid "Native Formats" -msgstr "" +msgstr "原生格式" #: ../../library/struct.rst:478 msgid "" @@ -912,11 +1027,15 @@ msgid "" "format string to round up to the correct byte boundary for proper alignment " "of consecutive chunks of data." msgstr "" +"當構造模擬原生配置的格式字串時,編譯器和機器架構會決定位元組順序和填充。在這" +"種情況下,應該使用 ``@`` 格式字元來指定原生位元組順序和資料大小。內部填充位元" +"組通常會自動插入。可能需要在格式字串的結尾使用零重複格式碼來向上舍入到正確的" +"位元組邊界,以便正確對齊連續的資料區塊 (chunks)。" #: ../../library/struct.rst:486 msgid "" "Consider these two simple examples (on a 64-bit, little-endian machine)::" -msgstr "" +msgstr "考慮這兩個簡單範例(在 64 位元小端序機器上): ::" #: ../../library/struct.rst:489 msgid "" @@ -936,6 +1055,8 @@ msgid "" "string without the use of extra padding. A zero-repeat format code solves " "that problem::" msgstr "" +"在第二個格式字串的結尾,如果不使用額外填充,資料不會填充到 8 位元組邊界。零重" +"複格式碼解決了這個問題: ::" #: ../../library/struct.rst:498 msgid "" @@ -950,16 +1071,18 @@ msgid "" "The ``'x'`` format code can be used to specify the repeat, but for native " "formats it is better to use a zero-repeat format like ``'0l'``." msgstr "" +"``'x'`` 格式碼可以用來指定重複,但對於原生格式來說最好使用像 ``'0l'`` 這樣的" +"零重複格式。" #: ../../library/struct.rst:504 msgid "" "By default, native byte ordering and alignment is used, but it is better to " "be explicit and use the ``'@'`` prefix character." -msgstr "" +msgstr "預設使用原生位元組順序和對齊,但最好明確使用 ``'@'`` 前綴字元。" #: ../../library/struct.rst:511 msgid "Standard Formats" -msgstr "" +msgstr "標準格式" #: ../../library/struct.rst:513 msgid "" @@ -974,6 +1097,12 @@ msgid "" "must explicitly add ``'x'`` pad bytes where needed. Revisiting the examples " "from the previous section, we have::" msgstr "" +"當與你的行程之外的網路或儲存區等交換資料時,要夠精確。指定確切的位元組順序、" +"大小和對齊。不要假設它們與特定機器的原生順序匹配。例如,網路位元組順序是大端" +"序,而許多流行的 CPU 是小端序。透過明確定義這一點,使用者無需關心其程式碼運行" +"的平台細節。第一個字元通常應該是 ``<`` 或 ``>``\\ (或 ``!``)。填充是程式設" +"計師的責任。零重複格式字元不會起作用。取而代之的是使用者必須在需要的地方明確" +"加入 ``'x'`` 填充位元組。重新檢視上一節的範例,我們有: ::" #: ../../library/struct.rst:525 msgid "" @@ -1013,6 +1142,8 @@ msgid "" "when executed on different machines. For example, the examples below were " "executed on a 32-bit machine::" msgstr "" +"上述結果(在 64 位元機器上執行)和在不同機器上執行時不保證會匹配。例如,下面" +"的範例是在 32 位元機器上執行的: ::" #: ../../library/struct.rst:544 msgid "" @@ -1045,6 +1176,9 @@ msgid "" "its methods is more efficient than calling module-level functions with the " "same format since the format string is only compiled once." msgstr "" +"回傳一個新的 Struct 物件,它會根據格式字串 *format* 寫入和讀取二進位資料。建" +"立一次 ``Struct`` 物件並呼叫其方法比使用相同格式呼叫模組層級函式更有效率,因" +"為格式字串只編譯一次。" #: ../../library/struct.rst:569 msgid "" @@ -1052,26 +1186,32 @@ msgid "" "level functions are cached, so programs that use only a few format strings " "needn't worry about reusing a single :class:`Struct` instance." msgstr "" +"傳遞給模組層級函式的最近一個格式字串的編譯版本會被快取起來,因此僅使用少數格" +"式字串的程式無需擔心重複使用單一 :class:`Struct` 實例。" #: ../../library/struct.rst:574 msgid "Compiled Struct objects support the following methods and attributes:" -msgstr "" +msgstr "編譯過的 Struct 物件支援以下方法和屬性:" #: ../../library/struct.rst:578 msgid "" "Identical to the :func:`pack` function, using the compiled format. " "(``len(result)`` will equal :attr:`size`.)" msgstr "" +"與 :func:`pack` 函式相同,會使用編譯過的格式。(``len(result)`` 將等" +"於 :attr:`size`。)" #: ../../library/struct.rst:584 msgid "Identical to the :func:`pack_into` function, using the compiled format." -msgstr "" +msgstr "與 :func:`pack_into` 函式相同,會使用編譯過的格式。" #: ../../library/struct.rst:589 msgid "" "Identical to the :func:`unpack` function, using the compiled format. The " "buffer's size in bytes must equal :attr:`size`." msgstr "" +"與 :func:`unpack` 函式相同,會使用編譯過的格式。緩衝區的位元組大小必須等" +"於 :attr:`size`。" #: ../../library/struct.rst:595 msgid "" @@ -1079,30 +1219,36 @@ msgid "" "The buffer's size in bytes, starting at position *offset*, must be at " "least :attr:`size`." msgstr "" +"與 :func:`unpack_from` 函式相同,會使用編譯過的格式。緩衝區從位置 *offset* 開" +"始的位元組大小必須至少為 :attr:`size`。" #: ../../library/struct.rst:602 msgid "" "Identical to the :func:`iter_unpack` function, using the compiled format. " "The buffer's size in bytes must be a multiple of :attr:`size`." msgstr "" +"與 :func:`iter_unpack` 函式相同,會使用編譯過的格式。緩衝區的位元組大小必須" +"是 :attr:`size` 的倍數。" #: ../../library/struct.rst:609 msgid "The format string used to construct this Struct object." -msgstr "" +msgstr "用於建構此 Struct 物件的格式字串。" #: ../../library/struct.rst:611 msgid "The format string type is now :class:`str` instead of :class:`bytes`." -msgstr "" +msgstr "格式字串型別現在是 :class:`str` 而不是 :class:`bytes`。" #: ../../library/struct.rst:616 msgid "" "The calculated size of the struct (and hence of the bytes object produced by " "the :meth:`pack` method) corresponding to :attr:`format`." msgstr "" +"對應於 :attr:`format` 的結構之計算出的大小(因此也是 :meth:`pack` 方法所產生" +"的位元組物件的大小)。" #: ../../library/struct.rst:619 msgid "The *repr()* of structs has changed. It is now:" -msgstr "" +msgstr "結構的 *repr()* 已經改變。現在是:" #: ../../library/struct.rst:13 msgid "C" diff --git a/tutorial/floatingpoint.po b/tutorial/floatingpoint.po index 1492e25182..32a61b128d 100644 --- a/tutorial/floatingpoint.po +++ b/tutorial/floatingpoint.po @@ -510,11 +510,9 @@ msgstr "" "8.042178034628478e-13\n" ">>> total = 0.0\n" ">>> for x in arr:\n" -"... total += x # 在標準精度中進行多次捨入 " -"\n" +"... total += x # 在標準精度中進行多次捨入\n" "...\n" -">>> total # 直接相加沒有正確的數字 " -"\n" +">>> total # 直接相加沒有正確的數字\n" "-0.0051575902860057365" #: ../../tutorial/floatingpoint.rst:260