@@ -1832,7 +1832,7 @@ msgstr "更好的方法是在所有类上定义一个 ``search()`` 方法,然
18321832
18331833#: ../../faq/programming.rst:1479
18341834msgid "What is delegation?"
1835- msgstr "什么是代理 ?"
1835+ msgstr "什么是委托 ?"
18361836
18371837#: ../../faq/programming.rst:1481
18381838msgid ""
@@ -1842,15 +1842,15 @@ msgid ""
18421842"implementation of the method you're interested in changing and delegates all"
18431843" other methods to the corresponding method of ``x``."
18441844msgstr ""
1845- "代理是一种面向对象的技术 (也称为设计模式)。假设您有一个对象 ``x`` "
1846- "并且想要改变其中一个方法的行为。 您可以创建一个新类,它提供您感兴趣的方法的新实现,并将所有其他方法委托给 ``x`` 的相应方法。"
1845+ "委托是一种面向对象的技巧 (也称为设计模式)。 假设您有一个对象 ``x`` 并且想要改变其中一个方法的行为。 "
1846+ "您可以创建一个新类,它提供您感兴趣的方法的新实现,并将所有其他方法委托给 ``x`` 的相应方法。"
18471847
18481848#: ../../faq/programming.rst:1487
18491849msgid ""
18501850"Python programmers can easily implement delegation. For example, the "
18511851"following class implements a class that behaves like a file but converts all"
18521852" written data to uppercase::"
1853- msgstr "Python程序员可以轻松实现代理。 例如,以下类实现了一个类,该类的行为类似于文件,但将所有写入的数据转换为大写:"
1853+ msgstr "Python程序员可以轻松实现委托。 例如,以下类实现了一个类,该类的行为类似于文件,但将所有写入的数据转换为大写:"
18541854
18551855#: ../../faq/programming.rst:1502
18561856msgid ""
@@ -1861,6 +1861,9 @@ msgid ""
18611861"the ``__getattr__`` method; consult :ref:`the language reference <attribute-"
18621862"access>` for more information about controlling attribute access."
18631863msgstr ""
1864+ "在这里 ``UpperOut`` 类重新定义了 ``write()`` 方法在调用下层的 ``self.__outfile.write()`` "
1865+ "方法之前将参数字符串转换为大写形式。 所有其他方法都被委托给下层的 ``self.__outfile`` 对象。 委托是通过 "
1866+ "``__getattr__`` 方法来完成的;请参阅 :ref:`语言参考 <attribute-access>` 了解有关控制属性访问的更多信息。"
18641867
18651868#: ../../faq/programming.rst:1509
18661869msgid ""
@@ -1870,12 +1873,15 @@ msgid ""
18701873"implementation of :meth:`__setattr__` is roughly equivalent to the "
18711874"following::"
18721875msgstr ""
1876+ "请注意对于更一般的情况来说,委托可能包含更多细节问题。 当某些属性既需要读取又需要设置时,类还必须定义 :meth:`__setattr__` "
1877+ "方法,并且这样做必须小心谨慎。 :meth:`__setattr__` 的基本实现大致相当于以下代码::"
18731878
18741879#: ../../faq/programming.rst:1520
18751880msgid ""
18761881"Most :meth:`__setattr__` implementations must modify ``self.__dict__`` to "
18771882"store local state for self without causing an infinite recursion."
18781883msgstr ""
1884+ "大多数 :meth:`__setattr__` 实现必须修改 ``self.__dict__`` 来为自身保存局部状态而又不至于造成无限递归。"
18791885
18801886#: ../../faq/programming.rst:1525
18811887msgid ""
@@ -1936,6 +1942,8 @@ msgid ""
19361942"``isinstance(c, C)`` holds, unless overridden by ``c`` itself or by some "
19371943"class on the base-class search path from ``c.__class__`` back to ``C``."
19381944msgstr ""
1945+ "对于任意 ``c`` 来说只要 ``isinstance(c, C)`` 为真,则 ``c.count`` 同样也指向 ``C.count``,除非被 "
1946+ "``c`` 自身,或者从 ``c.__class__`` 回到 ``C`` 的基类搜索路径上的某个类所重载。"
19391947
19401948#: ../../faq/programming.rst:1579
19411949msgid ""
@@ -1944,6 +1952,8 @@ msgid ""
19441952" Rebinding of a class-static data name must always specify the class "
19451953"whether inside a method or not::"
19461954msgstr ""
1955+ "注意:在 C 的某个方法内部,像 ``self.count = 42`` 这样的赋值将在 ``self`` 自身的字典中新建一个名为 \" count\" "
1956+ " 的不相关实例。 想要重新绑定类静态数据名称就必须总是指明类名,无论是在方法内部还是外部::"
19471957
19481958#: ../../faq/programming.rst:1586
19491959msgid "Static methods are possible::"
@@ -2006,6 +2016,9 @@ msgid ""
20062016"``classname`` is the current class name with any leading underscores "
20072017"stripped."
20082018msgstr ""
2019+ "以双下划线打头的变量会被“更名”以提供一种定义类私有变量的简单而有效的方式。 任何形式为 ``__spam`` "
2020+ "的标识符(至少前缀两个下划线,至多后缀一个下划线)文本会被替换为 ``_classname__spam``,其中 ``classname`` "
2021+ "为去除了全部前缀下划线的当前类名称。"
20092022
20102023#: ../../faq/programming.rst:1648
20112024msgid ""
0 commit comments