diff --git a/reference/import.po b/reference/import.po index 8886f39575..965acca8e4 100644 --- a/reference/import.po +++ b/reference/import.po @@ -16,7 +16,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Poedit 3.5\n" +"X-Generator: Poedit 3.8\n" #: ../../reference/import.rst:6 msgid "The import system" @@ -27,13 +27,13 @@ msgid "" "Python code in one :term:`module` gains access to the code in another module " "by the process of :term:`importing` it. The :keyword:`import` statement is " "the most common way of invoking the import machinery, but it is not the only " -"way. Functions such as :func:`importlib.import_module` and built-in :func:" -"`__import__` can also be used to invoke the import machinery." +"way. Functions such as :func:`importlib.import_module` and built-" +"in :func:`__import__` can also be used to invoke the import machinery." msgstr "" "一個 :term:`module` 中的 Python 程式碼透過 :term:`importing` 的過程來存取另一" "個模組中的程式碼。:keyword:`import` 陳述式是叫用 (invoke) 引入機制最常見的方" -"法,但這不是唯一的方法。函式如 :func:`importlib.import_module` 以及內建函式 :" -"func:`__import__` 也可以用來叫用引入機制。" +"法,但這不是唯一的方法。函式如 :func:`importlib.import_module` 以及內建函" +"式 :func:`__import__` 也可以用來叫用引入機制。" #: ../../reference/import.rst:16 msgid "" @@ -42,8 +42,8 @@ msgid "" "local scope. The search operation of the :keyword:`!import` statement is " "defined as a call to the :func:`__import__` function, with the appropriate " "arguments. The return value of :func:`__import__` is used to perform the " -"name binding operation of the :keyword:`!import` statement. See the :" -"keyword:`!import` statement for the exact details of that name binding " +"name binding operation of the :keyword:`!import` statement. See " +"the :keyword:`!import` statement for the exact details of that name binding " "operation." msgstr "" ":keyword:`import` 陳述式結合了兩個操作:首先搜尋指定的模組,然後將搜尋結果繫" @@ -67,14 +67,15 @@ msgstr "" #: ../../reference/import.rst:31 msgid "" -"When an :keyword:`import` statement is executed, the standard builtin :func:" -"`__import__` function is called. Other mechanisms for invoking the import " -"system (such as :func:`importlib.import_module`) may choose to bypass :func:" -"`__import__` and use their own solutions to implement import semantics." +"When an :keyword:`import` statement is executed, the standard " +"builtin :func:`__import__` function is called. Other mechanisms for invoking " +"the import system (such as :func:`importlib.import_module`) may choose to " +"bypass :func:`__import__` and use their own solutions to implement import " +"semantics." msgstr "" "當執行 :keyword:`import` 陳述式時,會呼叫內建的 :func:`__import__` 函式。其他" -"叫用引入系統的機制(如 :func:`importlib.import_module`)可以選擇略過 :func:" -"`__import__`,並使用它們自己的解決方案來實作引入語意。" +"叫用引入系統的機制(如 :func:`importlib.import_module`)可以選擇略" +"過 :func:`__import__`,並使用它們自己的解決方案來實作引入語意。" #: ../../reference/import.rst:36 msgid "" @@ -86,14 +87,15 @@ msgid "" "using various hooks described in the sections below." msgstr "" "當模組首次被引入時,Python 會搜尋該模組,若找到則會建立一個模組物件 " -"[#fnmo]_,並對其進行初始化。如果找不到指定的模組,則會引發 :exc:" -"`ModuleNotFoundError`。當引入機制被叫用時,Python 會實作各種策略來搜尋指定的" -"模組。這些策略可以透過使用以下章節描述的各種 hook(掛鉤)來修改和擴展。" +"[#fnmo]_,並對其進行初始化。如果找不到指定的模組,則會引" +"發 :exc:`ModuleNotFoundError`。當引入機制被叫用時,Python 會實作各種策略來搜" +"尋指定的模組。這些策略可以透過使用以下章節描述的各種 hook(掛鉤)來修改和擴" +"展。" #: ../../reference/import.rst:43 msgid "" -"The import system has been updated to fully implement the second phase of :" -"pep:`302`. There is no longer any implicit import machinery - the full " +"The import system has been updated to fully implement the second phase " +"of :pep:`302`. There is no longer any implicit import machinery - the full " "import system is exposed through :data:`sys.meta_path`. In addition, native " "namespace package support has been implemented (see :pep:`420`)." msgstr "" @@ -113,9 +115,10 @@ msgid "" "import machinery. Refer to the :mod:`importlib` library documentation for " "additional detail." msgstr "" -":mod:`importlib` 模組提供了豐富的 API 來與引入系統互動。例如,:func:" -"`importlib.import_module` 提供了一個比內建的 :func:`__import__` 更推薦且更簡" -"單的 API 來叫用引入機制。更多詳細資訊請參閱 :mod:`importlib` 函式庫文件。" +":mod:`importlib` 模組提供了豐富的 API 來與引入系統互動。例" +"如,:func:`importlib.import_module` 提供了一個比內建的 :func:`__import__` 更" +"推薦且更簡單的 API 來叫用引入機制。更多詳細資訊請參閱 :mod:`importlib` 函式庫" +"文件。" #: ../../reference/import.rst:62 msgid "Packages" @@ -167,8 +170,8 @@ msgid "" msgstr "" "所有模組都有一個名稱。子套件的名稱與其父套件名稱之間用一個點來分隔,類似於 " "Python 的標準屬性存取語法。因此,你可能會有一個名為 :mod:`email` 的套件,該套" -"件又有一個名為 :mod:`email.mime` 的子套件,並且該子套件中有一個名為 :mod:" -"`email.mime.text` 的模組。" +"件又有一個名為 :mod:`email.mime` 的子套件,並且該子套件中有一個名" +"為 :mod:`email.mime.text` 的模組。" #: ../../reference/import.rst:93 msgid "Regular packages" @@ -180,18 +183,18 @@ msgid "" "package>` and :term:`namespace packages `. Regular " "packages are traditional packages as they existed in Python 3.2 and earlier. " "A regular package is typically implemented as a directory containing an " -"``__init__.py`` file. When a regular package is imported, this ``__init__." -"py`` file is implicitly executed, and the objects it defines are bound to " -"names in the package's namespace. The ``__init__.py`` file can contain the " -"same Python code that any other module can contain, and Python will add some " -"additional attributes to the module when it is imported." -msgstr "" -"Python 定義了兩種類型的套件,:term:`一般套件 `\\ 和\\ :term:" -"`命名空間套件 `。一般套件是 Python 3.2 及更早版本中存在的" -"傳統套件。一般套件通常實作成一個包含 ``__init__.py`` 檔案的目錄。當引入一般套" -"件時,該 ``__init__.py`` 檔案會被隱式執行,其定義的物件會繫結到該套件的命名空" -"間中的名稱。``__init__.py`` 檔案可以包含與任何其他模組相同的 Python 程式碼," -"並且 Python 會在引入時為該模組增加一些額外的屬性。" +"``__init__.py`` file. When a regular package is imported, this " +"``__init__.py`` file is implicitly executed, and the objects it defines are " +"bound to names in the package's namespace. The ``__init__.py`` file can " +"contain the same Python code that any other module can contain, and Python " +"will add some additional attributes to the module when it is imported." +msgstr "" +"Python 定義了兩種類型的套件,:term:`一般套件 `\\ 和" +"\\ :term:`命名空間套件 `。一般套件是 Python 3.2 及更早版本" +"中存在的傳統套件。一般套件通常實作成一個包含 ``__init__.py`` 檔案的目錄。當引" +"入一般套件時,該 ``__init__.py`` 檔案會被隱式執行,其定義的物件會繫結到該套件" +"的命名空間中的名稱。``__init__.py`` 檔案可以包含與任何其他模組相同的 Python " +"程式碼,並且 Python 會在引入時為該模組增加一些額外的屬性。" #: ../../reference/import.rst:108 msgid "" @@ -280,7 +283,7 @@ msgstr "" #: ../../reference/import.rst:156 msgid "See also :pep:`420` for the namespace package specification." -msgstr "有關命名空間套件的規範,請參見 :pep:`420`。" +msgstr "有關命名空間套件的規格,請參見 :pep:`420`。" #: ../../reference/import.rst:160 msgid "Searching" @@ -297,21 +300,21 @@ msgid "" msgstr "" "在開始搜尋之前,Python 需要被引入模組(或套件,但在本討論中,兩者的區別無關緊" "要)的完整\\ :term:`限定名稱 (qualified name) `。此名稱可能來" -"自 :keyword:`import` 陳述式的各種引數,或來自 :func:`importlib." -"import_module` 或 :func:`__import__` 函式的參數。" +"自 :keyword:`import` 陳述式的各種引數,或來" +"自 :func:`importlib.import_module` 或 :func:`__import__` 函式的參數。" #: ../../reference/import.rst:168 msgid "" "This name will be used in various phases of the import search, and it may be " "the dotted path to a submodule, e.g. ``foo.bar.baz``. In this case, Python " -"first tries to import ``foo``, then ``foo.bar``, and finally ``foo.bar." -"baz``. If any of the intermediate imports fail, a :exc:`ModuleNotFoundError` " -"is raised." +"first tries to import ``foo``, then ``foo.bar``, and finally " +"``foo.bar.baz``. If any of the intermediate imports fail, " +"a :exc:`ModuleNotFoundError` is raised." msgstr "" "此名稱將在引入搜尋的各個階段中使用,並且它可能是指向子模組的點分隔路徑,例如 " -"``foo.bar.baz``。在這種情況下,Python 會首先嘗試引入 ``foo``,然後是 ``foo." -"bar``,最後是 ``foo.bar.baz``。如果任何中間引入失敗,則會引發 :exc:" -"`ModuleNotFoundError`。" +"``foo.bar.baz``。在這種情況下,Python 會首先嘗試引入 ``foo``,然後是 " +"``foo.bar``,最後是 ``foo.bar.baz``。如果任何中間引入失敗,則會引" +"發 :exc:`ModuleNotFoundError`。" #: ../../reference/import.rst:175 msgid "The module cache" @@ -327,21 +330,21 @@ msgid "" "module object." msgstr "" "在引入搜尋過程中首先檢查的地方是 :data:`sys.modules`。此對映用作所有先前引入" -"過的模組的快取,包括中間路徑。因此,如果 ``foo.bar.baz`` 之前已被引入,:data:" -"`sys.modules` 將包含 ``foo``、``foo.bar`` 和 ``foo.bar.baz`` 的條目。每個鍵的" -"值都是相應的模組物件。" +"過的模組的快取,包括中間路徑。因此,如果 ``foo.bar.baz`` 之前已被引" +"入,:data:`sys.modules` 將包含 ``foo``、``foo.bar`` 和 ``foo.bar.baz`` 的條" +"目。每個鍵的值都是相應的模組物件。" #: ../../reference/import.rst:187 msgid "" "During import, the module name is looked up in :data:`sys.modules` and if " "present, the associated value is the module satisfying the import, and the " -"process completes. However, if the value is ``None``, then a :exc:" -"`ModuleNotFoundError` is raised. If the module name is missing, Python will " -"continue searching for the module." +"process completes. However, if the value is ``None``, then " +"a :exc:`ModuleNotFoundError` is raised. If the module name is missing, " +"Python will continue searching for the module." msgstr "" "在引入過程中,會在 :data:`sys.modules` 中查找模組名稱,如果存在,則相關的值為" -"滿足此引入的模組,此引入過程即完成。然而,如果值是 ``None``,則會引發 :exc:" -"`ModuleNotFoundError`。如果模組名稱不存在,Python 會繼續搜尋該模組。" +"滿足此引入的模組,此引入過程即完成。然而,如果值是 ``None``,則會引" +"發 :exc:`ModuleNotFoundError`。如果模組名稱不存在,Python 會繼續搜尋該模組。" #: ../../reference/import.rst:193 msgid "" @@ -349,8 +352,8 @@ msgid "" "associated module (as other modules may hold references to it), but it will " "invalidate the cache entry for the named module, causing Python to search " "anew for the named module upon its next import. The key can also be assigned " -"to ``None``, forcing the next import of the module to result in a :exc:" -"`ModuleNotFoundError`." +"to ``None``, forcing the next import of the module to result in " +"a :exc:`ModuleNotFoundError`." msgstr "" ":data:`sys.modules` 是可寫入的。刪除一個鍵可能不會銷毀相關聯的模組(因為其他" "模組可能持有對它的參照),但會使指定的模組的快取條目失效,導致 Python 在下一" @@ -361,14 +364,14 @@ msgstr "" msgid "" "Beware though, as if you keep a reference to the module object, invalidate " "its cache entry in :data:`sys.modules`, and then re-import the named module, " -"the two module objects will *not* be the same. By contrast, :func:`importlib." -"reload` will reuse the *same* module object, and simply reinitialise the " -"module contents by rerunning the module's code." +"the two module objects will *not* be the same. By " +"contrast, :func:`importlib.reload` will reuse the *same* module object, and " +"simply reinitialise the module contents by rerunning the module's code." msgstr "" "但請注意,如果你保留了對模組物件的參照,並在 :data:`sys.modules` 中使其快取條" -"目失效,然後重新引入指定的模組,這兩個模組物件將\\ *不會*\\ 相同。相比之下,:" -"func:`importlib.reload` 會重用\\ *相同的*\\ 模組物件,並透過重新執行模組的程" -"式碼來簡單地重新初始化模組內容。" +"目失效,然後重新引入指定的模組,這兩個模組物件將\\ *不會*\\ 相同。相比之" +"下,:func:`importlib.reload` 會重用\\ *相同的*\\ 模組物件,並透過重新執行模組" +"的程式碼來簡單地重新初始化模組內容。" #: ../../reference/import.rst:210 msgid "Finders and loaders" @@ -378,18 +381,18 @@ msgstr "尋檢器 (Finder) 與載入器 (Loader)" msgid "" "If the named module is not found in :data:`sys.modules`, then Python's " "import protocol is invoked to find and load the module. This protocol " -"consists of two conceptual objects, :term:`finders ` and :term:" -"`loaders `. A finder's job is to determine whether it can find the " -"named module using whatever strategy it knows about. Objects that implement " -"both of these interfaces are referred to as :term:`importers ` - " -"they return themselves when they find that they can load the requested " -"module." +"consists of two conceptual objects, :term:`finders ` " +"and :term:`loaders `. A finder's job is to determine whether it can " +"find the named module using whatever strategy it knows about. Objects that " +"implement both of these interfaces are referred to as :term:`importers " +"` - they return themselves when they find that they can load the " +"requested module." msgstr "" "如果在 :data:`sys.modules` 中找不到指定的模組,則會叫用 Python 的引入協定來尋" -"找並載入該模組。這個協定由兩個概念性物件組成,:term:`尋檢器 ` 和\\ :" -"term:`載入器 `。尋檢器的任務是使用其已知的策略來確定是否能找到命名模" -"組。實作這兩個介面的物件稱為\\ :term:`引入器 (importer) ` ——當它們" -"發現可以載入所請求的模組時,會回傳它們自己。" +"找並載入該模組。這個協定由兩個概念性物件組成,:term:`尋檢器 ` 和" +"\\ :term:`載入器 `。尋檢器的任務是使用其已知的策略來確定是否能找到命" +"名模組。實作這兩個介面的物件稱為\\ :term:`引入器 (importer) ` ——當" +"它們發現可以載入所請求的模組時,會回傳它們自己。" #: ../../reference/import.rst:225 msgid "" @@ -470,10 +473,10 @@ msgstr "" #: ../../reference/import.rst:269 msgid "" -"Import path hooks are called as part of :data:`sys.path` (or ``package." -"__path__``) processing, at the point where their associated path item is " -"encountered. Import path hooks are registered by adding new callables to :" -"data:`sys.path_hooks` as described below." +"Import path hooks are called as part of :data:`sys.path` (or " +"``package.__path__``) processing, at the point where their associated path " +"item is encountered. Import path hooks are registered by adding new " +"callables to :data:`sys.path_hooks` as described below." msgstr "" "引入路徑掛鉤被視為 :data:`sys.path`\\ (或 ``package.__path__``)處理過程的一" "部分來呼叫,當遇到與其相關聯的路徑項目時就會被觸發。引入路徑掛鉤透過將新的可" @@ -488,17 +491,18 @@ msgid "" "When the named module is not found in :data:`sys.modules`, Python next " "searches :data:`sys.meta_path`, which contains a list of meta path finder " "objects. These finders are queried in order to see if they know how to " -"handle the named module. Meta path finders must implement a method called :" -"meth:`~importlib.abc.MetaPathFinder.find_spec` which takes three arguments: " -"a name, an import path, and (optionally) a target module. The meta path " -"finder can use any strategy it wants to determine whether it can handle the " -"named module or not." -msgstr "" -"當在 :data:`sys.modules` 中找不到命名模組時,Python 接下來會搜尋 :data:`sys." -"meta_path`,其中包含一個元路徑尋檢器物件串列。這些尋檢器會依次被查詢,看它們" -"是否知道如何處理命名模組。元路徑尋檢器必須實作一個名為 :meth:`~importlib.abc." -"MetaPathFinder.find_spec` 的方法,該方法接收三個引數:名稱、引入路徑和(可選" -"的)目標模組。元路徑尋檢器可以使用任何策略來確定它是否能處理命名模組。" +"handle the named module. Meta path finders must implement a method " +"called :meth:`~importlib.abc.MetaPathFinder.find_spec` which takes three " +"arguments: a name, an import path, and (optionally) a target module. The " +"meta path finder can use any strategy it wants to determine whether it can " +"handle the named module or not." +msgstr "" +"當在 :data:`sys.modules` 中找不到命名模組時,Python 接下來會搜" +"尋 :data:`sys.meta_path`,其中包含一個元路徑尋檢器物件串列。這些尋檢器會依次" +"被查詢,看它們是否知道如何處理命名模組。元路徑尋檢器必須實作一個名" +"為 :meth:`~importlib.abc.MetaPathFinder.find_spec` 的方法,該方法接收三個引" +"數:名稱、引入路徑和(可選的)目標模組。元路徑尋檢器可以使用任何策略來確定它" +"是否能處理命名模組。" #: ../../reference/import.rst:291 msgid "" @@ -540,16 +544,17 @@ msgid "" "importing ``foo.bar.baz`` will first perform a top level import, calling " "``mpf.find_spec(\"foo\", None, None)`` on each meta path finder (``mpf``). " "After ``foo`` has been imported, ``foo.bar`` will be imported by traversing " -"the meta path a second time, calling ``mpf.find_spec(\"foo.bar\", foo." -"__path__, None)``. Once ``foo.bar`` has been imported, the final traversal " -"will call ``mpf.find_spec(\"foo.bar.baz\", foo.bar.__path__, None)``." +"the meta path a second time, calling ``mpf.find_spec(\"foo.bar\", " +"foo.__path__, None)``. Once ``foo.bar`` has been imported, the final " +"traversal will call ``mpf.find_spec(\"foo.bar.baz\", foo.bar.__path__, " +"None)``." msgstr "" "對於一個引入請求,元路徑可能會被遍歷多次。例如,假設參與的模組都沒有被快取," "則引入 ``foo.bar.baz`` 將首先執行頂層引入,對每個元路徑尋檢器(``mpf``)呼叫 " "``mpf.find_spec(\"foo\", None, None)``。當 ``foo`` 被引入後,將再次藉由遍歷元" "路徑引入 ``foo.bar``,並呼叫 ``mpf.find_spec(\"foo.bar\", foo.__path__, " -"None)``。當 ``foo.bar`` 被引入後,最後一次遍歷會呼叫 ``mpf.find_spec(\"foo." -"bar.baz\", foo.bar.__path__, None)``。" +"None)``。當 ``foo.bar`` 被引入後,最後一次遍歷會呼叫 " +"``mpf.find_spec(\"foo.bar.baz\", foo.bar.__path__, None)``。" #: ../../reference/import.rst:318 msgid "" @@ -576,26 +581,27 @@ msgid "" "The :meth:`~importlib.abc.MetaPathFinder.find_spec` method of meta path " "finders replaced :meth:`!find_module`, which is now deprecated. While it " "will continue to work without change, the import machinery will try it only " -"if the finder does not implement :meth:`~importlib.abc.MetaPathFinder." -"find_spec`." +"if the finder does not " +"implement :meth:`~importlib.abc.MetaPathFinder.find_spec`." msgstr "" -"元路徑尋檢器的 :meth:`~importlib.abc.MetaPathFinder.find_spec` 方法取代了 :" -"meth:`!find_module`,後者現在已被棄用。雖然它將繼續正常工作,但引入機制僅在尋" -"檢器未實作 :meth:`~importlib.abc.MetaPathFinder.find_spec` 時才會嘗試使用它。" +"元路徑尋檢器的 :meth:`~importlib.abc.MetaPathFinder.find_spec` 方法取代" +"了 :meth:`!find_module`,後者現在已被棄用。雖然它將繼續正常工作,但引入機制僅" +"在尋檢器未實作 :meth:`~importlib.abc.MetaPathFinder.find_spec` 時才會嘗試使用" +"它。" #: ../../reference/import.rst:334 msgid "" -"Use of :meth:`!find_module` by the import system now raises :exc:" -"`ImportWarning`." +"Use of :meth:`!find_module` by the import system now " +"raises :exc:`ImportWarning`." msgstr "引入系統現在使用 :meth:`!find_module` 時將引發 :exc:`ImportWarning`。" #: ../../reference/import.rst:338 msgid "" -":meth:`!find_module` has been removed. Use :meth:`~importlib.abc." -"MetaPathFinder.find_spec` instead." +":meth:`!find_module` has been removed. " +"Use :meth:`~importlib.abc.MetaPathFinder.find_spec` instead." msgstr "" -":meth:`!find_module` 已被移除。請改用 :meth:`~importlib.abc.MetaPathFinder." -"find_spec`。" +":meth:`!find_module` 已被移除。請改" +"用 :meth:`~importlib.abc.MetaPathFinder.find_spec`。" #: ../../reference/import.rst:344 msgid "Loading" @@ -676,8 +682,8 @@ msgstr "請注意下列細節:" #: ../../reference/import.rst:381 msgid "" -"If there is an existing module object with the given name in :data:`sys." -"modules`, import will have already returned it." +"If there is an existing module object with the given name " +"in :data:`sys.modules`, import will have already returned it." msgstr "" "如果 :data:`sys.modules` 中已存在具有給定名稱的模組物件,引入會已回傳該物件。" @@ -696,10 +702,10 @@ msgstr "" #: ../../reference/import.rst:390 msgid "" "If loading fails, the failing module -- and only the failing module -- gets " -"removed from :data:`sys.modules`. Any module already in the :data:`sys." -"modules` cache, and any module that was successfully loaded as a side-" -"effect, must remain in the cache. This contrasts with reloading where even " -"the failing module is left in :data:`sys.modules`." +"removed from :data:`sys.modules`. Any module already in " +"the :data:`sys.modules` cache, and any module that was successfully loaded " +"as a side-effect, must remain in the cache. This contrasts with reloading " +"where even the failing module is left in :data:`sys.modules`." msgstr "" "如果載入失敗,只有載入失敗的模組會從 :data:`sys.modules` 中刪除。任何已存在" "於 :data:`sys.modules` 快取中的模組,以及任何在載入失敗前成功載入的模組,都必" @@ -737,11 +743,11 @@ msgstr "" #: ../../reference/import.rst:408 msgid "" "The import system has taken over the boilerplate responsibilities of " -"loaders. These were previously performed by the :meth:`importlib.abc.Loader." -"load_module` method." +"loaders. These were previously performed by " +"the :meth:`importlib.abc.Loader.load_module` method." msgstr "" -"引入系統已接管載入器的模板 (boilerplate) 責任。之前是由 :meth:`importlib.abc." -"Loader.load_module` 方法執行的。" +"引入系統已接管載入器的模板 (boilerplate) 責任。之前是" +"由 :meth:`importlib.abc.Loader.load_module` 方法執行的。" #: ../../reference/import.rst:414 msgid "Loaders" @@ -755,8 +761,8 @@ msgid "" "returned from :meth:`~importlib.abc.Loader.exec_module` is ignored." msgstr "" "模組載入器提供了載入的關鍵功能:模組執行。引入機制會以單一引數(即要執行的模" -"組物件)呼叫 :meth:`importlib.abc.Loader.exec_module` 方法。任何從 :meth:" -"`~importlib.abc.Loader.exec_module` 回傳的值都會被忽略。" +"組物件)呼叫 :meth:`importlib.abc.Loader.exec_module` 方法。任何" +"從 :meth:`~importlib.abc.Loader.exec_module` 回傳的值都會被忽略。" #: ../../reference/import.rst:421 msgid "Loaders must satisfy the following requirements:" @@ -773,12 +779,12 @@ msgstr "" #: ../../reference/import.rst:427 msgid "" -"If the loader cannot execute the module, it should raise an :exc:" -"`ImportError`, although any other exception raised during :meth:`~importlib." -"abc.Loader.exec_module` will be propagated." +"If the loader cannot execute the module, it should raise " +"an :exc:`ImportError`, although any other exception raised " +"during :meth:`~importlib.abc.Loader.exec_module` will be propagated." msgstr "" -"如果載入器無法執行該模組,應引發 :exc:`ImportError`。不過,在 :meth:" -"`~importlib.abc.Loader.exec_module` 中引發的任何其他例外也會被傳播。" +"如果載入器無法執行該模組,應引發 :exc:`ImportError`。不過," +"在 :meth:`~importlib.abc.Loader.exec_module` 中引發的任何其他例外也會被傳播。" #: ../../reference/import.rst:431 msgid "" @@ -786,9 +792,9 @@ msgid "" "the :meth:`~importlib.abc.MetaPathFinder.find_spec` method would just return " "a spec with the loader set to ``self``." msgstr "" -"在許多情況下,尋檢器和載入器可以是同一個物件;在這種情況下,:meth:" -"`~importlib.abc.MetaPathFinder.find_spec` 方法只需回傳一個載入器設為 " -"``self`` 的規格即可。" +"在許多情況下,尋檢器和載入器可以是同一個物件;在這種情況" +"下,:meth:`~importlib.abc.MetaPathFinder.find_spec` 方法只需回傳一個載入器設" +"為 ``self`` 的規格即可。" #: ../../reference/import.rst:435 msgid "" @@ -810,12 +816,13 @@ msgstr "載入器的 :meth:`~importlib.abc.Loader.create_module` 方法。" #: ../../reference/import.rst:445 msgid "" -"The :meth:`~importlib.abc.Loader.load_module` method was replaced by :meth:" -"`~importlib.abc.Loader.exec_module` and the import machinery assumed all the " -"boilerplate responsibilities of loading." +"The :meth:`~importlib.abc.Loader.load_module` method was replaced " +"by :meth:`~importlib.abc.Loader.exec_module` and the import machinery " +"assumed all the boilerplate responsibilities of loading." msgstr "" -":meth:`~importlib.abc.Loader.load_module` 方法已被 :meth:`~importlib.abc." -"Loader.exec_module` 取代,引入機制已承擔所有載入的模板責任。" +":meth:`~importlib.abc.Loader.load_module` 方法已" +"被 :meth:`~importlib.abc.Loader.exec_module` 取代,引入機制已承擔所有載入的模" +"板責任。" #: ../../reference/import.rst:450 msgid "" @@ -839,16 +846,16 @@ msgstr "" #: ../../reference/import.rst:459 msgid "" -"If there is an existing module object with the given name in :data:`sys." -"modules`, the loader must use that existing module. (Otherwise, :func:" -"`importlib.reload` will not work correctly.) If the named module does not " -"exist in :data:`sys.modules`, the loader must create a new module object and " -"add it to :data:`sys.modules`." +"If there is an existing module object with the given name " +"in :data:`sys.modules`, the loader must use that existing module. " +"(Otherwise, :func:`importlib.reload` will not work correctly.) If the named " +"module does not exist in :data:`sys.modules`, the loader must create a new " +"module object and add it to :data:`sys.modules`." msgstr "" "如果 :data:`sys.modules` 中已存在具有給定名稱的模組物件,載入器必須使用該模組" -"(否則 :func:`importlib.reload` 將無法正常運作)。如果命名模組不存在於 :data:" -"`sys.modules` 中,載入器必須建立一個新的模組物件並將其新增至 :data:`sys." -"modules`。" +"(否則 :func:`importlib.reload` 將無法正常運作)。如果命名模組不存在" +"於 :data:`sys.modules` 中,載入器必須建立一個新的模組物件並將其新增" +"至 :data:`sys.modules`。" #: ../../reference/import.rst:465 msgid "" @@ -860,9 +867,9 @@ msgstr "" #: ../../reference/import.rst:469 msgid "" -"If loading fails, the loader must remove any modules it has inserted into :" -"data:`sys.modules`, but it must remove **only** the failing module(s), and " -"only if the loader itself has loaded the module(s) explicitly." +"If loading fails, the loader must remove any modules it has inserted " +"into :data:`sys.modules`, but it must remove **only** the failing module(s), " +"and only if the loader itself has loaded the module(s) explicitly." msgstr "" "如果載入失敗,載入器必須移除已經插入到 :data:`sys.modules` 中的任何模組,但" "\\ **只能**\\ 移除失敗的模組(們),且僅在載入器本身明確載入這些模組時才需移" @@ -873,16 +880,16 @@ msgid "" "A :exc:`DeprecationWarning` is raised when ``exec_module()`` is defined but " "``create_module()`` is not." msgstr "" -"當 ``exec_module()`` 已定義但未定義 ``create_module()`` 時,將引發 :exc:" -"`DeprecationWarning`。" +"當 ``exec_module()`` 已定義但未定義 ``create_module()`` 時,將引" +"發 :exc:`DeprecationWarning`。" #: ../../reference/import.rst:478 msgid "" "An :exc:`ImportError` is raised when ``exec_module()`` is defined but " "``create_module()`` is not." msgstr "" -"當 ``exec_module()`` 已定義但未定義 ``create_module()`` 時,將引發 :exc:" -"`ImportError`。" +"當 ``exec_module()`` 已定義但未定義 ``create_module()`` 時,將引" +"發 :exc:`ImportError`。" #: ../../reference/import.rst:482 msgid "Use of ``load_module()`` will raise :exc:`ImportWarning`." @@ -903,9 +910,9 @@ msgid "" msgstr "" "當使用任何機制(例如 ``importlib`` APIs、``import`` 或 ``import-from`` 陳述" "式,或內建的 ``__import__()``\\ )載入子模組時,會將子模組物件繫結到父模組的" -"命名空間中。例如,如果套件 ``spam`` 有一個子模組 ``foo``,則在引入 ``spam." -"foo`` 之後,``spam`` 將擁有一個名為 ``foo`` 的屬性,該屬性繫結到子模組。我們" -"假設你有以下的目錄結構: ::" +"命名空間中。例如,如果套件 ``spam`` 有一個子模組 ``foo``,則在引入 " +"``spam.foo`` 之後,``spam`` 將擁有一個名為 ``foo`` 的屬性,該屬性繫結到子模" +"組。我們假設你有以下的目錄結構: ::" #: ../../reference/import.rst:495 msgid "" @@ -950,13 +957,13 @@ msgstr "" msgid "" "Given Python's familiar name binding rules this might seem surprising, but " "it's actually a fundamental feature of the import system. The invariant " -"holding is that if you have ``sys.modules['spam']`` and ``sys.modules['spam." -"foo']`` (as you would after the above import), the latter must appear as the " -"``foo`` attribute of the former." +"holding is that if you have ``sys.modules['spam']`` and " +"``sys.modules['spam.foo']`` (as you would after the above import), the " +"latter must appear as the ``foo`` attribute of the former." msgstr "" "鑑於 Python 相似的名稱繫結規則,這可能看起來有些出人意料,但這實際上是引入系" -"統的一個基本特性。不變的是如果你擁有 ``sys.modules['spam']`` 和 ``sys." -"modules['spam.foo']``\\ (就像上述引入後那樣),那麼後者必須作為前者的 " +"統的一個基本特性。不變的是如果你擁有 ``sys.modules['spam']`` 和 " +"``sys.modules['spam.foo']``\\ (就像上述引入後那樣),那麼後者必須作為前者的 " "``foo`` 屬性出現。" #: ../../reference/import.rst:521 @@ -990,8 +997,8 @@ msgstr "" msgid "" "The module's spec is exposed as :attr:`module.__spec__`. Setting :attr:`!" "__spec__` appropriately applies equally to :ref:`modules initialized during " -"interpreter startup `. The one exception is ``__main__``, where :" -"attr:`!__spec__` is :ref:`set to None in some cases `." +"interpreter startup `. The one exception is ``__main__``, " +"where :attr:`!__spec__` is :ref:`set to None in some cases `." msgstr "" "模組的規格以 :attr:`module.__spec__` 的形式公開。適當地設定 :attr:`!" "__spec__` 同樣適用於\\ :ref:`在直譯器啟動期間初始化的模組 `。唯一的" @@ -1007,24 +1014,30 @@ msgstr "" #: ../../reference/import.rst:548 msgid "__path__ attributes on modules" -msgstr "" +msgstr "模組上的 __path__ 屬性" #: ../../reference/import.rst:550 msgid "" -"The :attr:`~module.__path__` attribute should be a (possibly empty) :term:" -"`sequence` of strings enumerating the locations where the package's " -"submodules will be found. By definition, if a module has a :attr:`!__path__` " -"attribute, it is a :term:`package`." +"The :attr:`~module.__path__` attribute should be a (possibly " +"empty) :term:`sequence` of strings enumerating the locations where the " +"package's submodules will be found. By definition, if a module has a :attr:`!" +"__path__` attribute, it is a :term:`package`." msgstr "" +":attr:`~module.__path__` 屬性應該是一個(可能為空的)\\ :term:`sequence`,其" +"包含列舉套件子模組位置的字串。根據定義,如果一個模組有 :attr:`!__path__` 屬" +"性,那麼它就是一個 :term:`package`。" #: ../../reference/import.rst:555 msgid "" "A package's :attr:`~module.__path__` attribute is used during imports of its " -"subpackages. Within the import machinery, it functions much the same as :" -"data:`sys.path`, i.e. providing a list of locations to search for modules " -"during import. However, :attr:`!__path__` is typically much more constrained " -"than :data:`!sys.path`." +"subpackages. Within the import machinery, it functions much the same " +"as :data:`sys.path`, i.e. providing a list of locations to search for " +"modules during import. However, :attr:`!__path__` is typically much more " +"constrained than :data:`!sys.path`." msgstr "" +"套件的 :attr:`~module.__path__` 屬性在引入其子套件時被使用。在引入機制中,其" +"功能與 :data:`sys.path` 類似,即提供在引入期間搜尋模組的位置串列。然" +"而,:attr:`!__path__` 通常比 :data:`!sys.path` 更受限制。" #: ../../reference/import.rst:562 msgid "" @@ -1032,20 +1045,29 @@ msgid "" "__path__`. :data:`sys.path_hooks` (described below) are consulted when " "traversing a package's :attr:`!__path__`." msgstr "" +":data:`sys.path` 適用的規則同樣也適用於套件的 :attr:`!" +"__path__`。 :data:`sys.path_hooks` 會在遍歷套件的 :attr:`!__path__` 時被參考" +"(於後文詳述)。" #: ../../reference/import.rst:566 msgid "" -"A package's ``__init__.py`` file may set or alter the package's :attr:" -"`~module.__path__` attribute, and this was typically the way namespace " -"packages were implemented prior to :pep:`420`. With the adoption of :pep:" -"`420`, namespace packages no longer need to supply ``__init__.py`` files " -"containing only :attr:`!__path__` manipulation code; the import machinery " -"automatically sets :attr:`!__path__` correctly for the namespace package." +"A package's ``__init__.py`` file may set or alter the " +"package's :attr:`~module.__path__` attribute, and this was typically the way " +"namespace packages were implemented prior to :pep:`420`. With the adoption " +"of :pep:`420`, namespace packages no longer need to supply ``__init__.py`` " +"files containing only :attr:`!__path__` manipulation code; the import " +"machinery automatically sets :attr:`!__path__` correctly for the namespace " +"package." msgstr "" +"套件的 ``__init__.py`` 檔案可以設定或修改套件的 :attr:`~module.__path__` 屬" +"性,這通常是 :pep:`420` 之前實作命名空間套件的方式。隨著 :pep:`420` 的採用," +"命名空間套件不再需要提供僅包含 :attr:`!__path__` 操作程式碼的 " +"``__init__.py`` 檔案;引入機制會自動為命名空間套件正確地設定 :attr:`!" +"__path__`。" #: ../../reference/import.rst:575 msgid "Module reprs" -msgstr "" +msgstr "模組的 reprs" #: ../../reference/import.rst:577 msgid "" @@ -1053,20 +1075,26 @@ msgid "" "attributes set above, and in the module's spec, you can more explicitly " "control the repr of module objects." msgstr "" +"預設情況下,所有模組都有可用的 repr,然而根據上述設定及模組規格中的屬性,你" +"可以更明確地控制模組物件的 repr。" #: ../../reference/import.rst:581 msgid "" "If the module has a spec (``__spec__``), the import machinery will try to " "generate a repr from it. If that fails or there is no spec, the import " "system will craft a default repr using whatever information is available on " -"the module. It will try to use the ``module.__name__``, ``module." -"__file__``, and ``module.__loader__`` as input into the repr, with defaults " -"for whatever information is missing." +"the module. It will try to use the ``module.__name__``, " +"``module.__file__``, and ``module.__loader__`` as input into the repr, with " +"defaults for whatever information is missing." msgstr "" +"如果模組具有規格(``__spec__``),引入機制將嘗試從規格中產生 repr。如果" +"失敗或沒有規格,引入系統將使用模組上可用的資訊製作一個預設的 repr。它會嘗試使" +"用 ``module.__name__``、``module.__file__`` 和 ``module.__loader__`` 作為 " +"repr 的輸入,並為缺少的資訊提供預設值。" #: ../../reference/import.rst:588 msgid "Here are the exact rules used:" -msgstr "" +msgstr "以下是具體的使用規則:" #: ../../reference/import.rst:590 msgid "" @@ -1074,22 +1102,26 @@ msgid "" "used to generate the repr. The \"name\", \"loader\", \"origin\", and " "\"has_location\" attributes are consulted." msgstr "" +"如果模組具有 ``__spec__`` 屬性,則使用規格中的資訊產生 repr。會參考 " +"\"name\"、\"loader\"、\"origin\" 和 \"has_location\" 屬性。" #: ../../reference/import.rst:594 msgid "" "If the module has a ``__file__`` attribute, this is used as part of the " "module's repr." -msgstr "" +msgstr "如果模組具有 ``__file__`` 屬性,則會將其作為模組 repr 的一部分。" #: ../../reference/import.rst:597 msgid "" "If the module has no ``__file__`` but does have a ``__loader__`` that is not " "``None``, then the loader's repr is used as part of the module's repr." msgstr "" +"如果模組沒有 ``__file__`` 但有一個不為 ``None`` 的 ``__loader__`` ,則會將載" +"入器的 repr 作為模組 repr 的一部分。" #: ../../reference/import.rst:600 msgid "Otherwise, just use the module's ``__name__`` in the repr." -msgstr "" +msgstr "否則,在 repr 中只使用模組的 ``__name__``。" #: ../../reference/import.rst:602 msgid "" @@ -1097,10 +1129,12 @@ msgid "" "removed in Python 3.12 and is no longer called during the resolution of a " "module's repr." msgstr "" +":meth:`!module_repr` 自 Python 3.4 起被棄用,並在 Python 3.12 中移除,且不會" +"在解析模組的 repr 時被呼叫。" #: ../../reference/import.rst:610 msgid "Cached bytecode invalidation" -msgstr "" +msgstr "被快取的位元組碼的無效化" #: ../../reference/import.rst:612 msgid "" @@ -1111,39 +1145,57 @@ msgid "" "cache file by checking the stored metadata in the cache file against the " "source's metadata." msgstr "" +"在 Python 從 ``.pyc`` 檔案載入被快取的位元組碼之前,會檢查該快取是否與來源的 " +"``.py`` 檔案保持同步。預設情況下,Python 透過在寫入快取檔案時儲存來源檔案的最" +"後修改時間戳和大小來完成此操作。在 runtime,引入系統會透過將快取檔案中儲存的詮" +"釋資料 (metadata) 與來源檔案的詮釋資料進行比對來驗證快取檔案。" #: ../../reference/import.rst:619 msgid "" "Python also supports \"hash-based\" cache files, which store a hash of the " "source file's contents rather than its metadata. There are two variants of " -"hash-based ``.pyc`` files: checked and unchecked. For checked hash-based ``." -"pyc`` files, Python validates the cache file by hashing the source file and " -"comparing the resulting hash with the hash in the cache file. If a checked " -"hash-based cache file is found to be invalid, Python regenerates it and " -"writes a new checked hash-based cache file. For unchecked hash-based ``." -"pyc`` files, Python simply assumes the cache file is valid if it exists. " -"Hash-based ``.pyc`` files validation behavior may be overridden with the :" -"option:`--check-hash-based-pycs` flag." -msgstr "" +"hash-based ``.pyc`` files: checked and unchecked. For checked hash-based " +"``.pyc`` files, Python validates the cache file by hashing the source file " +"and comparing the resulting hash with the hash in the cache file. If a " +"checked hash-based cache file is found to be invalid, Python regenerates it " +"and writes a new checked hash-based cache file. For unchecked hash-based " +"``.pyc`` files, Python simply assumes the cache file is valid if it exists. " +"Hash-based ``.pyc`` files validation behavior may be overridden with " +"the :option:`--check-hash-based-pycs` flag." +msgstr "" +"Python 還支援「基於雜湊」的快取檔案,這些檔案儲存源頭檔案內容的雜湊值,而不是" +"其詮釋資料。基於雜湊的 ``.pyc`` 檔案有兩種變體:需檢查和不需要檢查的。對於需檢" +"查的基於雜湊的 ``.pyc`` 檔案, Python 會對來源檔案進行雜湊,並將結果與快取檔案" +"中的雜湊進行比較來驗證快取檔案。如果發現需檢查的基於雜湊的快取檔案無效," +"Python 會重新產生並寫入新的需檢查的基於雜湊的快取檔案。對於不需要檢查的基於雜" +"湊的 ``.pyc`` 檔案,只要檔案存在,Python 就假設快取檔案是有效的。可以使" +"用 :option:`--check-hash-based-pycs` 旗標覆蓋基於雜湊的 ``.pyc`` 檔案的驗證行" +"為。" #: ../../reference/import.rst:630 msgid "" "Added hash-based ``.pyc`` files. Previously, Python only supported timestamp-" "based invalidation of bytecode caches." msgstr "" +"新增了基於雜湊的 ``.pyc`` 檔案。此前,Python 只支援基於時間戳的位元組碼快取無" +"效化。" #: ../../reference/import.rst:636 msgid "The Path Based Finder" -msgstr "" +msgstr "基於路徑的尋檢器" #: ../../reference/import.rst:641 msgid "" "As mentioned previously, Python comes with several default meta path " -"finders. One of these, called the :term:`path based finder` (:class:" -"`~importlib.machinery.PathFinder`), searches an :term:`import path`, which " -"contains a list of :term:`path entries `. Each path entry names " -"a location to search for modules." +"finders. One of these, called the :term:`path based finder` " +"(:class:`~importlib.machinery.PathFinder`), searches an :term:`import path`, " +"which contains a list of :term:`path entries `. Each path entry " +"names a location to search for modules." msgstr "" +"如前所述,Python 附帶了幾個預設的元路徑尋檢器。其中之一稱為 :term:`path " +"based finder`\\ (:class:`~importlib.machinery.PathFinder`),它搜" +"尋 :term:`import path`,該路徑包含一個\\ :term:`路徑條目 `\\ 的串列。" +"每個路徑條目都指定了一個用於搜尋模組的位置。" #: ../../reference/import.rst:647 msgid "" @@ -1151,17 +1203,24 @@ msgid "" "it traverses the individual path entries, associating each of them with a " "path entry finder that knows how to handle that particular kind of path." msgstr "" +"基於路徑的尋檢器本身並不知道如何引入任何東西。相反,它遍歷各個路徑條目,並將" +"每個路徑條目與一個知道如何處理該特定路徑類型的路徑條目尋檢器關聯起來。" #: ../../reference/import.rst:651 msgid "" "The default set of path entry finders implement all the semantics for " "finding modules on the file system, handling special file types such as " "Python source code (``.py`` files), Python byte code (``.pyc`` files) and " -"shared libraries (e.g. ``.so`` files). When supported by the :mod:" -"`zipimport` module in the standard library, the default path entry finders " -"also handle loading all of these file types (other than shared libraries) " -"from zipfiles." +"shared libraries (e.g. ``.so`` files). When supported by " +"the :mod:`zipimport` module in the standard library, the default path entry " +"finders also handle loading all of these file types (other than shared " +"libraries) from zipfiles." msgstr "" +"預設的一組路徑條目尋檢器實作了在檔案系統中尋找模組的所有語意,包括處理特殊檔" +"案類型,例如 Python 原始程式碼檔案(``.py`` 檔案)、Python 位元組程式碼檔案" +"(``.pyc`` 檔案)以及共享函式庫(例如 ``.so`` 檔案)。當標準函式庫中" +"的 :mod:`zipimport` 模組支援時,預設的路徑條目尋檢器也能處理從壓縮檔案中載入" +"這些檔案類型(共享函式庫除外)。" #: ../../reference/import.rst:658 msgid "" @@ -1169,6 +1228,8 @@ msgid "" "to URLs, database queries, or any other location that can be specified as a " "string." msgstr "" +"路徑條目不必侷限於檔案系統位置。它們可以參照 URL、資料庫查詢或任何可以作為字" +"串指定的位置。" #: ../../reference/import.rst:662 msgid "" @@ -1180,17 +1241,26 @@ msgid "" "protocol described below, which was then used to get a loader for the module " "from the web." msgstr "" +"基於路徑的尋檢器提供了額外的掛鉤和協定,讓你可以擴展和自訂可搜尋的路徑條目類" +"型。例如,如果你希望支援將路徑條目作為網路 URLs,你可以撰寫一個實作 HTTP 語意" +"的掛鉤,用於在網路上尋找模組。這個掛鉤(一個可呼叫物件)會回傳一個支援下述協" +"定的 :term:`path entry finder` ,該尋檢器隨後用於從網路中取得模組的載入器。" #: ../../reference/import.rst:670 msgid "" "A word of warning: this section and the previous both use the term *finder*, " -"distinguishing between them by using the terms :term:`meta path finder` and :" -"term:`path entry finder`. These two types of finders are very similar, " +"distinguishing between them by using the terms :term:`meta path finder` " +"and :term:`path entry finder`. These two types of finders are very similar, " "support similar protocols, and function in similar ways during the import " "process, but it's important to keep in mind that they are subtly different. " "In particular, meta path finders operate at the beginning of the import " "process, as keyed off the :data:`sys.meta_path` traversal." msgstr "" +"提醒一句:本節與前一節都使用了 *尋檢器* 這個術語,並透過使用術語 :term:`meta " +"path finder` 和 :term:`path entry finder` 來區分它們。這兩種類型的尋檢器非常" +"相似,它們支援類似的協定,並在引入過程中以類似的方式運作,但請記住,它們之間仍有些" +"許的差異。尤其元路徑尋檢器會在引入過程開始時運作,並通" +"過 :data:`sys.meta_path` 的遍歷關閉 (key off)。" #: ../../reference/import.rst:678 msgid "" @@ -1199,10 +1269,13 @@ msgid "" "removed from :data:`sys.meta_path`, none of the path entry finder semantics " "would be invoked." msgstr "" +"相比之下,路徑條目尋檢器在某種意義上是基於路徑的尋檢器的一個實作細節。事實" +"上,如果基於路徑的尋檢器從 :data:`sys.meta_path` 中移除,路徑條目尋檢器的任何" +"語意都不會被叫用。" #: ../../reference/import.rst:685 msgid "Path entry finders" -msgstr "" +msgstr "路徑條目尋檢器" #: ../../reference/import.rst:693 msgid "" @@ -1211,22 +1284,32 @@ msgid "" "entry`. Most path entries name locations in the file system, but they need " "not be limited to this." msgstr "" +":term:`path based finder` 負責尋找並載入其位置以字串 :term:`path entry` 指定" +"的 Python 模組與套件。大多數路徑條目指向檔案系統中的位置,但不必侷限於此。" #: ../../reference/import.rst:698 msgid "" -"As a meta path finder, the :term:`path based finder` implements the :meth:" -"`~importlib.abc.MetaPathFinder.find_spec` protocol previously described, " -"however it exposes additional hooks that can be used to customize how " -"modules are found and loaded from the :term:`import path`." +"As a meta path finder, the :term:`path based finder` implements " +"the :meth:`~importlib.abc.MetaPathFinder.find_spec` protocol previously " +"described, however it exposes additional hooks that can be used to customize " +"how modules are found and loaded from the :term:`import path`." msgstr "" +"作為元路徑尋檢器,:term:`path based finder` 實作了先前描述" +"的 :meth:`~importlib.abc.MetaPathFinder.find_spec` 協定,但它另外提供了可用來" +"自訂模組如何從 :term:`import path` 被找到並載入的掛鉤。" #: ../../reference/import.rst:703 msgid "" -"Three variables are used by the :term:`path based finder`, :data:`sys." -"path`, :data:`sys.path_hooks` and :data:`sys.path_importer_cache`. The " -"``__path__`` attributes on package objects are also used. These provide " -"additional ways that the import machinery can be customized." +"Three variables are used by the :term:`path based " +"finder`, :data:`sys.path`, :data:`sys.path_hooks` " +"and :data:`sys.path_importer_cache`. The ``__path__`` attributes on package " +"objects are also used. These provide additional ways that the import " +"machinery can be customized." msgstr "" +":term:`path based finder` 會使用三個變" +"數::data:`sys.path`、:data:`sys.path_hooks` " +"和 :data:`sys.path_importer_cache`。套件物件上的 ``__path__`` 屬性也會被使" +"用。這些提供了額外的方法來自訂引入機制。" #: ../../reference/import.rst:708 msgid "" @@ -1234,65 +1317,100 @@ msgid "" "modules and packages. It is initialized from the :envvar:`PYTHONPATH` " "environment variable and various other installation- and implementation-" "specific defaults. Entries in :data:`sys.path` can name directories on the " -"file system, zip files, and potentially other \"locations\" (see the :mod:" -"`site` module) that should be searched for modules, such as URLs, or " -"database queries. Only strings should be present on :data:`sys.path`; all " -"other data types are ignored." +"file system, zip files, and potentially other \"locations\" (see " +"the :mod:`site` module) that should be searched for modules, such as URLs, " +"or database queries. Only strings should be present on :data:`sys.path`; " +"all other data types are ignored." msgstr "" +":data:`sys.path` 包含一個字串的 list,用來提供模組與套件的搜尋位置。它會" +"從 :envvar:`PYTHONPATH` 環境變數,以及各種安裝與實作相關的預設值初始" +"化。:data:`sys.path` 中的條目可以指定檔案系統上的目錄、zip 檔案,或其他可能需" +"要搜尋模組的「位置」(參閱 :mod:`site` 模組),例如 URL 或資料庫查" +"詢。:data:`sys.path` 中只能包含字串;其他資料型別都會被忽略。" #: ../../reference/import.rst:717 msgid "" "The :term:`path based finder` is a :term:`meta path finder`, so the import " "machinery begins the :term:`import path` search by calling the path based " "finder's :meth:`~importlib.machinery.PathFinder.find_spec` method as " -"described previously. When the ``path`` argument to :meth:`~importlib." -"machinery.PathFinder.find_spec` is given, it will be a list of string paths " -"to traverse - typically a package's ``__path__`` attribute for an import " -"within that package. If the ``path`` argument is ``None``, this indicates a " -"top level import and :data:`sys.path` is used." -msgstr "" +"described previously. When the ``path`` argument " +"to :meth:`~importlib.machinery.PathFinder.find_spec` is given, it will be a " +"list of string paths to traverse - typically a package's ``__path__`` " +"attribute for an import within that package. If the ``path`` argument is " +"``None``, this indicates a top level import and :data:`sys.path` is used." +msgstr "" +":term:`path based finder` 也是一種 :term:`meta path finder`,因此引入機制會如前所" +"述般透過呼叫基於路徑的尋檢器" +"的 :meth:`~importlib.machinery.PathFinder.find_spec` 方法來開" +"始 :term:`import path` 的搜尋。當有提" +"供 :meth:`~importlib.machinery.PathFinder.find_spec` 的 ``path`` 引數時,它會" +"是一個要遍歷的字串路徑 list——通常是在套件內引入時使用該套件的 ``__path__`` 屬" +"性。如果 ``path`` 引數為 ``None``,則表示為頂層引入並使用 :data:`sys.path`。" #: ../../reference/import.rst:726 msgid "" "The path based finder iterates over every entry in the search path, and for " -"each of these, looks for an appropriate :term:`path entry finder` (:class:" -"`~importlib.abc.PathEntryFinder`) for the path entry. Because this can be " -"an expensive operation (e.g. there may be ``stat()`` call overheads for this " -"search), the path based finder maintains a cache mapping path entries to " -"path entry finders. This cache is maintained in :data:`sys." -"path_importer_cache` (despite the name, this cache actually stores finder " -"objects rather than being limited to :term:`importer` objects). In this way, " -"the expensive search for a particular :term:`path entry` location's :term:" -"`path entry finder` need only be done once. User code is free to remove " -"cache entries from :data:`sys.path_importer_cache` forcing the path based " -"finder to perform the path entry search again." -msgstr "" +"each of these, looks for an appropriate :term:`path entry finder` " +"(:class:`~importlib.abc.PathEntryFinder`) for the path entry. Because this " +"can be an expensive operation (e.g. there may be ``stat()`` call overheads " +"for this search), the path based finder maintains a cache mapping path " +"entries to path entry finders. This cache is maintained " +"in :data:`sys.path_importer_cache` (despite the name, this cache actually " +"stores finder objects rather than being limited to :term:`importer` " +"objects). In this way, the expensive search for a particular :term:`path " +"entry` location's :term:`path entry finder` need only be done once. User " +"code is free to remove cache entries from :data:`sys.path_importer_cache` " +"forcing the path based finder to perform the path entry search again." +msgstr "" +"基於路徑的尋檢器會遍歷搜尋路徑中的每個條目,並為每個條目尋找適當" +"的 :term:`path entry finder` (:class:`~importlib.abc.PathEntryFinder`)。由於" +"這可能是代價高昂的操作(例如此搜尋可能會有 ``stat()`` 呼叫的額外開銷),基於路徑" +"的尋檢器會維護一個將路徑條目對映到路徑條目尋檢器的快取。此快取存放" +"於 :data:`sys.path_importer_cache`\\(儘管名稱如此,該快取實際上儲存的是尋檢" +"器物件,而非僅限於 :term:`importer` 物件)。如此一來,針對特定 :term:`path " +"entry` 位置的 :term:`path entry finder` 的高代價搜尋只需進行一次。使用者程式碼" +"可以移除 :data:`sys.path_importer_cache` 中的快取條目,以強制基於路徑的尋檢器" +"再次執行路徑條目搜尋。" #: ../../reference/import.rst:739 msgid "" "If the path entry is not present in the cache, the path based finder " -"iterates over every callable in :data:`sys.path_hooks`. Each of the :term:" -"`path entry hooks ` in this list is called with a single " -"argument, the path entry to be searched. This callable may either return a :" -"term:`path entry finder` that can handle the path entry, or it may raise :" -"exc:`ImportError`. An :exc:`ImportError` is used by the path based finder " -"to signal that the hook cannot find a :term:`path entry finder` for that :" -"term:`path entry`. The exception is ignored and :term:`import path` " +"iterates over every callable in :data:`sys.path_hooks`. Each of " +"the :term:`path entry hooks ` in this list is called with a " +"single argument, the path entry to be searched. This callable may either " +"return a :term:`path entry finder` that can handle the path entry, or it may " +"raise :exc:`ImportError`. An :exc:`ImportError` is used by the path based " +"finder to signal that the hook cannot find a :term:`path entry finder` for " +"that :term:`path entry`. The exception is ignored and :term:`import path` " "iteration continues. The hook should expect either a string or bytes " "object; the encoding of bytes objects is up to the hook (e.g. it may be a " "file system encoding, UTF-8, or something else), and if the hook cannot " "decode the argument, it should raise :exc:`ImportError`." msgstr "" +"如果該路徑條目不在快取中,基於路徑的尋檢器會遍歷 :data:`sys.path_hooks` 中的" +"每個可呼叫物件。此 list 中的每個 :term:`路徑條目掛鉤 ` 都會" +"以單一引數被呼叫,即要搜尋的路徑條目。這個可呼叫物件可以回傳一個能處理該路徑" +"條目的 :term:`path entry finder`,也可以引發 :exc:`ImportError`。基於路徑的尋" +"檢器會使用 :exc:`ImportError` 來表示該掛鉤無法為該 :term:`path entry` 找" +"到 :term:`path entry finder`。此例外會被忽略,並繼續疊代 :term:`import " +"path`。該掛鉤應預期接收字串或 bytes 物件;bytes 物件的編碼由掛鉤決定(例如檔" +"案系統編碼、UTF-8 或其他),若掛鉤無法解碼該引數,則應引" +"發 :exc:`ImportError`。" #: ../../reference/import.rst:753 msgid "" "If :data:`sys.path_hooks` iteration ends with no :term:`path entry finder` " -"being returned, then the path based finder's :meth:`~importlib.machinery." -"PathFinder.find_spec` method will store ``None`` in :data:`sys." -"path_importer_cache` (to indicate that there is no finder for this path " -"entry) and return ``None``, indicating that this :term:`meta path finder` " -"could not find the module." -msgstr "" +"being returned, then the path based " +"finder's :meth:`~importlib.machinery.PathFinder.find_spec` method will store " +"``None`` in :data:`sys.path_importer_cache` (to indicate that there is no " +"finder for this path entry) and return ``None``, indicating that " +"this :term:`meta path finder` could not find the module." +msgstr "" +"若 :data:`sys.path_hooks` 的疊代結束後仍未回傳任何 :term:`path entry " +"finder`,則基於路徑的尋檢器" +"的 :meth:`~importlib.machinery.PathFinder.find_spec` 方法會" +"在 :data:`sys.path_importer_cache` 中存入 ``None``\\(表示此路徑條目沒有尋檢" +"器),並回傳 ``None``,表示此 :term:`meta path finder` 無法找到該模組。" #: ../../reference/import.rst:760 msgid "" @@ -1301,6 +1419,9 @@ msgid "" "used to ask the finder for a module spec, which is then used when loading " "the module." msgstr "" +"若 :data:`sys.path_hooks` 上的某個 :term:`路徑條目掛鉤 ` 可" +"呼叫物件 *確實* 回傳了 :term:`path entry finder`,則會使用以下協定向該尋檢器" +"要求模組規格,並在載入模組時使用該規格。" #: ../../reference/import.rst:765 msgid "" @@ -1313,10 +1434,16 @@ msgid "" "meth:`importlib.machinery.PathFinder.find_spec` will be the actual current " "working directory and not the empty string." msgstr "" +"目前工作目錄——以空字串表示——的處理方式與 :data:`sys.path`" +" 上其他條目略有不同。第一,如果目前工作目錄無法判定或被發現不存在,便不會在" +" :data:`sys.path_importer_cache` 中儲存任何值。第二,對於每次模組查找,都會" +"重新查詢目前工作目錄的值。第三,供 :data:`sys.path_importer_cache` 使用並由" +" :meth:`importlib.machinery.PathFinder.find_spec` 回傳的路徑會是實際的目前工" +"作目錄,而不是空字串。" #: ../../reference/import.rst:775 msgid "Path entry finder protocol" -msgstr "" +msgstr "路徑條目尋檢器協定" #: ../../reference/import.rst:777 msgid "" @@ -1324,6 +1451,8 @@ msgid "" "contribute portions to namespace packages, path entry finders must implement " "the :meth:`~importlib.abc.PathEntryFinder.find_spec` method." msgstr "" +"為了支援模組與已初始化套件的引入,並能為命名空間套件提供部分組成,路徑條目尋檢器" +"必須實作 :meth:`~importlib.abc.PathEntryFinder.find_spec` 方法。" #: ../../reference/import.rst:781 msgid "" @@ -1332,13 +1461,18 @@ msgid "" "module. ``find_spec()`` returns a fully populated spec for the module. This " "spec will always have \"loader\" set (with one exception)." msgstr "" +":meth:`~importlib.abc.PathEntryFinder.find_spec` 會接收兩個引數:正在引入的模" +"組之完整限定名稱,以及(可選的)目標模組。``find_spec()`` 會回傳一個完整填入" +"的模組規格。此規格會一律設定 \"loader\"(只有一個例外)。" #: ../../reference/import.rst:786 msgid "" -"To indicate to the import machinery that the spec represents a namespace :" -"term:`portion`, the path entry finder sets ``submodule_search_locations`` to " -"a list containing the portion." +"To indicate to the import machinery that the spec represents a " +"namespace :term:`portion`, the path entry finder sets " +"``submodule_search_locations`` to a list containing the portion." msgstr "" +"為了向引入機制表明該規格代表一個命名空間 :term:`portion`,路徑條目尋檢器會將 " +"``submodule_search_locations`` 設為包含該部分的 list。" #: ../../reference/import.rst:790 msgid "" @@ -1346,6 +1480,9 @@ msgid "" "find_loader` and :meth:`!find_module`, both of which are now deprecated, but " "will be used if ``find_spec()`` is not defined." msgstr "" +":meth:`~importlib.abc.PathEntryFinder.find_spec` 已取代 :meth:`!find_loader` " +"與 :meth:`!find_module`,兩者現已棄用,但若未定義 ``find_spec()`` 仍會被使" +"用。" #: ../../reference/import.rst:796 msgid "" @@ -1354,6 +1491,9 @@ msgid "" "backward compatibility. However, if ``find_spec()`` is implemented on the " "path entry finder, the legacy methods are ignored." msgstr "" +"較舊的路徑條目尋檢器可能會實作這兩個已棄用的方法之一,而不是 " +"``find_spec()``。為了向後相容,這些方法仍會被尊重。然而,如果路徑條目尋檢器實" +"作了 ``find_spec()``,這些舊方法就會被忽略。" #: ../../reference/import.rst:801 msgid "" @@ -1361,6 +1501,9 @@ msgid "" "module being imported. ``find_loader()`` returns a 2-tuple where the first " "item is the loader and the second item is a namespace :term:`portion`." msgstr "" +":meth:`!find_loader` 接收一個引數,即正在引入的模組之完整限定名稱。" +"``find_loader()`` 會回傳一個 2-tuple,其中第一個項目是 loader,第二個項目是命" +"名空間 :term:`portion`。" #: ../../reference/import.rst:806 msgid "" @@ -1371,6 +1514,10 @@ msgid "" "(they are expected to record the appropriate path information from the " "initial call to the path hook)." msgstr "" +"為了與其他引入協定的實作向後相容,許多路徑條目尋檢器也支援元路徑尋檢器所支援" +"的相同、傳統的 ``find_module()`` 方法。然而,路徑條目尋檢器的 " +"``find_module()`` 方法永遠不會帶著 ``path`` 引數被呼叫(它們預期會從對路徑條" +"目掛鉤的初始呼叫中記錄適當的路徑資訊)。" #: ../../reference/import.rst:813 msgid "" @@ -1380,12 +1527,17 @@ msgid "" "entry finder, the import system will always call ``find_loader()`` in " "preference to ``find_module()``." msgstr "" +"路徑條目尋檢器上的 ``find_module()`` 方法已被棄用,因為它不允許路徑條目尋檢器" +"為命名空間套件只提供部分組成。若路徑條目尋檢器同時存在 ``find_loader()`` 與 " +"``find_module()``,引入系統會一律優先呼叫 ``find_loader()``。" #: ../../reference/import.rst:819 msgid "" "Calls to :meth:`!find_module` and :meth:`!find_loader` by the import system " "will raise :exc:`ImportWarning`." msgstr "" +"引入系統對 :meth:`!find_module` 與 :meth:`!find_loader` 的呼叫將會引" +"發 :exc:`ImportWarning`。" #: ../../reference/import.rst:824 msgid "``find_module()`` and ``find_loader()`` have been removed." @@ -1393,7 +1545,7 @@ msgstr "``find_module()`` 和 ``find_loader()`` 已被移除。" #: ../../reference/import.rst:829 msgid "Replacing the standard import system" -msgstr "" +msgstr "取代標準引入系統" #: ../../reference/import.rst:831 msgid "" @@ -1401,6 +1553,8 @@ msgid "" "delete the default contents of :data:`sys.meta_path`, replacing them " "entirely with a custom meta path hook." msgstr "" +"取代整個引入系統最可靠的機制是刪除 :data:`sys.meta_path` 的預設內容,並以自訂" +"的元路徑掛鉤完全取代它們。" #: ../../reference/import.rst:835 msgid "" @@ -1408,20 +1562,26 @@ msgid "" "affecting other APIs that access the import system, then replacing the " "builtin :func:`__import__` function may be sufficient." msgstr "" +"如果可以只改變 import 陳述式的行為,而不影響其他存取引入系統的 API,那麼替換" +"內建的 :func:`__import__` 函式可能就足夠了。" #: ../../reference/import.rst:839 msgid "" "To selectively prevent the import of some modules from a hook early on the " "meta path (rather than disabling the standard import system entirely), it is " -"sufficient to raise :exc:`ModuleNotFoundError` directly from :meth:" -"`~importlib.abc.MetaPathFinder.find_spec` instead of returning ``None``. The " -"latter indicates that the meta path search should continue, while raising an " -"exception terminates it immediately." +"sufficient to raise :exc:`ModuleNotFoundError` directly " +"from :meth:`~importlib.abc.MetaPathFinder.find_spec` instead of returning " +"``None``. The latter indicates that the meta path search should continue, " +"while raising an exception terminates it immediately." msgstr "" +"若要從元路徑較早處的掛鉤選擇性地阻止某些模組被引入(而不是完全停用標準引入系" +"統),只要在 :meth:`~importlib.abc.MetaPathFinder.find_spec` 直接引" +"發 :exc:`ModuleNotFoundError`,而不是回傳 ``None`` 即可。後者表示元路徑搜尋應" +"繼續,而引發例外則會立即終止。" #: ../../reference/import.rst:849 msgid "Package Relative Imports" -msgstr "" +msgstr "套件相對引入" #: ../../reference/import.rst:851 msgid "" @@ -1430,6 +1590,9 @@ msgid "" "a relative import to the parent(s) of the current package, one level per dot " "after the first. For example, given the following package layout::" msgstr "" +"相對引入使用前導點號。一個前導點號表示從目前套件開始的相對引入。兩個或更多前" +"導點號表示相對引入到目前套件的父層,第一個之後每多一個點號就往上一層。例如," +"給定以下套件配置: ::" #: ../../reference/import.rst:856 msgid "" @@ -1460,6 +1623,8 @@ msgid "" "In either ``subpackage1/moduleX.py`` or ``subpackage1/__init__.py``, the " "following are valid relative imports::" msgstr "" +"在 ``subpackage1/moduleX.py`` 或 ``subpackage1/__init__.py`` 中,以下皆為有效" +"的相對引入: ::" #: ../../reference/import.rst:870 msgid "" @@ -1483,6 +1648,8 @@ msgid "" "syntax, but relative imports may only use the second form; the reason for " "this is that::" msgstr "" +"絕對引入可以使用 ``import <>`` 或 ``from <> import <>`` 語法,但相對引入只能" +"使用第二種形式;原因是: ::" #: ../../reference/import.rst:881 msgid "import XXX.YYY.ZZZ" @@ -1493,21 +1660,27 @@ msgid "" "should expose ``XXX.YYY.ZZZ`` as a usable expression, but .moduleY is not a " "valid expression." msgstr "" +"應該要將 ``XXX.YYY.ZZZ`` 作為可用的運算式公開,但 .moduleY 不是有效的運算式。" #: ../../reference/import.rst:890 msgid "Special considerations for __main__" -msgstr "" +msgstr "__main__ 的特殊考量" #: ../../reference/import.rst:892 msgid "" "The :mod:`__main__` module is a special case relative to Python's import " "system. As noted :ref:`elsewhere `, the ``__main__`` module is " -"directly initialized at interpreter startup, much like :mod:`sys` and :mod:" -"`builtins`. However, unlike those two, it doesn't strictly qualify as a " -"built-in module. This is because the manner in which ``__main__`` is " +"directly initialized at interpreter startup, much like :mod:`sys` " +"and :mod:`builtins`. However, unlike those two, it doesn't strictly qualify " +"as a built-in module. This is because the manner in which ``__main__`` is " "initialized depends on the flags and other options with which the " "interpreter is invoked." msgstr "" +":mod:`__main__` 模組相對於 Python 的引入系統而言是一個特殊案例。" +"如 :ref:`elsewhere ` 所述,``__main__`` 模組會在直譯器啟動時直接初" +"始化,類似於 :mod:`sys` 與 :mod:`builtins`。然而,與那兩者不同,它並不嚴格算" +"是內建模組。這是因為 ``__main__`` 的初始化方式取決於呼叫直譯器時使用的旗標與" +"其他選項。" #: ../../reference/import.rst:903 msgid "__main__.__spec__" @@ -1518,6 +1691,8 @@ msgid "" "Depending on how :mod:`__main__` is initialized, ``__main__.__spec__`` gets " "set appropriately or to ``None``." msgstr "" +"視 :mod:`__main__` 的初始化方式而定,``__main__.__spec__`` 會被適當設定,或設" +"為 ``None``。" #: ../../reference/import.rst:908 msgid "" @@ -1526,17 +1701,23 @@ msgid "" "populated when the ``__main__`` module is loaded as part of executing a " "directory, zipfile or other :data:`sys.path` entry." msgstr "" +"當 Python 以 :option:`-m` 選項啟動時,``__spec__`` 會設定為對應模組或套件的模" +"組規格。當 ``__main__`` 模組作為執行目錄、zipfile 或其他 :data:`sys.path` 條" +"目的一部分而被載入時,``__spec__`` 也會被填入。" #: ../../reference/import.rst:913 msgid "" -"In :ref:`the remaining cases ` ``__main__." -"__spec__`` is set to ``None``, as the code used to populate the :mod:" -"`__main__` does not correspond directly with an importable module:" +"In :ref:`the remaining cases ` " +"``__main__.__spec__`` is set to ``None``, as the code used to populate " +"the :mod:`__main__` does not correspond directly with an importable module:" msgstr "" +"在 :ref:`其餘狀況 ` 中," +"``__main__.__spec__`` 會被設為 ``None``,因為用來填入 :mod:`__main__` 的程式" +"碼並不直接對應可引入的模組:" #: ../../reference/import.rst:917 msgid "interactive prompt" -msgstr "" +msgstr "互動式提示字元" #: ../../reference/import.rst:918 msgid ":option:`-c` option" @@ -1544,19 +1725,22 @@ msgstr ":option:`-c` 選項" #: ../../reference/import.rst:919 msgid "running from stdin" -msgstr "" +msgstr "從 stdin 執行" #: ../../reference/import.rst:920 msgid "running directly from a source or bytecode file" -msgstr "" +msgstr "直接從原始碼或位元組碼檔案執行" #: ../../reference/import.rst:922 msgid "" "Note that ``__main__.__spec__`` is always ``None`` in the last case, *even " "if* the file could technically be imported directly as a module instead. Use " -"the :option:`-m` switch if valid module metadata is desired in :mod:" -"`__main__`." +"the :option:`-m` switch if valid module metadata is desired " +"in :mod:`__main__`." msgstr "" +"請注意,在最後一種情況下,``__main__.__spec__`` 一律為 ``None``,*即使* 該檔" +"案在技術上可直接作為模組引入也一樣。若希望在 :mod:`__main__` 中取得有效的模組詮" +"釋資料,請使用 :option:`-m` 選項。" #: ../../reference/import.rst:927 msgid "" @@ -1566,10 +1750,14 @@ msgid "" "__name__ == \"__main__\":`` checks only execute when the module is used to " "populate the ``__main__`` namespace, and not during normal import." msgstr "" +"另請注意,即使 ``__main__`` 對應到可引入的模組,且 ``__main__.__spec__`` 也已" +"相應設定,它們仍被視為 *不同* 的模組。這是因為由 ``if __name__ == " +"\"__main__\":`` 檢查所包住的程式碼區塊,只會在該模組用來填入 ``__main__`` 命" +"名空間時執行,而不會在一般引入時執行。" #: ../../reference/import.rst:935 msgid "References" -msgstr "" +msgstr "參考資料" #: ../../reference/import.rst:937 msgid "" @@ -1578,12 +1766,16 @@ msgid "" "packages/>`_ is still available to read, although some details have changed " "since the writing of that document." msgstr "" +"引入機制自 Python 早期以來已有相當大的演進。原始的 `套件規格 `_ 仍可閱讀,儘管自該文件撰寫以來部分細節已有" +"所變更。" #: ../../reference/import.rst:942 msgid "" "The original specification for :data:`sys.meta_path` was :pep:`302`, with " "subsequent extension in :pep:`420`." msgstr "" +":data:`sys.meta_path` 的原始規格是 :pep:`302`,後續在 :pep:`420` 中擴充。" #: ../../reference/import.rst:945 msgid "" @@ -1591,12 +1783,15 @@ msgid "" "Python 3.3. :pep:`420` also introduced the :meth:`!find_loader` protocol as " "an alternative to :meth:`!find_module`." msgstr "" +":pep:`420` 在 Python 3.3 中引進了 :term:`namespace packages `。:pep:`420` 也引進了 :meth:`!find_loader` 協定,作為 :meth:`!" +"find_module` 的替代方案。" #: ../../reference/import.rst:949 msgid "" ":pep:`366` describes the addition of the ``__package__`` attribute for " "explicit relative imports in main modules." -msgstr "" +msgstr ":pep:`366` 描述了在主模組中的明確相對引入加上``__package__`` 屬性。" #: ../../reference/import.rst:952 msgid "" @@ -1604,10 +1799,12 @@ msgid "" "proposed ``__name__`` for semantics :pep:`366` would eventually specify for " "``__package__``." msgstr "" +":pep:`328` 引進了絕對引入與明確的相對引入,並最初提出以 ``__name__`` 來表" +"示 :pep:`366` 最終為 ``__package__`` 指定的語意。" #: ../../reference/import.rst:956 msgid ":pep:`338` defines executing modules as scripts." -msgstr "" +msgstr ":pep:`338` 定義了將模組作為腳本執行。" #: ../../reference/import.rst:958 msgid "" @@ -1617,6 +1814,9 @@ msgid "" "of several APIs in the import system and also addition of new methods to " "finders and loaders." msgstr "" +":pep:`451` 增加了在 spec 物件中封裝個別模組的引入狀態。它也將載入器的大部分樣" +"板責任移回引入機制。這些變更讓引入系統中的多個 API 得以棄用,並新增尋檢器與載" +"入器的方法。" #: ../../reference/import.rst:965 msgid "Footnotes" @@ -1629,11 +1829,16 @@ msgstr "參閱 :class:`types.ModuleType`。" #: ../../reference/import.rst:968 msgid "" "The importlib implementation avoids using the return value directly. " -"Instead, it gets the module object by looking the module name up in :data:" -"`sys.modules`. The indirect effect of this is that an imported module may " -"replace itself in :data:`sys.modules`. This is implementation-specific " -"behavior that is not guaranteed to work in other Python implementations." -msgstr "" +"Instead, it gets the module object by looking the module name up " +"in :data:`sys.modules`. The indirect effect of this is that an imported " +"module may replace itself in :data:`sys.modules`. This is implementation-" +"specific behavior that is not guaranteed to work in other Python " +"implementations." +msgstr "" +"importlib 的實作避免直接使用回傳值,而是透過在 :data:`sys.modules` 中查找模組" +"名稱來取得模組物件。這樣的間接效果是,被引入的模組可能會" +"在 :data:`sys.modules` 中替換自己。這是實作特定的行為,並不保證能在其他 " +"Python 實作中運作。" #: ../../reference/import.rst:8 msgid "import machinery"