@@ -7,8 +7,8 @@ msgstr ""
7
7
"Project-Id-Version : Python 3.13\n "
8
8
"Report-Msgid-Bugs-To : \n "
9
9
"POT-Creation-Date : 2024-09-03 11:11+0800\n "
10
- "PO-Revision-Date : 2024-10-07 21:14 +0800\n "
11
- "Last-Translator : Adrian Liaw <adrianliaw2000 @gmail.com>\n "
10
+ "PO-Revision-Date : 2024-11-06 14:55 +0800\n "
11
+ "Last-Translator : Ken Cheng <ken71301 @gmail.com>\n "
12
12
"Language-Team : Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
13
13
"tw)\n "
14
14
"Language : zh_TW\n "
@@ -599,14 +599,16 @@ msgstr ""
599
599
600
600
#: ../../reference/import.rst:342
601
601
msgid "Loading"
602
- msgstr ""
602
+ msgstr "載入 "
603
603
604
604
#: ../../reference/import.rst:344
605
605
msgid ""
606
606
"If and when a module spec is found, the import machinery will use it (and "
607
607
"the loader it contains) when loading the module. Here is an approximation "
608
608
"of what happens during the loading portion of import::"
609
609
msgstr ""
610
+ "如果找到模組規格,引入機制會在載入模組時使用該規格(以及它包含的載入器)。以"
611
+ "下是引入過程中載入部分的大致情況: ::"
610
612
611
613
#: ../../reference/import.rst:348
612
614
msgid ""
@@ -639,16 +641,45 @@ msgid ""
639
641
" raise\n"
640
642
"return sys.modules[spec.name]"
641
643
msgstr ""
644
+ "module = None\n"
645
+ "if spec.loader is not None and hasattr(spec.loader, 'create_module'):\n"
646
+ " # 這裡假設載入器上也會定義 'exec_module'\n"
647
+ " module = spec.loader.create_module(spec)\n"
648
+ "if module is None:\n"
649
+ " module = ModuleType(spec.name)\n"
650
+ "# 與引入相關的模組屬性會在此處設定:\n"
651
+ "_init_module_attrs(spec, module)\n"
652
+ "\n"
653
+ "if spec.loader is None:\n"
654
+ " # 不支援\n"
655
+ " raise ImportError\n"
656
+ "if spec.origin is None and spec.submodule_search_locations is not None:\n"
657
+ " # 命名空間套件\n"
658
+ " sys.modules[spec.name] = module\n"
659
+ "elif not hasattr(spec.loader, 'exec_module'):\n"
660
+ " module = spec.loader.load_module(spec.name)\n"
661
+ "else:\n"
662
+ " sys.modules[spec.name] = module\n"
663
+ " try:\n"
664
+ " spec.loader.exec_module(module)\n"
665
+ " except BaseException:\n"
666
+ " try:\n"
667
+ " del sys.modules[spec.name]\n"
668
+ " except KeyError:\n"
669
+ " pass\n"
670
+ " raise\n"
671
+ "return sys.modules[spec.name]"
642
672
643
673
#: ../../reference/import.rst:377
644
674
msgid "Note the following details:"
645
- msgstr ""
675
+ msgstr "請注意下列細節: "
646
676
647
677
#: ../../reference/import.rst:379
648
678
msgid ""
649
679
"If there is an existing module object with the given name in :data:`sys."
650
680
"modules`, import will have already returned it."
651
681
msgstr ""
682
+ "如果 :data:`sys.modules` 中已存在具有給定名稱的模組物件,引入會已回傳該物件。"
652
683
653
684
#: ../../reference/import.rst:382
654
685
msgid ""
@@ -658,6 +689,9 @@ msgid ""
658
689
"prevents unbounded recursion in the worst case and multiple loading in the "
659
690
"best."
660
691
msgstr ""
692
+ "在載入器執行模組程式碼之前,模組將已存在於 :data:`sys.modules` 中。這一點至關"
693
+ "重要,因為模組程式碼可能會(直接或間接)引入自己;事先將其增加到 :data:`sys."
694
+ "modules` 可以預防類似無限遞迴以及多次重覆載入等情形。"
661
695
662
696
#: ../../reference/import.rst:388
663
697
msgid ""
@@ -667,6 +701,10 @@ msgid ""
667
701
"effect, must remain in the cache. This contrasts with reloading where even "
668
702
"the failing module is left in :data:`sys.modules`."
669
703
msgstr ""
704
+ "如果載入失敗,只有載入失敗的模組會從 :data:`sys.modules` 中刪除。任何已存在"
705
+ "於 :data:`sys.modules` 快取中的模組,以及任何在載入失敗前成功載入的模組,都必"
706
+ "須保留在快取中。此情形與重新載入不同,在重新載入時,即使載入失敗的模組也會保"
707
+ "留在 :data:`sys.modules` 中。"
670
708
671
709
#: ../../reference/import.rst:394
672
710
msgid ""
@@ -675,30 +713,39 @@ msgid ""
675
713
"code example above), as summarized in a :ref:`later section <import-mod-"
676
714
"attrs>`."
677
715
msgstr ""
716
+ "模組建立後、在執行之前,引入機制會設置與引入相關的模組屬性(在上面的偽程式碼"
717
+ "範例中為 \" _init_module_attrs\" ),具體內容在\\ :ref:`之後的段落<import-mod-"
718
+ "attrs>`\\ 會總結。"
678
719
679
720
#: ../../reference/import.rst:399
680
721
msgid ""
681
722
"Module execution is the key moment of loading in which the module's "
682
723
"namespace gets populated. Execution is entirely delegated to the loader, "
683
724
"which gets to decide what gets populated and how."
684
725
msgstr ""
726
+ "模組執行是載入過程中的關鍵時刻,此時模組的命名空間會被新增名稱。執行過程完全"
727
+ "交由載入器處理,由其決定如何新增以及新增什麼。"
685
728
686
729
#: ../../reference/import.rst:403
687
730
msgid ""
688
731
"The module created during loading and passed to exec_module() may not be the "
689
732
"one returned at the end of import [#fnlo]_."
690
733
msgstr ""
734
+ "在載入過程中建立並傳遞給 exec_module() 的模組,可能不會是引入結束時回傳的模"
735
+ "組 [#fnlo]_。"
691
736
692
737
#: ../../reference/import.rst:406
693
738
msgid ""
694
739
"The import system has taken over the boilerplate responsibilities of "
695
740
"loaders. These were previously performed by the :meth:`importlib.abc.Loader."
696
741
"load_module` method."
697
742
msgstr ""
743
+ "引入系統已接管載入器的模板 (boilerplate) 責任。之前是由 :meth:`importlib.abc."
744
+ "Loader.load_module` 方法執行的。"
698
745
699
746
#: ../../reference/import.rst:412
700
747
msgid "Loaders"
701
- msgstr ""
748
+ msgstr "載入器 "
702
749
703
750
#: ../../reference/import.rst:414
704
751
msgid ""
@@ -707,31 +754,41 @@ msgid ""
707
754
"method with a single argument, the module object to execute. Any value "
708
755
"returned from :meth:`~importlib.abc.Loader.exec_module` is ignored."
709
756
msgstr ""
757
+ "模組載入器提供了載入的關鍵功能:模組執行。引入機制會以單一引數(即要執行的模"
758
+ "組物件)呼叫 :meth:`importlib.abc.Loader.exec_module` 方法。任何從 :meth:"
759
+ "`~importlib.abc.Loader.exec_module` 回傳的值都會被忽略。"
710
760
711
761
#: ../../reference/import.rst:419
712
762
msgid "Loaders must satisfy the following requirements:"
713
- msgstr ""
763
+ msgstr "載入器必須滿足以下要求: "
714
764
715
765
#: ../../reference/import.rst:421
716
766
msgid ""
717
767
"If the module is a Python module (as opposed to a built-in module or a "
718
768
"dynamically loaded extension), the loader should execute the module's code "
719
769
"in the module's global name space (``module.__dict__``)."
720
770
msgstr ""
771
+ "如果模組是 Python 模組(而非內建模組或動態載入的擴充),載入器應在模組的全域"
772
+ "命名空間 (``module.__dict__``\\ ) 中執行該模組的程式碼。"
721
773
722
774
#: ../../reference/import.rst:425
723
775
msgid ""
724
776
"If the loader cannot execute the module, it should raise an :exc:"
725
777
"`ImportError`, although any other exception raised during :meth:`~importlib."
726
778
"abc.Loader.exec_module` will be propagated."
727
779
msgstr ""
780
+ "如果載入器無法執行該模組,應引發 :exc:`ImportError`。不過,在 :meth:"
781
+ "`~importlib.abc.Loader.exec_module` 中引發的任何其他例外也會被傳播。"
728
782
729
783
#: ../../reference/import.rst:429
730
784
msgid ""
731
785
"In many cases, the finder and loader can be the same object; in such cases "
732
786
"the :meth:`~importlib.abc.MetaPathFinder.find_spec` method would just return "
733
787
"a spec with the loader set to ``self``."
734
788
msgstr ""
789
+ "在許多情況下,尋檢器和載入器可以是同一個物件;在這種情況下,:meth:"
790
+ "`~importlib.abc.MetaPathFinder.find_spec` 方法只需回傳一個載入器設為 "
791
+ "``self`` 的規格即可。"
735
792
736
793
#: ../../reference/import.rst:433
737
794
msgid ""
@@ -742,17 +799,23 @@ msgid ""
742
799
"the module object. If the method returns ``None``, the import machinery "
743
800
"will create the new module itself."
744
801
msgstr ""
802
+ "模組載入器可以選擇透過實作 :meth:`~importlib.abc.Loader.create_module` 方法,"
803
+ "在載入過程中建立模組物件。該方法接受一個引數,即模組規格,並回傳在載入過程中"
804
+ "要使用的新的模組物件。``create_module()`` 不需要在模組物件上設定任何屬性。如"
805
+ "果該方法回傳 ``None``,引入機制將自行建立新的模組。"
745
806
746
807
#: ../../reference/import.rst:440
747
808
msgid "The :meth:`~importlib.abc.Loader.create_module` method of loaders."
748
- msgstr ""
809
+ msgstr "載入器的 :meth:`~importlib.abc.Loader.create_module` 方法。 "
749
810
750
811
#: ../../reference/import.rst:443
751
812
msgid ""
752
813
"The :meth:`~importlib.abc.Loader.load_module` method was replaced by :meth:"
753
814
"`~importlib.abc.Loader.exec_module` and the import machinery assumed all the "
754
815
"boilerplate responsibilities of loading."
755
816
msgstr ""
817
+ ":meth:`~importlib.abc.Loader.load_module` 方法已被 :meth:`~importlib.abc."
818
+ "Loader.exec_module` 取代,引入機制已承擔所有載入的模板責任。"
756
819
757
820
#: ../../reference/import.rst:448
758
821
msgid ""
@@ -761,13 +824,18 @@ msgid ""
761
824
"also implement ``exec_module()``. However, ``load_module()`` has been "
762
825
"deprecated and loaders should implement ``exec_module()`` instead."
763
826
msgstr ""
827
+ "為了與現有的載入器相容,引入機制會在載入器未實作 ``exec_module()`` 且存在 "
828
+ "``load_module()`` 方法時使用該方法。然而,``load_module()`` 已被棄用,載入器"
829
+ "應改為實作 ``exec_module()``。"
764
830
765
831
#: ../../reference/import.rst:453
766
832
msgid ""
767
833
"The ``load_module()`` method must implement all the boilerplate loading "
768
834
"functionality described above in addition to executing the module. All the "
769
835
"same constraints apply, with some additional clarification:"
770
836
msgstr ""
837
+ "``load_module()`` 方法除了執行模組外,還必須實作上述全部的模板載入功能。所有"
838
+ "相同的限制依然適用,並且還有一些額外的說明:"
771
839
772
840
#: ../../reference/import.rst:457
773
841
msgid ""
@@ -777,35 +845,48 @@ msgid ""
777
845
"exist in :data:`sys.modules`, the loader must create a new module object and "
778
846
"add it to :data:`sys.modules`."
779
847
msgstr ""
848
+ "如果 :data:`sys.modules` 中已存在具有給定名稱的模組物件,載入器必須使用該模組"
849
+ "(否則 :func:`importlib.reload` 將無法正常運作)。如果命名模組不存在於 :data:"
850
+ "`sys.modules` 中,載入器必須建立一個新的模組物件並將其新增至 :data:`sys."
851
+ "modules`。"
780
852
781
853
#: ../../reference/import.rst:463
782
854
msgid ""
783
855
"The module *must* exist in :data:`sys.modules` before the loader executes "
784
856
"the module code, to prevent unbounded recursion or multiple loading."
785
857
msgstr ""
858
+ "在載入器執行模組程式碼之前,該模組\\ *必須*\\ 已存在於 :data:`sys.modules` "
859
+ "中,以防止無限遞迴或多次載入。"
786
860
787
861
#: ../../reference/import.rst:467
788
862
msgid ""
789
863
"If loading fails, the loader must remove any modules it has inserted into :"
790
864
"data:`sys.modules`, but it must remove **only** the failing module(s), and "
791
865
"only if the loader itself has loaded the module(s) explicitly."
792
866
msgstr ""
867
+ "如果載入失敗,載入器必須移除已經插入到 :data:`sys.modules` 中的任何模組,但"
868
+ "\\ **只能**\\ 移除失敗的模組(們),且僅在載入器本身明確載入這些模組時才需移"
869
+ "除。"
793
870
794
871
#: ../../reference/import.rst:472
795
872
msgid ""
796
873
"A :exc:`DeprecationWarning` is raised when ``exec_module()`` is defined but "
797
874
"``create_module()`` is not."
798
875
msgstr ""
876
+ "當 ``exec_module()`` 已定義但未定義 ``create_module()`` 時,將引發 :exc:"
877
+ "`DeprecationWarning`。"
799
878
800
879
#: ../../reference/import.rst:476
801
880
msgid ""
802
881
"An :exc:`ImportError` is raised when ``exec_module()`` is defined but "
803
882
"``create_module()`` is not."
804
883
msgstr ""
884
+ "當 ``exec_module()`` 已定義但未定義 ``create_module()`` 時,將引發 :exc:"
885
+ "`ImportError`。"
805
886
806
887
#: ../../reference/import.rst:480
807
888
msgid "Use of ``load_module()`` will raise :exc:`ImportWarning`."
808
- msgstr ""
889
+ msgstr "使用 ``load_module()`` 將引發 :exc:`ImportWarning`。 "
809
890
810
891
#: ../../reference/import.rst:484
811
892
msgid "Submodules"
@@ -820,6 +901,11 @@ msgid ""
820
901
"``spam.foo``, ``spam`` will have an attribute ``foo`` which is bound to the "
821
902
"submodule. Let's say you have the following directory structure::"
822
903
msgstr ""
904
+ "當使用任何機制(例如 ``importlib`` APIs、``import`` 或 ``import-from`` 陳述"
905
+ "式,或內建的 ``__import__()``\\ )載入子模組時,會將子模組物件繫結到父模組的"
906
+ "命名空間中。例如,如果套件 ``spam`` 有一個子模組 ``foo``,則在引入 ``spam."
907
+ "foo`` 之後,``spam`` 將擁有一個名為 ``foo`` 的屬性,該屬性繫結到子模組。我們"
908
+ "假設你有以下的目錄結構: ::"
823
909
824
910
#: ../../reference/import.rst:493
825
911
msgid ""
@@ -833,7 +919,7 @@ msgstr ""
833
919
834
920
#: ../../reference/import.rst:497
835
921
msgid "and ``spam/__init__.py`` has the following line in it::"
836
- msgstr ""
922
+ msgstr "並且 ``spam/__init__.py`` 中包含以下程式碼: :: "
837
923
838
924
#: ../../reference/import.rst:499
839
925
msgid "from .foo import Foo"
@@ -844,6 +930,7 @@ msgid ""
844
930
"then executing the following puts name bindings for ``foo`` and ``Foo`` in "
845
931
"the ``spam`` module::"
846
932
msgstr ""
933
+ "那麼執行以下程式碼會將 ``foo`` 和 ``Foo`` 的名稱繫結到 ``spam`` 模組中: ::"
847
934
848
935
#: ../../reference/import.rst:504
849
936
msgid ""
@@ -867,10 +954,14 @@ msgid ""
867
954
"foo']`` (as you would after the above import), the latter must appear as the "
868
955
"``foo`` attribute of the former."
869
956
msgstr ""
957
+ "鑑於 Python 相似的名稱繫結規則,這可能看起來有些出人意料,但這實際上是引入系"
958
+ "統的一個基本特性。不變的是如果你擁有 ``sys.modules['spam']`` 和 ``sys."
959
+ "modules['spam.foo']``(就像上述引入後那樣),那麼後者必須作為前者的 ``foo`` "
960
+ "屬性出現。"
870
961
871
962
#: ../../reference/import.rst:519
872
963
msgid "Module specs"
873
- msgstr ""
964
+ msgstr "模組規格 "
874
965
875
966
#: ../../reference/import.rst:521
876
967
msgid ""
@@ -879,6 +970,9 @@ msgid ""
879
970
"modules. The purpose of a module's spec is to encapsulate this import-"
880
971
"related information on a per-module basis."
881
972
msgstr ""
973
+ "引入機制在引入過程中使用有關每個模組的各種資訊,尤其是在載入之前。大多數資訊"
974
+ "對所有模組來說都是通用的。模組規格的目的是以每個模組為基礎封裝這些與引入相關"
975
+ "的資訊。"
882
976
883
977
#: ../../reference/import.rst:526
884
978
msgid ""
@@ -888,6 +982,9 @@ msgid ""
888
982
"machinery to perform the boilerplate operations of loading, whereas without "
889
983
"a module spec the loader had that responsibility."
890
984
msgstr ""
985
+ "在引入過程中使用規格允許在引入系統的各個組件之間傳遞狀態,例如在建立模組規格"
986
+ "的尋檢器和執行該規格的載入器之間傳遞。最重要的是,這允許引入機制執行載入的模"
987
+ "板操作,而在沒有模組規格的情況下,這些操作則是載入器的責任。"
891
988
892
989
#: ../../reference/import.rst:532
893
990
msgid ""
@@ -896,12 +993,17 @@ msgid ""
896
993
"interpreter startup <programs>`. The one exception is ``__main__``, where :"
897
994
"attr:`!__spec__` is :ref:`set to None in some cases <main_spec>`."
898
995
msgstr ""
996
+ "模組的規格以 :attr:`module.__spec__` 的形式公開。適當地設定 :attr:`!"
997
+ "__spec__` 同樣適用於\\ :ref:`在直譯器啟動期間初始化的模組 <programs>`。唯一的"
998
+ "例外是 ``__main__``,其中 :attr:`!__spec__` 會\\ :ref:`在某些情況下被設定成 "
999
+ "None <main_spec>`。"
899
1000
900
1001
#: ../../reference/import.rst:538
901
1002
msgid ""
902
1003
"See :class:`~importlib.machinery.ModuleSpec` for details on the contents of "
903
1004
"the module spec."
904
1005
msgstr ""
1006
+ "有關模組規格內容的詳細資訊,請參閱 :class:`~importlib.machinery.ModuleSpec`。"
905
1007
906
1008
#: ../../reference/import.rst:546
907
1009
msgid "__path__ attributes on modules"
0 commit comments