-
-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathimport.po
1796 lines (1595 loc) · 80.3 KB
/
import.po
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (C) 2001-2024, Python Software Foundation
# This file is distributed under the same license as the Python package.
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: Python 3.13\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-03 11:11+0800\n"
"PO-Revision-Date: 2024-12-23 15:33+0800\n"
"Last-Translator: Ken Cheng <[email protected]>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
"tw)\n"
"Language: zh_TW\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Poedit 3.5\n"
#: ../../reference/import.rst:6
msgid "The import system"
msgstr "模組引入系統"
#: ../../reference/import.rst:10
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."
msgstr ""
"一個 :term:`module` 中的 Python 程式碼透過 :term:`importing` 的過程來存取另一"
"個模組中的程式碼。:keyword:`import` 陳述式是調用 (invoke) 引入機制最常見的方"
"法,但這不是唯一的方法。函式如 :func:`importlib.import_module` 以及內建函式 :"
"func:`__import__` 也可以用來調用引入機制。"
#: ../../reference/import.rst:16
msgid ""
"The :keyword:`import` statement combines two operations; it searches for the "
"named module, then it binds the results of that search to a name in the "
"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 "
"operation."
msgstr ""
":keyword:`import` 陳述式結合了兩個操作:首先搜尋指定的模組,然後將搜尋結果繫"
"結到本地作用域中的一個名稱。:keyword:`!import` 陳述式的搜尋操作被定義為一個"
"對 :func:`__import__` 函式的呼叫,並帶有相應的引數。:func:`__import__` 的回傳"
"值用於執行 :keyword:`!import` 陳述式的名稱繫結操作。有關名稱繫結操作的詳細資"
"訊,請參見 :keyword:`!import` 陳述式。"
#: ../../reference/import.rst:25
msgid ""
"A direct call to :func:`__import__` performs only the module search and, if "
"found, the module creation operation. While certain side-effects may occur, "
"such as the importing of parent packages, and the updating of various caches "
"(including :data:`sys.modules`), only the :keyword:`import` statement "
"performs a name binding operation."
msgstr ""
"直接呼叫 :func:`__import__` 只會執行模組搜尋操作,以及在找到時執行模組的建立"
"操作。雖然某些副作用可能會發生,例如引入父套件 (parent package),以及更新各種"
"快取(包括 :data:`sys.modules`),但只有 :keyword:`import` 陳述式會執行名稱繫"
"結操作。"
#: ../../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."
msgstr ""
"當執行 :keyword:`import` 陳述式時,會呼叫內建的 :func:`__import__` 函式。其他"
"調用引入系統的機制(如 :func:`importlib.import_module`)可以選擇略過 :func:"
"`__import__`,並使用它們自己的解決方案來實作引入語意。"
#: ../../reference/import.rst:36
msgid ""
"When a module is first imported, Python searches for the module and if "
"found, it creates a module object [#fnmo]_, initializing it. If the named "
"module cannot be found, a :exc:`ModuleNotFoundError` is raised. Python "
"implements various strategies to search for the named module when the import "
"machinery is invoked. These strategies can be modified and extended by "
"using various hooks described in the sections below."
msgstr ""
"當模組首次被引入時,Python 會搜尋該模組,若找到則會建立一個模組物件 "
"[#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 "
"import system is exposed through :data:`sys.meta_path`. In addition, native "
"namespace package support has been implemented (see :pep:`420`)."
msgstr ""
"引入系統已被更新,以完全實作 :pep:`302` 的第二階段。不再有隱式引入機制——完整"
"的引入系統已透過 :data:`sys.meta_path` 公開。此外,原生命名空間套件支援(請參"
"閱 :pep:`420`)也已被實作。"
#: ../../reference/import.rst:51
msgid ":mod:`importlib`"
msgstr ":mod:`importlib`"
#: ../../reference/import.rst:53
msgid ""
"The :mod:`importlib` module provides a rich API for interacting with the "
"import system. For example :func:`importlib.import_module` provides a "
"recommended, simpler API than built-in :func:`__import__` for invoking the "
"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` 函式庫文件。"
#: ../../reference/import.rst:62
msgid "Packages"
msgstr "套件"
#: ../../reference/import.rst:67
msgid ""
"Python has only one type of module object, and all modules are of this type, "
"regardless of whether the module is implemented in Python, C, or something "
"else. To help organize modules and provide a naming hierarchy, Python has a "
"concept of :term:`packages <package>`."
msgstr ""
"Python 只有一種類型的模組物件,且所有模組,無論其是使用 Python、C 還是其他語"
"言實作,都是這種類型。為了幫助組織模組並提供命名階層,Python 導入了\\ :term:`"
"套件 <package>`\\ 的概念。"
#: ../../reference/import.rst:72
msgid ""
"You can think of packages as the directories on a file system and modules as "
"files within directories, but don't take this analogy too literally since "
"packages and modules need not originate from the file system. For the "
"purposes of this documentation, we'll use this convenient analogy of "
"directories and files. Like file system directories, packages are organized "
"hierarchically, and packages may themselves contain subpackages, as well as "
"regular modules."
msgstr ""
"你可以將套件視為檔案系統中的目錄,模組則是目錄中的檔案,但不要過於字面地理解"
"這個比喻,因為套件和模組不一定來自檔案系統。為了方便解釋,我們將使用這個目錄"
"和檔案的比喻。就像檔案系統目錄一樣,套件是分層組織的,套件本身可以包含子套件"
"以及一般模組。"
#: ../../reference/import.rst:80
msgid ""
"It's important to keep in mind that all packages are modules, but not all "
"modules are packages. Or put another way, packages are just a special kind "
"of module. Specifically, any module that contains a ``__path__`` attribute "
"is considered a package."
msgstr ""
"請記住,所有的套件都是模組,但並非所有模組都是套件。換句話說,套件只是一種特"
"殊的模組。具體來說,任何包含 ``__path__`` 屬性的模組都被視為套件。"
#: ../../reference/import.rst:85
msgid ""
"All modules have a name. Subpackage names are separated from their parent "
"package name by a dot, akin to Python's standard attribute access syntax. "
"Thus you might have a package called :mod:`email`, which in turn has a "
"subpackage called :mod:`email.mime` and a module within that subpackage "
"called :mod:`email.mime.text`."
msgstr ""
"所有模組都有一個名稱。子套件的名稱與其父套件名稱之間用一個點來分隔,類似於 "
"Python 的標準屬性存取語法。因此,你可能會有一個名為 :mod:`email` 的套件,該套"
"件又有一個名為 :mod:`email.mime` 的子套件,並且該子套件中有一個名為 :mod:"
"`email.mime.text` 的模組。"
#: ../../reference/import.rst:93
msgid "Regular packages"
msgstr "一般套件"
#: ../../reference/import.rst:98
msgid ""
"Python defines two types of packages, :term:`regular packages <regular "
"package>` and :term:`namespace packages <namespace package>`. 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:`一般套件 <regular package>`\\ 和\\ :term:"
"`命名空間套件 <namespace package>`。一般套件是 Python 3.2 及更早版本中存在的"
"傳統套件。一般套件通常實作成一個包含 ``__init__.py`` 檔案的目錄。當引入一般套"
"件時,該 ``__init__.py`` 檔案會被隱式執行,其定義的物件會繫結到該套件的命名空"
"間中的名稱。``__init__.py`` 檔案可以包含與任何其他模組相同的 Python 程式碼,"
"並且 Python 會在引入時為該模組增加一些額外的屬性。"
#: ../../reference/import.rst:108
msgid ""
"For example, the following file system layout defines a top level ``parent`` "
"package with three subpackages::"
msgstr ""
"例如,以下檔案系統布置定義了一個頂層的 ``parent`` 套件,該套件包含三個子套"
"件: ::"
#: ../../reference/import.rst:111
msgid ""
"parent/\n"
" __init__.py\n"
" one/\n"
" __init__.py\n"
" two/\n"
" __init__.py\n"
" three/\n"
" __init__.py"
msgstr ""
"parent/\n"
" __init__.py\n"
" one/\n"
" __init__.py\n"
" two/\n"
" __init__.py\n"
" three/\n"
" __init__.py"
#: ../../reference/import.rst:120
msgid ""
"Importing ``parent.one`` will implicitly execute ``parent/__init__.py`` and "
"``parent/one/__init__.py``. Subsequent imports of ``parent.two`` or "
"``parent.three`` will execute ``parent/two/__init__.py`` and ``parent/three/"
"__init__.py`` respectively."
msgstr ""
"引入 ``parent.one`` 將隱式執行 ``parent/__init__.py`` 和 ``parent/one/"
"__init__.py``。隨後引入 ``parent.two`` 或 ``parent.three`` 將分別執行 "
"``parent/two/__init__.py`` 和 ``parent/three/__init__.py``。"
#: ../../reference/import.rst:127
msgid "Namespace packages"
msgstr "命名空間套件"
#: ../../reference/import.rst:133
msgid ""
"A namespace package is a composite of various :term:`portions <portion>`, "
"where each portion contributes a subpackage to the parent package. Portions "
"may reside in different locations on the file system. Portions may also be "
"found in zip files, on the network, or anywhere else that Python searches "
"during import. Namespace packages may or may not correspond directly to "
"objects on the file system; they may be virtual modules that have no "
"concrete representation."
msgstr ""
"命名空間套件是由不同的\\ :term:`部分 <portion>` 組成的,每個部分都為父套件提"
"供一個子套件。這些部分可以位於檔案系統上的不同位置。部分可能也存在於壓縮檔案"
"中、網路上,或 Python 在引入時搜尋的任何其他地方。命名空間套件不一定直接對應"
"於檔案系統中的對象;它們可能是沒有具體表示的虛擬模組。"
#: ../../reference/import.rst:141
msgid ""
"Namespace packages do not use an ordinary list for their ``__path__`` "
"attribute. They instead use a custom iterable type which will automatically "
"perform a new search for package portions on the next import attempt within "
"that package if the path of their parent package (or :data:`sys.path` for a "
"top level package) changes."
msgstr ""
"命名空間套件的 ``__path__`` 屬性不使用普通的串列。它們使用自定義的可疊代型"
"別,當父套件的路徑(或頂層套件的 :data:`sys.path`)發生變化時,會在下一次引入"
"嘗試時自動執行新一輪的套件部分搜尋。"
#: ../../reference/import.rst:147
msgid ""
"With namespace packages, there is no ``parent/__init__.py`` file. In fact, "
"there may be multiple ``parent`` directories found during import search, "
"where each one is provided by a different portion. Thus ``parent/one`` may "
"not be physically located next to ``parent/two``. In this case, Python will "
"create a namespace package for the top-level ``parent`` package whenever it "
"or one of its subpackages is imported."
msgstr ""
"在命名空間套件中,不存在 ``parent/__init__.py`` 檔案。實際上,在引入搜尋過程"
"中可能會找到多個 ``parent`` 目錄,每個目錄由不同的部分提供。因此,``parent/"
"one`` 可能與 ``parent/two`` 不會實際位於一起。在這種情況下,每當引入頂層 "
"``parent`` 套件或其子套件之一時,Python 會為頂層 ``parent`` 套件建立一個命名"
"空間套件。"
#: ../../reference/import.rst:154
msgid "See also :pep:`420` for the namespace package specification."
msgstr "有關命名空間套件的規範,請參見 :pep:`420`。"
#: ../../reference/import.rst:158
msgid "Searching"
msgstr "搜尋"
#: ../../reference/import.rst:160
msgid ""
"To begin the search, Python needs the :term:`fully qualified <qualified "
"name>` name of the module (or package, but for the purposes of this "
"discussion, the difference is immaterial) being imported. This name may "
"come from various arguments to the :keyword:`import` statement, or from the "
"parameters to the :func:`importlib.import_module` or :func:`__import__` "
"functions."
msgstr ""
"在開始搜尋之前,Python 需要被引入模組(或套件,但在本討論中,兩者的區別無關緊"
"要)的完整\\ :term:`限定名稱 (qualified name) <qualified name>`。此名稱可能來"
"自 :keyword:`import` 陳述式的各種引數,或來自 :func:`importlib."
"import_module` 或 :func:`__import__` 函式的參數。"
#: ../../reference/import.rst:166
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."
msgstr ""
"此名稱將在引入搜尋的各個階段中使用,並且它可能是指向子模組的點分隔路徑,例如 "
"``foo.bar.baz``。在這種情況下,Python 會首先嘗試引入 ``foo``,然後是 ``foo."
"bar``,最後是 ``foo.bar.baz``。如果任何中間引入失敗,則會引發 :exc:"
"`ModuleNotFoundError`。"
#: ../../reference/import.rst:173
msgid "The module cache"
msgstr "模組快取"
#: ../../reference/import.rst:178
msgid ""
"The first place checked during import search is :data:`sys.modules`. This "
"mapping serves as a cache of all modules that have been previously imported, "
"including the intermediate paths. So if ``foo.bar.baz`` was previously "
"imported, :data:`sys.modules` will contain entries for ``foo``, ``foo.bar``, "
"and ``foo.bar.baz``. Each key will have as its value the corresponding "
"module object."
msgstr ""
"在引入搜尋過程中首先檢查的地方是 :data:`sys.modules`。此對映用作所有先前引入"
"過的模組的快取,包括中間路徑。因此,如果 ``foo.bar.baz`` 之前已被引入,:data:"
"`sys.modules` 將包含 ``foo``、``foo.bar`` 和 ``foo.bar.baz`` 的條目。每個鍵的"
"值都是相應的模組物件。"
#: ../../reference/import.rst:185
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."
msgstr ""
"在引入過程中,會在 :data:`sys.modules` 中查找模組名稱,如果存在,則相關的值為"
"滿足此引入的模組,此引入過程即完成。然而,如果值是 ``None``,則會引發 :exc:"
"`ModuleNotFoundError`。如果模組名稱不存在,Python 會繼續搜尋該模組。"
#: ../../reference/import.rst:191
msgid ""
":data:`sys.modules` is writable. Deleting a key may not destroy the "
"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`."
msgstr ""
":data:`sys.modules` 是可寫入的。刪除一個鍵可能不會銷毀相關聯的模組(因為其他"
"模組可能持有對它的參照),但會使指定的模組的快取條目失效,導致 Python 在下一"
"次引入該模組時重新搜尋。也可以將鍵賦值為 ``None``,這會強制下一次引入該模組時"
"引發 :exc:`ModuleNotFoundError`。"
#: ../../reference/import.rst:198
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."
msgstr ""
"但請注意,如果你保留了對模組物件的參照,並在 :data:`sys.modules` 中使其快取條"
"目失效,然後重新引入指定的模組,這兩個模組物件將\\ *不會*\\ 相同。相比之下,:"
"func:`importlib.reload` 會重用\\ *相同的*\\ 模組物件,並透過重新執行模組的程"
"式碼來簡單地重新初始化模組內容。"
#: ../../reference/import.rst:208
msgid "Finders and loaders"
msgstr "尋檢器 (Finder) 與載入器 (Loader)"
#: ../../reference/import.rst:215
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 <finder>` and :term:"
"`loaders <loader>`. 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 <importer>` - "
"they return themselves when they find that they can load the requested "
"module."
msgstr ""
"如果在 :data:`sys.modules` 中找不到指定的模組,則會調用 Python 的引入協定來尋"
"找並載入該模組。這個協定由兩個概念性物件組成,:term:`尋檢器 <finder>` 和\\ :"
"term:`載入器 <loader>`。尋檢器的任務是使用其已知的策略來確定是否能找到命名模"
"組。實作這兩個介面的物件稱為\\ :term:`引入器 (importer) <importer>` ——當它們"
"發現可以載入所請求的模組時,會回傳它們自己。"
#: ../../reference/import.rst:223
msgid ""
"Python includes a number of default finders and importers. The first one "
"knows how to locate built-in modules, and the second knows how to locate "
"frozen modules. A third default finder searches an :term:`import path` for "
"modules. The :term:`import path` is a list of locations that may name file "
"system paths or zip files. It can also be extended to search for any "
"locatable resource, such as those identified by URLs."
msgstr ""
"Python 包含多個預設的尋檢器和引入器。第一個尋檢器知道如何定位內建模組,第二個"
"尋檢器知道如何定位凍結模組。第三個預設尋檢器會在 :term:`import path` 中搜尋模"
"組。:term:`import path` 是一個位置的列表,這些位置可能是檔案系統路徑或壓縮檔"
"案,也可以擴展以搜尋任何可定位的資源,例如由 URL 識別的資源。"
#: ../../reference/import.rst:230
msgid ""
"The import machinery is extensible, so new finders can be added to extend "
"the range and scope of module searching."
msgstr ""
"引入機制是可擴展的,因此可以增加新的尋檢器來擴展模組搜尋的範圍和作用域。"
#: ../../reference/import.rst:233
msgid ""
"Finders do not actually load modules. If they can find the named module, "
"they return a :dfn:`module spec`, an encapsulation of the module's import-"
"related information, which the import machinery then uses when loading the "
"module."
msgstr ""
"尋檢器實際上不會載入模組。如果它們能找到指定的模組,它們會回傳一個\\ :dfn:`模"
"組規格`,這是一個模組的引入相關資訊的封裝,引入機制會在載入模組時使用這些資"
"訊。"
#: ../../reference/import.rst:237
msgid ""
"The following sections describe the protocol for finders and loaders in more "
"detail, including how you can create and register new ones to extend the "
"import machinery."
msgstr ""
"以下各節將更詳細地描述尋檢器和載入器的協定,包括如何建立和註冊新的尋檢器和載"
"入器來擴展引入機制。"
#: ../../reference/import.rst:241
msgid ""
"In previous versions of Python, finders returned :term:`loaders <loader>` "
"directly, whereas now they return module specs which *contain* loaders. "
"Loaders are still used during import but have fewer responsibilities."
msgstr ""
"Python 在之前的版本中,尋檢器會直接回傳\\ :term:`載入器 <loader>`,而現在它們"
"回傳的是\\ *包含*\\ 載入器的模組規格。載入器仍在引入過程中使用,但其責任減少"
"了。"
#: ../../reference/import.rst:247
msgid "Import hooks"
msgstr "引入掛鉤 (Import hooks)"
#: ../../reference/import.rst:257
msgid ""
"The import machinery is designed to be extensible; the primary mechanism for "
"this are the *import hooks*. There are two types of import hooks: *meta "
"hooks* and *import path hooks*."
msgstr ""
"引入機制的設計是可擴展的;其主要機制是\\ *引入掛鉤*。引入掛鉤有兩種類型:*元"
"掛鉤 (meta hooks)* 和\\ *引入路徑掛鉤*。"
#: ../../reference/import.rst:261
msgid ""
"Meta hooks are called at the start of import processing, before any other "
"import processing has occurred, other than :data:`sys.modules` cache look "
"up. This allows meta hooks to override :data:`sys.path` processing, frozen "
"modules, or even built-in modules. Meta hooks are registered by adding new "
"finder objects to :data:`sys.meta_path`, as described below."
msgstr ""
"元掛鉤會在引入處理的開始階段被呼叫,除了查找 :data:`sys.modules` 快取外,其他"
"引入處理還未發生時就會呼叫。這允許元掛鉤覆蓋 :data:`sys.path` 的處理、凍結模"
"組,甚至是內建模組。元掛鉤透過將新的尋檢器物件添加到 :data:`sys.meta_path` 中"
"來註冊,具體描述請參閱以下段落。"
#: ../../reference/import.rst:267
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."
msgstr ""
"引入路徑掛鉤被視為 :data:`sys.path`\\ (或 ``package.__path__``)處理過程的一"
"部分來呼叫,當遇到與其相關聯的路徑項目時就會被觸發。引入路徑掛鉤透過將新的可"
"呼叫對象增加到 :data:`sys.path_hooks` 中來註冊,具體描述請參閱以下段落。"
#: ../../reference/import.rst:274
msgid "The meta path"
msgstr "元路徑"
#: ../../reference/import.rst:280
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` 的方法,該方法接收三個引數:名稱、引入路徑和(可選"
"的)目標模組。元路徑尋檢器可以使用任何策略來確定它是否能處理命名模組。"
#: ../../reference/import.rst:289
msgid ""
"If the meta path finder knows how to handle the named module, it returns a "
"spec object. If it cannot handle the named module, it returns ``None``. "
"If :data:`sys.meta_path` processing reaches the end of its list without "
"returning a spec, then a :exc:`ModuleNotFoundError` is raised. Any other "
"exceptions raised are simply propagated up, aborting the import process."
msgstr ""
"如果元路徑尋檢器知道如何處理命名模組,它會回傳一個規格物件。如果它無法處理命"
"名模組,則回傳 ``None``。如果 :data:`sys.meta_path` 的處理到達串列的末尾仍未"
"回傳規格,則會引發 :exc:`ModuleNotFoundError`。任何其他引發的例外將直接向上傳"
"播,並中止引入過程。"
#: ../../reference/import.rst:295
msgid ""
"The :meth:`~importlib.abc.MetaPathFinder.find_spec` method of meta path "
"finders is called with two or three arguments. The first is the fully "
"qualified name of the module being imported, for example ``foo.bar.baz``. "
"The second argument is the path entries to use for the module search. For "
"top-level modules, the second argument is ``None``, but for submodules or "
"subpackages, the second argument is the value of the parent package's "
"``__path__`` attribute. If the appropriate ``__path__`` attribute cannot be "
"accessed, a :exc:`ModuleNotFoundError` is raised. The third argument is an "
"existing module object that will be the target of loading later. The import "
"system passes in a target module only during reload."
msgstr ""
"元路徑尋檢器的 :meth:`~importlib.abc.MetaPathFinder.find_spec` 方法會以兩個或"
"三個引數來呼叫。第一個是被引入模組的完全限定名稱,例如 ``foo.bar.baz``。第二"
"個引數是用於模組搜尋的路徑條目。對於頂層模組,第二個引數是 ``None``,但對於子"
"模組或子套件,第二個引數是父套件的 ``__path__`` 屬性的值。如果無法存取相應的 "
"``__path__`` 屬性,將引發 :exc:`ModuleNotFoundError`。第三個引數是一個現有的"
"模組物件,該物件將成為後續載入的目標。引入系統只會在重新載入時傳入目標模組。"
#: ../../reference/import.rst:306
msgid ""
"The meta path may be traversed multiple times for a single import request. "
"For example, assuming none of the modules involved has already been cached, "
"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)``."
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)``。"
#: ../../reference/import.rst:316
msgid ""
"Some meta path finders only support top level imports. These importers will "
"always return ``None`` when anything other than ``None`` is passed as the "
"second argument."
msgstr ""
"一些元路徑尋檢器僅支援頂層引入。當第二個引數傳入 ``None`` 以外的值時,這些引"
"入器將始終回傳 ``None``。"
#: ../../reference/import.rst:320
msgid ""
"Python's default :data:`sys.meta_path` has three meta path finders, one that "
"knows how to import built-in modules, one that knows how to import frozen "
"modules, and one that knows how to import modules from an :term:`import "
"path` (i.e. the :term:`path based finder`)."
msgstr ""
"Python 的預設 :data:`sys.meta_path` 有三個元路徑尋檢器,一個知道如何引入內建"
"模組,一個知道如何引入凍結模組,還有一個知道如何從 :term:`import path` 引入模"
"組(即 :term:`path based finder`)。"
#: ../../reference/import.rst:325
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`."
msgstr ""
"元路徑尋檢器的 :meth:`~importlib.abc.MetaPathFinder.find_spec` 方法取代了 :"
"meth:`!find_module`,後者現在已被棄用。雖然它將繼續正常工作,但引入機制僅在尋"
"檢器未實作 :meth:`~importlib.abc.MetaPathFinder.find_spec` 時才會嘗試使用它。"
#: ../../reference/import.rst:332
msgid ""
"Use of :meth:`!find_module` by the import system now raises :exc:"
"`ImportWarning`."
msgstr "引入系統現在使用 :meth:`!find_module` 時將引發 :exc:`ImportWarning`。"
#: ../../reference/import.rst:336
msgid ""
":meth:`!find_module` has been removed. Use :meth:`~importlib.abc."
"MetaPathFinder.find_spec` instead."
msgstr ""
":meth:`!find_module` 已被移除。請改用 :meth:`~importlib.abc.MetaPathFinder."
"find_spec`。"
#: ../../reference/import.rst:342
msgid "Loading"
msgstr "載入"
#: ../../reference/import.rst:344
msgid ""
"If and when a module spec is found, the import machinery will use it (and "
"the loader it contains) when loading the module. Here is an approximation "
"of what happens during the loading portion of import::"
msgstr ""
"如果找到模組規格,引入機制會在載入模組時使用該規格(以及它包含的載入器)。以"
"下是引入過程中載入部分的大致情況: ::"
#: ../../reference/import.rst:348
msgid ""
"module = None\n"
"if spec.loader is not None and hasattr(spec.loader, 'create_module'):\n"
" # It is assumed 'exec_module' will also be defined on the loader.\n"
" module = spec.loader.create_module(spec)\n"
"if module is None:\n"
" module = ModuleType(spec.name)\n"
"# The import-related module attributes get set here:\n"
"_init_module_attrs(spec, module)\n"
"\n"
"if spec.loader is None:\n"
" # unsupported\n"
" raise ImportError\n"
"if spec.origin is None and spec.submodule_search_locations is not None:\n"
" # namespace package\n"
" sys.modules[spec.name] = module\n"
"elif not hasattr(spec.loader, 'exec_module'):\n"
" module = spec.loader.load_module(spec.name)\n"
"else:\n"
" sys.modules[spec.name] = module\n"
" try:\n"
" spec.loader.exec_module(module)\n"
" except BaseException:\n"
" try:\n"
" del sys.modules[spec.name]\n"
" except KeyError:\n"
" pass\n"
" raise\n"
"return sys.modules[spec.name]"
msgstr ""
"module = None\n"
"if spec.loader is not None and hasattr(spec.loader, 'create_module'):\n"
" # 這裡假設載入器上也會定義 'exec_module'\n"
" module = spec.loader.create_module(spec)\n"
"if module is None:\n"
" module = ModuleType(spec.name)\n"
"# 與引入相關的模組屬性會在此處設定:\n"
"_init_module_attrs(spec, module)\n"
"\n"
"if spec.loader is None:\n"
" # 不支援\n"
" raise ImportError\n"
"if spec.origin is None and spec.submodule_search_locations is not None:\n"
" # 命名空間套件\n"
" sys.modules[spec.name] = module\n"
"elif not hasattr(spec.loader, 'exec_module'):\n"
" module = spec.loader.load_module(spec.name)\n"
"else:\n"
" sys.modules[spec.name] = module\n"
" try:\n"
" spec.loader.exec_module(module)\n"
" except BaseException:\n"
" try:\n"
" del sys.modules[spec.name]\n"
" except KeyError:\n"
" pass\n"
" raise\n"
"return sys.modules[spec.name]"
#: ../../reference/import.rst:377
msgid "Note the following details:"
msgstr "請注意下列細節:"
#: ../../reference/import.rst:379
msgid ""
"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` 中已存在具有給定名稱的模組物件,引入會已回傳該物件。"
#: ../../reference/import.rst:382
msgid ""
"The module will exist in :data:`sys.modules` before the loader executes the "
"module code. This is crucial because the module code may (directly or "
"indirectly) import itself; adding it to :data:`sys.modules` beforehand "
"prevents unbounded recursion in the worst case and multiple loading in the "
"best."
msgstr ""
"在載入器執行模組程式碼之前,模組將已存在於 :data:`sys.modules` 中。這一點至關"
"重要,因為模組程式碼可能會(直接或間接)引入自己;事先將其增加到 :data:`sys."
"modules` 可以預防類似無限遞迴以及多次重覆載入等情形。"
#: ../../reference/import.rst:388
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`."
msgstr ""
"如果載入失敗,只有載入失敗的模組會從 :data:`sys.modules` 中刪除。任何已存在"
"於 :data:`sys.modules` 快取中的模組,以及任何在載入失敗前成功載入的模組,都必"
"須保留在快取中。此情形與重新載入不同,在重新載入時,即使載入失敗的模組也會保"
"留在 :data:`sys.modules` 中。"
#: ../../reference/import.rst:394
msgid ""
"After the module is created but before execution, the import machinery sets "
"the import-related module attributes (\"_init_module_attrs\" in the pseudo-"
"code example above), as summarized in a :ref:`later section <import-mod-"
"attrs>`."
msgstr ""
"模組建立後、在執行之前,引入機制會設置與引入相關的模組屬性(在上面的偽程式碼"
"範例中為 \"_init_module_attrs\"),具體內容在\\ :ref:`之後的段落<import-mod-"
"attrs>`\\ 會總結。"
#: ../../reference/import.rst:399
msgid ""
"Module execution is the key moment of loading in which the module's "
"namespace gets populated. Execution is entirely delegated to the loader, "
"which gets to decide what gets populated and how."
msgstr ""
"模組執行是載入過程中的關鍵時刻,此時模組的命名空間會被新增名稱。執行過程完全"
"交由載入器處理,由其決定如何新增以及新增什麼。"
#: ../../reference/import.rst:403
msgid ""
"The module created during loading and passed to exec_module() may not be the "
"one returned at the end of import [#fnlo]_."
msgstr ""
"在載入過程中建立並傳遞給 exec_module() 的模組,可能不會是引入結束時回傳的模"
"組 [#fnlo]_。"
#: ../../reference/import.rst:406
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."
msgstr ""
"引入系統已接管載入器的模板 (boilerplate) 責任。之前是由 :meth:`importlib.abc."
"Loader.load_module` 方法執行的。"
#: ../../reference/import.rst:412
msgid "Loaders"
msgstr "載入器"
#: ../../reference/import.rst:414
msgid ""
"Module loaders provide the critical function of loading: module execution. "
"The import machinery calls the :meth:`importlib.abc.Loader.exec_module` "
"method with a single argument, the module object to execute. Any value "
"returned from :meth:`~importlib.abc.Loader.exec_module` is ignored."
msgstr ""
"模組載入器提供了載入的關鍵功能:模組執行。引入機制會以單一引數(即要執行的模"
"組物件)呼叫 :meth:`importlib.abc.Loader.exec_module` 方法。任何從 :meth:"
"`~importlib.abc.Loader.exec_module` 回傳的值都會被忽略。"
#: ../../reference/import.rst:419
msgid "Loaders must satisfy the following requirements:"
msgstr "載入器必須滿足以下要求:"
#: ../../reference/import.rst:421
msgid ""
"If the module is a Python module (as opposed to a built-in module or a "
"dynamically loaded extension), the loader should execute the module's code "
"in the module's global name space (``module.__dict__``)."
msgstr ""
"如果模組是 Python 模組(而非內建模組或動態載入的擴充),載入器應在模組的全域"
"命名空間 (``module.__dict__``\\ ) 中執行該模組的程式碼。"
#: ../../reference/import.rst:425
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."
msgstr ""
"如果載入器無法執行該模組,應引發 :exc:`ImportError`。不過,在 :meth:"
"`~importlib.abc.Loader.exec_module` 中引發的任何其他例外也會被傳播。"
#: ../../reference/import.rst:429
msgid ""
"In many cases, the finder and loader can be the same object; in such cases "
"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`` 的規格即可。"
#: ../../reference/import.rst:433
msgid ""
"Module loaders may opt in to creating the module object during loading by "
"implementing a :meth:`~importlib.abc.Loader.create_module` method. It takes "
"one argument, the module spec, and returns the new module object to use "
"during loading. ``create_module()`` does not need to set any attributes on "
"the module object. If the method returns ``None``, the import machinery "
"will create the new module itself."
msgstr ""
"模組載入器可以選擇透過實作 :meth:`~importlib.abc.Loader.create_module` 方法,"
"在載入過程中建立模組物件。該方法接受一個引數,即模組規格,並回傳在載入過程中"
"要使用的新的模組物件。``create_module()`` 不需要在模組物件上設定任何屬性。如"
"果該方法回傳 ``None``,引入機制將自行建立新的模組。"
#: ../../reference/import.rst:440
msgid "The :meth:`~importlib.abc.Loader.create_module` method of loaders."
msgstr "載入器的 :meth:`~importlib.abc.Loader.create_module` 方法。"
#: ../../reference/import.rst:443
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."
msgstr ""
":meth:`~importlib.abc.Loader.load_module` 方法已被 :meth:`~importlib.abc."
"Loader.exec_module` 取代,引入機制已承擔所有載入的模板責任。"
#: ../../reference/import.rst:448
msgid ""
"For compatibility with existing loaders, the import machinery will use the "
"``load_module()`` method of loaders if it exists and the loader does not "
"also implement ``exec_module()``. However, ``load_module()`` has been "
"deprecated and loaders should implement ``exec_module()`` instead."
msgstr ""
"為了與現有的載入器相容,引入機制會在載入器未實作 ``exec_module()`` 且存在 "
"``load_module()`` 方法時使用該方法。然而,``load_module()`` 已被棄用,載入器"
"應改為實作 ``exec_module()``。"
#: ../../reference/import.rst:453
msgid ""
"The ``load_module()`` method must implement all the boilerplate loading "
"functionality described above in addition to executing the module. All the "
"same constraints apply, with some additional clarification:"
msgstr ""
"``load_module()`` 方法除了執行模組外,還必須實作上述全部的模板載入功能。所有"
"相同的限制依然適用,並且還有一些額外的說明:"
#: ../../reference/import.rst:457
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`."
msgstr ""
"如果 :data:`sys.modules` 中已存在具有給定名稱的模組物件,載入器必須使用該模組"
"(否則 :func:`importlib.reload` 將無法正常運作)。如果命名模組不存在於 :data:"
"`sys.modules` 中,載入器必須建立一個新的模組物件並將其新增至 :data:`sys."
"modules`。"
#: ../../reference/import.rst:463
msgid ""
"The module *must* exist in :data:`sys.modules` before the loader executes "
"the module code, to prevent unbounded recursion or multiple loading."
msgstr ""
"在載入器執行模組程式碼之前,該模組\\ *必須*\\ 已存在於 :data:`sys.modules` "
"中,以防止無限遞迴或多次載入。"
#: ../../reference/import.rst:467
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."
msgstr ""
"如果載入失敗,載入器必須移除已經插入到 :data:`sys.modules` 中的任何模組,但"
"\\ **只能**\\ 移除失敗的模組(們),且僅在載入器本身明確載入這些模組時才需移"
"除。"
#: ../../reference/import.rst:472
msgid ""
"A :exc:`DeprecationWarning` is raised when ``exec_module()`` is defined but "
"``create_module()`` is not."
msgstr ""
"當 ``exec_module()`` 已定義但未定義 ``create_module()`` 時,將引發 :exc:"
"`DeprecationWarning`。"
#: ../../reference/import.rst:476
msgid ""
"An :exc:`ImportError` is raised when ``exec_module()`` is defined but "
"``create_module()`` is not."
msgstr ""
"當 ``exec_module()`` 已定義但未定義 ``create_module()`` 時,將引發 :exc:"
"`ImportError`。"
#: ../../reference/import.rst:480
msgid "Use of ``load_module()`` will raise :exc:`ImportWarning`."
msgstr "使用 ``load_module()`` 將引發 :exc:`ImportWarning`。"
#: ../../reference/import.rst:484
msgid "Submodules"
msgstr "子模組"
#: ../../reference/import.rst:486
msgid ""
"When a submodule is loaded using any mechanism (e.g. ``importlib`` APIs, the "
"``import`` or ``import-from`` statements, or built-in ``__import__()``) a "
"binding is placed in the parent module's namespace to the submodule object. "
"For example, if package ``spam`` has a submodule ``foo``, after importing "
"``spam.foo``, ``spam`` will have an attribute ``foo`` which is bound to the "
"submodule. Let's say you have the following directory structure::"
msgstr ""
"當使用任何機制(例如 ``importlib`` APIs、``import`` 或 ``import-from`` 陳述"
"式,或內建的 ``__import__()``\\ )載入子模組時,會將子模組物件繫結到父模組的"
"命名空間中。例如,如果套件 ``spam`` 有一個子模組 ``foo``,則在引入 ``spam."
"foo`` 之後,``spam`` 將擁有一個名為 ``foo`` 的屬性,該屬性繫結到子模組。我們"
"假設你有以下的目錄結構: ::"
#: ../../reference/import.rst:493
msgid ""
"spam/\n"
" __init__.py\n"
" foo.py"
msgstr ""
"spam/\n"
" __init__.py\n"
" foo.py"
#: ../../reference/import.rst:497
msgid "and ``spam/__init__.py`` has the following line in it::"
msgstr "並且 ``spam/__init__.py`` 中包含以下程式碼: ::"
#: ../../reference/import.rst:499
msgid "from .foo import Foo"
msgstr "from .foo import Foo"
#: ../../reference/import.rst:501
msgid ""
"then executing the following puts name bindings for ``foo`` and ``Foo`` in "
"the ``spam`` module::"
msgstr ""
"那麼執行以下程式碼會將 ``foo`` 和 ``Foo`` 的名稱繫結到 ``spam`` 模組中: ::"
#: ../../reference/import.rst:504
msgid ""
">>> import spam\n"
">>> spam.foo\n"
"<module 'spam.foo' from '/tmp/imports/spam/foo.py'>\n"
">>> spam.Foo\n"
"<class 'spam.foo.Foo'>"
msgstr ""
">>> import spam\n"
">>> spam.foo\n"
"<module 'spam.foo' from '/tmp/imports/spam/foo.py'>\n"
">>> spam.Foo\n"
"<class 'spam.foo.Foo'>"
#: ../../reference/import.rst:510
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."
msgstr ""
"鑑於 Python 相似的名稱繫結規則,這可能看起來有些出人意料,但這實際上是引入系"
"統的一個基本特性。不變的是如果你擁有 ``sys.modules['spam']`` 和 ``sys."
"modules['spam.foo']``\\ (就像上述引入後那樣),那麼後者必須作為前者的 "
"``foo`` 屬性出現。"
#: ../../reference/import.rst:519
msgid "Module specs"
msgstr "模組規格"
#: ../../reference/import.rst:521
msgid ""
"The import machinery uses a variety of information about each module during "
"import, especially before loading. Most of the information is common to all "
"modules. The purpose of a module's spec is to encapsulate this import-"
"related information on a per-module basis."
msgstr ""
"引入機制在引入過程中使用有關每個模組的各種資訊,尤其是在載入之前。大多數資訊"
"對所有模組來說都是通用的。模組規格的目的是以每個模組為基礎封裝這些與引入相關"
"的資訊。"
#: ../../reference/import.rst:526
msgid ""
"Using a spec during import allows state to be transferred between import "
"system components, e.g. between the finder that creates the module spec and "
"the loader that executes it. Most importantly, it allows the import "
"machinery to perform the boilerplate operations of loading, whereas without "
"a module spec the loader had that responsibility."
msgstr ""
"在引入過程中使用規格允許在引入系統的各個組件之間傳遞狀態,例如在建立模組規格"
"的尋檢器和執行該規格的載入器之間傳遞。最重要的是,這允許引入機制執行載入的模"
"板操作,而在沒有模組規格的情況下,這些操作則是載入器的責任。"
#: ../../reference/import.rst:532
msgid ""
"The module's spec is exposed as :attr:`module.__spec__`. Setting :attr:`!"
"__spec__` appropriately applies equally to :ref:`modules initialized during "
"interpreter startup <programs>`. The one exception is ``__main__``, where :"
"attr:`!__spec__` is :ref:`set to None in some cases <main_spec>`."
msgstr ""
"模組的規格以 :attr:`module.__spec__` 的形式公開。適當地設定 :attr:`!"
"__spec__` 同樣適用於\\ :ref:`在直譯器啟動期間初始化的模組 <programs>`。唯一的"
"例外是 ``__main__``,其中 :attr:`!__spec__` 會\\ :ref:`在某些情況下被設定成 "
"None <main_spec>`。"