-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathimport.po
More file actions
1800 lines (1593 loc) · 95 KB
/
import.po
File metadata and controls
1800 lines (1593 loc) · 95 KB
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
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001-2025, Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# python-doc bot, 2025
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.11\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-03 15:28+0000\n"
"PO-Revision-Date: 2025-09-22 16:51+0000\n"
"Last-Translator: python-doc bot, 2025\n"
"Language-Team: Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: zh_CN\n"
"Plural-Forms: nplurals=1; plural=0;\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` 语句是唤起导入机制的最常用方式,但不是唯一的方式。 :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__` 的直接调用将仅执行模块搜索以及在找到时的模块创建操作。 不过也可能产生某些副作用,例如导入父包和更新各种缓存 "
"(包括 :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 会搜索该模块,如果找到就创建一个 module 对象 [#fnmo]_ 并初始化它。 "
"如果指定名称的模块未找到,则会引发 :exc:`ModuleNotFoundError`。 当唤起导入机制时,Python "
"会实现多种策略来搜索指定名称的模块。 这些策略可以通过使用使用下文所描述的多种钩子来加以修改和扩展。"
#: ../../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: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>` 构成的,每个部分为父包增加一个子包。 各个部分可能处于文件系统的不同位置。 部分也可能处于"
" zip 文件中、网络上,或者 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`` 相邻。 "
"在这种情况下,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>`。 "
"此名称可以来自 :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 "查找器和加载器"
#: ../../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>` —— "
"它们在确定能加载所需的模块时会返回其自身。"
#: ../../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` 是一个由文件系统路径或 zip 文件组成的位置列表。 "
"它还可以扩展为搜索任意可定位资源,例如由 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 "导入钩子"
#: ../../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 "导入机制被设计为可扩展;其中的基本机制是 *导入钩子*。 导入钩子有两种类型: *元钩子* 和 *导入路径钩子*。"
#: ../../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:`~importlib.abc.MetaPathFinder.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 ""
#: ../../reference/import.rst:332
msgid ""
"Use of :meth:`~importlib.abc.MetaPathFinder.find_module` by the import "
"system now raises :exc:`ImportWarning`."
msgstr ""
"导入系统使用 :meth:`~importlib.abc.MetaPathFinder.find_module` 现在将会引发 "
":exc:`ImportWarning`。"
#: ../../reference/import.rst:338
msgid "Loading"
msgstr "加载"
#: ../../reference/import.rst:340
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:374
msgid "Note the following details:"
msgstr "请注意以下细节:"
#: ../../reference/import.rst:376
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:379
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:385
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:391
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:396
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:400
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:403
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 ""
"导入系统已经接管了加载器建立样板的责任。 这些在以前是由 :meth:`importlib.abc.Loader.load_module` "
"方法来执行的。"
#: ../../reference/import.rst:409
msgid "Loaders"
msgstr "加载器"
#: ../../reference/import.rst:411
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:416
msgid "Loaders must satisfy the following requirements:"
msgstr "加载器必须满足下列要求:"
#: ../../reference/import.rst:418
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:422
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:426
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:430
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:437
msgid "The :meth:`~importlib.abc.Loader.create_module` method of loaders."
msgstr "加载器的 :meth:`~importlib.abc.Loader.create_module` 方法。"
#: ../../reference/import.rst:440
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:445
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 ""
"为了与现有的加载器兼容,导入机制会使用导入器的 ``load_module()`` 方法,如果它存在且导入器也未实现 "
"``exec_module()``。 但是,``load_module()`` 现已弃用,加载器应该转而实现 ``exec_module()``。"
#: ../../reference/import.rst:450
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:454
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:460
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:464
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:469
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:473
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:477
msgid "Use of ``load_module()`` will raise :exc:`ImportWarning`."
msgstr "使用 ``load_module()`` 将引发 :exc:`ImportWarning`。"
#: ../../reference/import.rst:481
msgid "Submodules"
msgstr "子模块"
#: ../../reference/import.rst:483
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`` API, ``import`` 及 ``import-from`` 语句或者内置的 "
"``__import__()``) 加载一个子模块时,父模块的命名空间中会添加一个对子模块对象的绑定。 例如,如果包 ``spam`` 有一个子模块 "
"``foo``,则在导入 ``spam.foo`` 之后,``spam`` 将具有一个 绑定到相应子模块的 ``foo`` 属性。 "
"假如现在有如下的目录结构::"
#: ../../reference/import.rst:494
msgid "and ``spam/__init__.py`` has the following line in it::"
msgstr "并且 ``spam/__init__.py`` 中有如下几行内容::"
#: ../../reference/import.rst:498
msgid ""
"then executing the following puts name bindings for ``foo`` and ``Foo`` in "
"the ``spam`` module::"
msgstr "那么执行如下代码将把 ``foo`` 和 ``Foo`` 的名称绑定添加到 ``spam`` 模块中::"
#: ../../reference/import.rst:507
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:514
msgid "Module spec"
msgstr "模块规格说明"
#: ../../reference/import.rst:516
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:521
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:527
msgid ""
"The module's spec is exposed as the ``__spec__`` attribute on a module "
"object. See :class:`~importlib.machinery.ModuleSpec` for details on the "
"contents of the module spec."
msgstr ""
"模块的规格说明会作为模块对象的 ``__spec__`` 属性对外公开。 有关模块规格的详细内容请参阅 "
":class:`~importlib.machinery.ModuleSpec`。"
#: ../../reference/import.rst:536
msgid "Import-related module attributes"
msgstr "导入相关的模块属性"
#: ../../reference/import.rst:538
msgid ""
"The import machinery fills in these attributes on each module object during "
"loading, based on the module's spec, before the loader executes the module."
msgstr "导入机制会在加载期间会根据模块的规格说明填充每个模块对象的这些属性,并在加载器执行模块之前完成。"
#: ../../reference/import.rst:544
msgid ""
"The ``__name__`` attribute must be set to the fully qualified name of the "
"module. This name is used to uniquely identify the module in the import "
"system."
msgstr "``__name__`` 属性必须被设为模块的完整限定名称。 此名称被用来在导入系统中唯一地标识模块。"
#: ../../reference/import.rst:550
msgid ""
"The ``__loader__`` attribute must be set to the loader object that the "
"import machinery used when loading the module. This is mostly for "
"introspection, but can be used for additional loader-specific functionality,"
" for example getting data associated with a loader."
msgstr ""
"``__loader__`` 属性必须被设为导入系统在加载模块时使用的加载器对象。 "
"这主要是用于内省,但也可用于额外的加载器专用功能,例如获取关联到加载器的数据。"
#: ../../reference/import.rst:557
msgid ""
"The module's ``__package__`` attribute must be set. Its value must be a "
"string, but it can be the same value as its ``__name__``. When the module "
"is a package, its ``__package__`` value should be set to its ``__name__``. "
"When the module is not a package, ``__package__`` should be set to the empty"
" string for top-level modules, or for submodules, to the parent package's "
"name. See :pep:`366` for further details."
msgstr ""
"模块的 ``__package__`` 属性必须设定。 其取值必须为一个字符串,但可以与 ``__name__`` 取相同的值。 当模块是包时,其 "
"``__package__`` 值应该设为其 ``__name__`` 值。 当模块不是包时,对于最高层级模块 ``__package__`` "
"应该设为空字符串,对于子模块则应该设为其父包名。 更多详情可参阅 :pep:`366`。"
#: ../../reference/import.rst:565
msgid ""
"This attribute is used instead of ``__name__`` to calculate explicit "
"relative imports for main modules, as defined in :pep:`366`. It is expected "
"to have the same value as ``__spec__.parent``."
msgstr ""
"该属性取代 ``__name__`` 被用来为主模块计算显式相对导入,相关定义见 :pep:`366`。 预期它与 "
"``__spec__.parent`` 具有相同的值。"
#: ../../reference/import.rst:569
msgid ""
"The value of ``__package__`` is expected to be the same as "
"``__spec__.parent``."
msgstr "``__package__`` 预期与 ``__spec__.parent`` 具有相同的值。"
#: ../../reference/import.rst:575
msgid ""
"The ``__spec__`` attribute must be set to the module spec that was used when"
" importing the module. Setting ``__spec__`` appropriately applies equally to"
" :ref:`modules initialized during interpreter startup <programs>`. The one "
"exception is ``__main__``, where ``__spec__`` is :ref:`set to None in some "
"cases <main_spec>`."
msgstr ""
"``__spec__`` 属性必须设为在导入模块时要使用的模块规格说明。 对 ``__spec__`` 的正确设定将同时作用于 "
":ref:`解释器启动期间初始化的模块 <programs>`。 唯一的例外是 ``__main__``,其中的 ``__spec__`` 会 "
":ref:`在某些情况下设为 None <main_spec>`."
#: ../../reference/import.rst:581
msgid ""
"When ``__package__`` is not defined, ``__spec__.parent`` is used as a "
"fallback."
msgstr "当 ``__package__`` 未定义时, ``__spec__.parent`` 会被用作回退项。"
#: ../../reference/import.rst:586
msgid ""
"``__spec__.parent`` is used as a fallback when ``__package__`` is not "
"defined."
msgstr "当 ``__package__`` 未定义时,``__spec__.parent`` 会被用作回退项。"
#: ../../reference/import.rst:592
msgid ""
"If the module is a package (either regular or namespace), the module "
"object's ``__path__`` attribute must be set. The value must be iterable, "
"but may be empty if ``__path__`` has no further significance. If "
"``__path__`` is not empty, it must produce strings when iterated over. More "
"details on the semantics of ``__path__`` are given :ref:`below <package-"
"path-rules>`."
msgstr ""
"如果模块为包(不论是正规包还是命名空间包),则必须设置模块对象的 ``__path__`` 属性。 属性值必须为可迭代对象,但如果 "
"``__path__`` 没有进一步的用处则可以为空。 如果 ``__path__`` 不为空,则在迭代时它应该产生字符串。 有关 "
"``__path__`` 语义的更多细节将在 :ref:`下文 <package-path-rules>` 中给出。"
#: ../../reference/import.rst:599
msgid "Non-package modules should not have a ``__path__`` attribute."
msgstr "不是包的模块不应该具有 ``__path__`` 属性。"
#: ../../reference/import.rst:604
msgid ""
"``__file__`` is optional (if set, value must be a string). It indicates the "
"pathname of the file from which the module was loaded (if loaded from a "
"file), or the pathname of the shared library file for extension modules "
"loaded dynamically from a shared library. It might be missing for certain "
"types of modules, such as C modules that are statically linked into the "
"interpreter, and the import system may opt to leave it unset if it has no "
"semantic meaning (e.g. a module loaded from a database)."
msgstr ""
"``__file__`` 是可选项(如果设置,其值必须为字符串)。 "
"它指明要载入的模块所在文件的路径(如果是从文件载入),或者对于从共享库动态载入的扩展模块来说则是共享库文件的路径。 "
"它对特定类型的模块来说可能是缺失的,例如静态链接到解释器中的 C 模块,并且导入系统也可能会在它没有语法意义时选择不设置它(例如是从数据库导入的模块)。"
#: ../../reference/import.rst:613
msgid ""
"If ``__file__`` is set then the ``__cached__`` attribute might also be set,"
" which is the path to any compiled version of the code (e.g. byte-compiled "
"file). The file does not need to exist to set this attribute; the path can "
"simply point to where the compiled file would exist (see :pep:`3147`)."
msgstr ""
"如果设置了 ``__file__`` 则 ``__cached__`` 属性也可能会被设置,它是指向任何代码的已编译版本的路径(即字节码文件)。 "
"设置此属性并不需要存在相应的文件;该路径可以简单地指向已编译文件将要存在的位置 (参见 :pep:`3147`)。"
#: ../../reference/import.rst:619
msgid ""
"Note that ``__cached__`` may be set even if ``__file__`` is not set. "
"However, that scenario is quite atypical. Ultimately, the loader is what "
"makes use of the module spec provided by the finder (from which ``__file__``"
" and ``__cached__`` are derived). So if a loader can load from a cached "
"module but otherwise does not load from a file, that atypical scenario may "
"be appropriate."
msgstr ""
"请注意 ``__cached__`` 即使在未设置 ``__file__`` 时也可能会被设置。 但是,那样的场景是非典型的。 最终,加载器会是查找器 "
"(``__file__`` 和 ``__cached__`` 也是自它派生的) 所提供的模块规格说明的使用方。 "
"因此如果一个加载器可以从缓存加载模块但是不能从文件加载,那样的非典型场景就是适当的。"
#: ../../reference/import.rst:629
msgid "module.__path__"
msgstr "module.__path__"
#: ../../reference/import.rst:631
msgid ""
"By definition, if a module has a ``__path__`` attribute, it is a package."
msgstr "根据定义,如果一个模块具有 ``__path__`` 属性,它就是包。"
#: ../../reference/import.rst:633
msgid ""
"A package's ``__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, ``__path__`` is typically much more constrained than"
" :data:`sys.path`."
msgstr ""
"包的 ``__path__`` 属性会在导入其子包期间被使用。 在导入机制内部,它的功能与 :data:`sys.path` "
"基本相同,即在导入期间提供一个模块搜索位置列表。 但是,``__path__`` 通常会比 :data:`sys.path` 受到更多限制。"
#: ../../reference/import.rst:639
msgid ""
"``__path__`` must be an iterable of strings, but it may be empty. The same "
"rules used for :data:`sys.path` also apply to a package's ``__path__``, and "
":data:`sys.path_hooks` (described below) are consulted when traversing a "
"package's ``__path__``."
msgstr ""
"``__path__`` 必须是由字符串组成的可迭代对象,但它也可以为空。 作用于 :data:`sys.path` 的规则同样适用于包的 "
"``__path__``,并且 :data:`sys.path_hooks` (见下文) 会在遍历包的 ``__path__`` 时被查询。"
#: ../../reference/import.rst:644
msgid ""
"A package's ``__init__.py`` file may set or alter the package's ``__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 "
"``__path__`` manipulation code; the import machinery automatically sets "
"``__path__`` correctly for the namespace package."
msgstr ""
"包的 ``__init__.py`` 文件可以设置或更改包的 ``__path__`` 属性,而且这是在 :pep:`420` "
"之前实现命名空间包的典型方式。 随着 :pep:`420` 的引入,命名空间包不再需要提供仅包含 ``__path__`` 操控代码的 "
"``__init__.py`` 文件;导入机制会自动为命名空间包正确地设置 ``__path__``。"
#: ../../reference/import.rst:652
msgid "Module reprs"
msgstr "模块的 repr"