@@ -11,7 +11,7 @@ msgid ""
11
11
msgstr ""
12
12
"Project-Id-Version : Python 3.10\n "
13
13
"Report-Msgid-Bugs-To : \n "
14
- "POT-Creation-Date : 2024-07-12 15:50 +0000\n "
14
+ "POT-Creation-Date : 2024-07-19 16:03 +0000\n "
15
15
"PO-Revision-Date : 2022-11-05 17:23+0000\n "
16
16
"
Last-Translator :
Rafael Fontenelle <[email protected] >, 2024\n "
17
17
"Language-Team : Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n "
@@ -488,12 +488,16 @@ msgid ""
488
488
":attr:`~object.__slots__` to limit the legal attributes to a particular set"
489
489
" of names. An example will make this clear::"
490
490
msgstr ""
491
+ "最后,可以使用新的类属性 :attr:`~object.__slots__` 来限制对象上可以引用的属性列表。Python "
492
+ "对象通常非常动态,可以随时通过简单地 ``obj.new_attr=1`` 来定义一个新属性。新式类可以定义一个名为 "
493
+ ":attr:`~object.__slots__` 的类属性,以将合法属性限制为特定的一组名称。一个例子可以更清楚地说明这一点:"
491
494
492
495
#: ../../whatsnew/2.2.rst:385
493
496
msgid ""
494
497
"Note how you get an :exc:`AttributeError` on the attempt to assign to an "
495
498
"attribute not listed in :attr:`~object.__slots__`."
496
499
msgstr ""
500
+ "注意,当尝试为未列在 :attr:`~object.__slots__` 中的属性赋值时,会引发 :exc:`AttributeError`。"
497
501
498
502
#: ../../whatsnew/2.2.rst:392
499
503
msgid "Related Links"
@@ -529,6 +533,10 @@ msgid ""
529
533
"explode. Both PEPs were written and implemented by Guido van Rossum, with "
530
534
"substantial assistance from the rest of the Zope Corp. team."
531
535
msgstr ""
536
+ "接下来,有两个相关的 PEP,即 :pep:`252` 和 :pep:`253`。:pep:`252` 标题为“使类型更像类”,涵盖了描述符 "
537
+ "API。:pep:`253` 标题为“内置类型的子类型化”,描述了使内置对象可以进行子类型化的类型对象的更改。:pep:`253` 是这两个 PEP "
538
+ "中更复杂的一个,在某些点上,必要的类型和元类型解释可能会让人感到头疼。两个 PEP 都由 Guido van Rossum 编写和实现,并得到了 "
539
+ "Zope Corp. 团队其他成员的实质性协助。"
532
540
533
541
#: ../../whatsnew/2.2.rst:412
534
542
msgid ""
@@ -537,6 +545,8 @@ msgid ""
537
545
"should only resort to it after all other avenues have been exhausted, "
538
546
"including posting a question to python-list or python-dev."
539
547
msgstr ""
548
+ "最后,还有最终的权威来源:源代码。大部分类型处理的机制都在 :file:`Objects/typeobject.c` "
549
+ "中,但只有在所有其他途径都用尽之后,包括在 python-list 或 python-dev 上发布问题后,才应求助于源代码。"
540
550
541
551
#: ../../whatsnew/2.2.rst:421
542
552
msgid "PEP 234: Iterators"
@@ -597,6 +607,8 @@ msgid ""
597
607
"When there are no more values to be returned, calling :meth:`next` should "
598
608
"raise the :exc:`StopIteration` exception. ::"
599
609
msgstr ""
610
+ "总结一下,迭代器实际上做什么?它们有一个必需的方法 :meth:`next`,该方法不接受任何参数并返回下一个值。当没有更多的值可以返回时,调用 "
611
+ ":meth:`next` 应该引发 :exc:`StopIteration` 异常。以下是一个简单的例子来说明迭代器的工作原理:"
600
612
601
613
#: ../../whatsnew/2.2.rst:478
602
614
msgid ""
@@ -615,7 +627,7 @@ msgid ""
615
627
"Iterator support has been added to some of Python's basic types. Calling "
616
628
":func:`iter` on a dictionary will return an iterator which loops over its "
617
629
"keys::"
618
- msgstr ""
630
+ msgstr "迭代器支持已被添加到Python的一些基本类型中。对字典调用 :func:`iter` 会返回一个迭代器,该迭代器遍历字典的键,如下所示: "
619
631
620
632
#: ../../whatsnew/2.2.rst:512
621
633
msgid ""
@@ -674,6 +686,9 @@ msgid ""
674
686
"This is what generators provide; they can be thought of as resumable "
675
687
"functions."
676
688
msgstr ""
689
+ "你一定熟悉在Python或C语言中函数调用的工作方式。当你调用一个函数时,它会获得一个私有命名空间,在这个命名空间中创建其局部变量。当函数执行到 "
690
+ ":keyword:`return` "
691
+ "语句时,这些局部变量会被销毁,并将结果值返回给调用者。稍后对同一个函数的调用将获得一套全新的局部变量。但,如果局部变量在函数退出时不被丢弃呢?如果你可以在函数停止的地方稍后恢复执行呢?这就是生成器所提供的功能;它们可以被视为可恢复的函数。"
677
692
678
693
#: ../../whatsnew/2.2.rst:556
679
694
msgid "Here's the simplest example of a generator function::"
@@ -689,6 +704,9 @@ msgid ""
689
704
"import generators`` statement near the top of the module's source code. In "
690
705
"Python 2.3 this statement will become unnecessary."
691
706
msgstr ""
707
+ "一个新的关键字 :keyword:`yield` 被引入用于生成器。任何包含 :keyword:`!yield` "
708
+ "语句的函数都是生成器函数;这由Python的字节码编译器检测到,并因此对函数进行特殊编译。由于引入了一个新的关键字,生成器必须通过在模块的源代码顶部附近包含一条"
709
+ " ``from __future__ import generators`` 语句来显式启用。在Python 2.3中,这条语句将变得不再必要。"
692
710
693
711
#: ../../whatsnew/2.2.rst:570
694
712
msgid ""
@@ -706,6 +724,12 @@ msgid ""
706
724
" full explanation of the interaction between :keyword:`!yield` and "
707
725
"exceptions.)"
708
726
msgstr ""
727
+ "当你调用一个生成器函数时,它不会返回单个值;相反,它返回一个支持迭代器协议的生成器对象。在执行 :keyword:`yield` 语句时,生成器输出 "
728
+ "``i`` 的值,类似于 :keyword:`return` 语句。:keyword:`!yield` 和 :keyword:`!return` "
729
+ "语句之间的重大区别在于,当到达 :keyword:`!yield` 时,生成器的执行状态被挂起,并且局部变量被保留。在下一次调用生成器的 "
730
+ "``next()`` 方法时,函数将立即在 :keyword:`!yield` 语句之后恢复执行。(由于复杂的原因,:keyword:`!yield` "
731
+ "语句不允许在 :keyword:`try` ... :keyword:`finally` 语句的 :keyword:`!try` 块中使用;请阅读 "
732
+ ":pep:`255` 以获得关于 :keyword:`!yield` 和异常交互的详细解释。)"
709
733
710
734
#: ../../whatsnew/2.2.rst:583
711
735
msgid "Here's a sample usage of the :func:`generate_ints` generator::"
@@ -728,6 +752,10 @@ msgid ""
728
752
" indicated by raising :exc:`StopIteration` manually, or by just letting the "
729
753
"flow of execution fall off the bottom of the function."
730
754
msgstr ""
755
+ "在生成器函数内部, :keyword:`return` "
756
+ "语句只能不带值使用,并表示值的生成过程结束;之后,生成器不能再返回任何值。在生成器函数内部,带值的 :keyword:`!return`,例如 "
757
+ "``return 5``,是语法错误。生成器结果的结束也可以通过手动引发 :exc:`StopIteration` "
758
+ "异常来指示,或者只是让执行流自然地从函数底部流出。"
731
759
732
760
#: ../../whatsnew/2.2.rst:611
733
761
msgid ""
@@ -741,6 +769,10 @@ msgid ""
741
769
"examples. The simplest one implements an in-order traversal of a tree using"
742
770
" generators recursively. ::"
743
771
msgstr ""
772
+ "你可以通过编写自己的类并将生成器的所有局部变量存储为实例变量,手动实现生成器的效果。例如,返回一个整数列表可以通过将 ``self.count`` "
773
+ "设置为0,并让 :meth:`next` 方法递增 ``self.count`` "
774
+ "并返回它。然而,对于一个中等复杂的生成器,编写一个相应的类将会更加混乱。:file:`Lib/test/test_generators.py` "
775
+ "包含了一些更有趣的例子。其中最简单的一个使用生成器递归实现了树的中序遍历:"
744
776
745
777
#: ../../whatsnew/2.2.rst:629
746
778
msgid ""
0 commit comments