@@ -470,35 +470,35 @@ msgstr ""
470470msgid ""
471471"Users of the package can import individual modules from the package, for "
472472"example::"
473- msgstr ""
473+ msgstr "包的用户可以从包中导入单个模块,例如:: "
474474
475475#: ../../tutorial/modules.rst:440
476476msgid ""
477477"This loads the submodule :mod:`sound.effects.echo`. It must be referenced "
478478"with its full name. ::"
479- msgstr ""
479+ msgstr "这会加载子模块 :mod:`sound.effects.echo` 。但引用它时必须使用它的全名。 :: "
480480
481481#: ../../tutorial/modules.rst:445
482482msgid "An alternative way of importing the submodule is::"
483- msgstr ""
483+ msgstr "导入子模块的另一种方法是 :: "
484484
485485#: ../../tutorial/modules.rst:449
486486msgid ""
487487"This also loads the submodule :mod:`echo`, and makes it available without "
488488"its package prefix, so it can be used as follows::"
489- msgstr ""
489+ msgstr "这也会加载子模块 :mod:`echo` ,并使其在没有包前缀的情况下可用,因此可以按如下方式使用:: "
490490
491491#: ../../tutorial/modules.rst:454
492492msgid ""
493493"Yet another variation is to import the desired function or variable "
494494"directly::"
495- msgstr ""
495+ msgstr "另一种形式是直接导入所需的函数或变量:: "
496496
497497#: ../../tutorial/modules.rst:458
498498msgid ""
499499"Again, this loads the submodule :mod:`echo`, but this makes its function "
500500":func:`echofilter` directly available::"
501- msgstr ""
501+ msgstr "同样,这也会加载子模块 :mod:`echo`,但这使它的功能 :func:`echofilter` 直接可用:: "
502502
503503#: ../../tutorial/modules.rst:463
504504msgid ""
@@ -509,6 +509,9 @@ msgid ""
509509"it is a module and attempts to load it. If it fails to find it, an "
510510":exc:`ImportError` exception is raised."
511511msgstr ""
512+ "请注意,当使用 ``from package import item`` "
513+ "时,该项可以是包的子模块(或子包),也可以是包中定义的其他名称,如函数,类或变量。 ``import`` "
514+ "语句首先测试是否在包中定义了该项;如果没有,它假定它是一个模块并尝试加载它。如果找不到它,则引发 :exc:`ImportError` 异常。"
512515
513516#: ../../tutorial/modules.rst:470
514517msgid ""
@@ -517,10 +520,12 @@ msgid ""
517520" a package but can't be a class or function or variable defined in the "
518521"previous item."
519522msgstr ""
523+ "相反,当使用 ``import item.subitem.subsubitem`` "
524+ "这样的语法时,除了last之外的每个项都必须是一个包;最后一项可以是模块或包,但不能是前一项中定义的类或函数或变量。"
520525
521526#: ../../tutorial/modules.rst:479
522527msgid "Importing \\ * From a Package"
523- msgstr ""
528+ msgstr "从包中导入 \\ * "
524529
525530#: ../../tutorial/modules.rst:483
526531msgid ""
@@ -548,7 +553,7 @@ msgstr ""
548553msgid ""
549554"This would mean that ``from sound.effects import *`` would import the three "
550555"named submodules of the :mod:`sound` package."
551- msgstr ""
556+ msgstr "这意味着 ``from sound.effects import *`` 将导入 :mod:`sound` 包的三个命名子模块。 "
552557
553558#: ../../tutorial/modules.rst:504
554559msgid ""
@@ -562,6 +567,9 @@ msgid ""
562567"package that were explicitly loaded by previous :keyword:`import` "
563568"statements. Consider this code::"
564569msgstr ""
570+ "如果没有定义 ``__all__``,``from sound.effects import *`` 语句*不*会从包 "
571+ ":mod:`sound.effects` 中导入所有子模块到当前命名空间;它只确保导入了包 :mod:`sound.effects` (可能运行任何在 "
572+ ":file:`__init__.py` 中的初始化代码),然后导入包中定义的任何名称。"
565573
566574#: ../../tutorial/modules.rst:517
567575msgid ""
@@ -570,13 +578,15 @@ msgid ""
570578"package when the ``from...import`` statement is executed. (This also works "
571579"when ``__all__`` is defined.)"
572580msgstr ""
581+ "在这个例子中, :mod:`echo` 和 :mod:`surround` 模块是在执行 ``from...import`` "
582+ "时导入到当前命名空间中的,它们定义在 :mod:`sound.effects` 包中。(这在定义了 ``__all__`` 时也有效。)"
573583
574584#: ../../tutorial/modules.rst:522
575585msgid ""
576586"Although certain modules are designed to export only names that follow "
577587"certain patterns when you use ``import *``, it is still considered bad "
578588"practice in production code."
579- msgstr ""
589+ msgstr "虽然某些模块被设计为在使用 ``import *`` 时只导出遵循某些模式的名称,但在生产代码中它仍然被认为是不好的做法。 "
580590
581591#: ../../tutorial/modules.rst:526
582592msgid ""
@@ -585,10 +595,12 @@ msgid ""
585595"importing module needs to use submodules with the same name from different "
586596"packages."
587597msgstr ""
598+ "请记住,使用 ``from package import specific_submodule`` "
599+ "没有任何问题!实际上,除非导入模块需要使用来自不同包的同名子模块,否则这是推荐的表示法。"
588600
589601#: ../../tutorial/modules.rst:533
590602msgid "Intra-package References"
591- msgstr ""
603+ msgstr "子包参考 "
592604
593605#: ../../tutorial/modules.rst:535
594606msgid ""
@@ -598,6 +610,9 @@ msgid ""
598610":mod:`sound.filters.vocoder` needs to use the :mod:`echo` module in the "
599611":mod:`sound.effects` package, it can use ``from sound.effects import echo``."
600612msgstr ""
613+ "当包被构造成子包时(与示例中的 :mod:`sound` 包一样),您可以使用绝对导入来引用兄弟包的子模块。例如,如果模块 "
614+ ":mod:`sound.filters.vocoder` 需要在 :mod:`sound.effects` 包中使用 :mod:`echo` "
615+ "模块,它可以使用 ``from sound.effects import echo`` 。"
601616
602617#: ../../tutorial/modules.rst:541
603618msgid ""
@@ -606,6 +621,8 @@ msgid ""
606621"current and parent packages involved in the relative import. From the "
607622":mod:`surround` module for example, you might use::"
608623msgstr ""
624+ "您还可以使用import语句的 ``from module import name`` "
625+ "形式编写相对导入。这些导入使用前导点来指示相对导入中涉及的当前和父包。例如,从 :mod:`surround` 模块,您可以使用::"
609626
610627#: ../../tutorial/modules.rst:550
611628msgid ""
@@ -614,10 +631,12 @@ msgid ""
614631"intended for use as the main module of a Python application must always use "
615632"absolute imports."
616633msgstr ""
634+ "请注意,相对导入是基于当前模块的名称进行导入的。由于主模块的名称总是 ``\" __main__\" `` "
635+ ",因此用作Python应用程序主模块的模块必须始终使用绝对导入。"
617636
618637#: ../../tutorial/modules.rst:556
619638msgid "Packages in Multiple Directories"
620- msgstr ""
639+ msgstr "多个目录中的包 "
621640
622641#: ../../tutorial/modules.rst:558
623642msgid ""
@@ -627,12 +646,14 @@ msgid ""
627646"This variable can be modified; doing so affects future searches for modules "
628647"and subpackages contained in the package."
629648msgstr ""
649+ "包支持另一个特殊属性 :attr:`__path__` 。这被初始化为一个列表,其中包含在执行该文件中的代码之前保存包的文件 "
650+ ":file:`__init__.py` 的目录的名称。这个变量可以修改;做会影响搜索包中包含的模块和子包。"
630651
631652#: ../../tutorial/modules.rst:564
632653msgid ""
633654"While this feature is not often needed, it can be used to extend the set of "
634655"modules found in a package."
635- msgstr ""
656+ msgstr "虽然通常不需要此功能,但它可用于扩展程序包中的模块集。 "
636657
637658#: ../../tutorial/modules.rst:569
638659msgid "Footnotes"
0 commit comments