@@ -477,6 +477,8 @@ msgid ""
477477"greater flexibility. In that case, arguments given to the class "
478478"instantiation operator are passed on to :meth:`!__init__`. For example, ::"
479479msgstr ""
480+ "当然,:meth:`~object.__init__` 方法还有一些参数用于实现更高的灵活性。 在这种情况下,提供给类实例化运算符的参数将被传递给 "
481+ ":meth:`!__init__`。 例如, ::"
480482
481483#: ../../tutorial/classes.rst:322
482484msgid "Instance Objects"
@@ -498,6 +500,9 @@ msgid ""
498500"following piece of code will print the value ``16``, without leaving a "
499501"trace::"
500502msgstr ""
503+ "*数据属性* 对应于 Smalltalk 中的“实例变量”,以及 C++ 中的“数据成员”。 "
504+ "数据属性不需要声明;就像局部变量一样,它们将在首次被赋值时产生。 举例来说,如果 ``x`` 是上面创建的 :class:`!MyClass` "
505+ "的实例,则以下代码将打印数值 ``16``,且不保留任何追踪信息::"
501506
502507#: ../../tutorial/classes.rst:340
503508msgid ""
@@ -541,6 +546,8 @@ msgid ""
541546"is a method object, and can be stored away and called at a later time. For "
542547"example::"
543548msgstr ""
549+ "在 :class:`!MyClass` 示例中,这将返回字符串 ``'hello world'``。 但是,方法并不是必须立即调用: ``x.f`` "
550+ "是一个方法对象,它可以被保存起来以后再调用。 例如::"
544551
545552#: ../../tutorial/classes.rst:374
546553msgid "will continue to print ``hello world`` until the end of time."
@@ -555,6 +562,9 @@ msgid ""
555562" argument is called without any --- even if the argument isn't actually "
556563"used..."
557564msgstr ""
565+ "当一个方法被调用时究竟会发生什么? 你可能已经注意到尽管 :meth:`!f` 的函数定义指定了一个参数,但上面调用 ``x.f()`` "
566+ "时却没有带参数。 这个参数发生了什么事? 当一个需要参数的函数在不附带任何参数的情况下被调用时 Python 肯定会引发异常 --- "
567+ "即使参数实际上没有被使用..."
558568
559569#: ../../tutorial/classes.rst:382
560570msgid ""
@@ -684,6 +694,8 @@ msgid ""
684694"instances of :class:`!C` --- ``h`` being exactly equivalent to ``g``. Note "
685695"that this practice usually only serves to confuse the reader of a program."
686696msgstr ""
697+ "现在 ``f``、``g`` 和 ``h`` 都 :class:`!C` 类的指向函数对象的属性,因此它们都是 :class:`!C` 实例的方法 "
698+ "--- 其中 ``h`` 与 ``g`` 完全等价。 但请注意这种做法通常只会使程序的阅读者感到迷惑。"
687699
688700#: ../../tutorial/classes.rst:540
689701msgid ""
@@ -729,6 +741,8 @@ msgid ""
729741"class name, other arbitrary expressions are also allowed. This can be "
730742"useful, for example, when the base class is defined in another module::"
731743msgstr ""
744+ "名称 :class:`!BaseClassName` 必须定义于可从包含所派生的类的定义的作用域访问的命名空间中。 "
745+ "作为基类名称的替代,也允许使用其他任意表达式。 例如,当基类定义在另一个模块中时,这就会很有用处::"
732746
733747#: ../../tutorial/classes.rst:592
734748msgid ""
@@ -822,6 +836,9 @@ msgid ""
822836"classes of :class:`!Base1`, and if it was not found there, it was searched "
823837"for in :class:`!Base2`, and so on."
824838msgstr ""
839+ "对于多数目的来说,在最简单的情况下,你可以认为搜索从父类所继承属性的操作是深度优先、从左到右的,当层次结构存在重叠时不会在同一个类中搜索两次。 "
840+ "因此,如果某个属性在 :class:`!DerivedClassName` 中找不到,就会在 :class:`!Base1` 中搜索它,然后(递归地)在"
841+ " :class:`!Base1` 的基类中搜索,如果在那里也找不到,就将在 :class:`!Base2` 中搜索,依此类推。"
825842
826843#: ../../tutorial/classes.rst:652
827844msgid ""
@@ -948,6 +965,9 @@ msgid ""
948965":meth:`~io.TextIOBase.readline` that get the data from a string buffer "
949966"instead, and pass it as an argument."
950967msgstr ""
968+ "一段期望使用特定抽象数据类型的 Python 代码通常可以通过传入一个模拟了该数据类型的方法的类作为替代。 "
969+ "例如,如果你有一个基于文件对象来格式化某些数据的函数,你可以定义一个带有 :meth:`~io.TextIOBase.read` 和 "
970+ ":meth:`~io.TextIOBase.readline` 方法以便从字典串缓冲区获取数据的类,并将其作为参数传入。"
951971
952972#: ../../tutorial/classes.rst:772
953973msgid ""
0 commit comments