Differences between revisions 4 and 5
Revision 4 as of 2007-07-07 13:32:39
Size: 1637
Editor: XiaoQi
Comment:
Revision 5 as of 2007-07-07 13:48:49
Size: 4330
Editor: XiaoQi
Comment:
Deletions are marked like this. Additions are marked like this.
Line 9: Line 9:
 1. ''例5.4下, 提示'':不像在 Java 中有一个特殊的'''像''' extends '''的'''关键字。 {i} 多余,删去
 1. ''例5.5'':初始化 FileInfo '''Class''' {i} 没有翻译?! (./) 类
 1. ''例5.4下, 提示'':不像在 Java 中有一个特殊的'''像''' extends '''的'''关键字。 (i) 多余,删去
 1. ''例5.5'':初始化 FileInfo '''Class''' (i) 没有翻译?! (./) 类
Line 18: Line 18:
 1. ''例5.7, (4)'':修正一处格式化错误(不再列出)。
 1. ''例5.8, (1)'':然后函数结束 {i} ^时^ 没有释放 f
Line 20: Line 21:
 1. ''Para 1'':如你所见,FileInfo 是一个'''像字典一样动作'''的类。[[BR]]
 (./) 如你所见,FileInfo 是一个'''有着像字典一样的行为方式'''的类。
 1. ''例5.9, (5), Line -1'':你可以用这种语法,或者可以在后面的行'''拥有'''缩近代码…… (./) '''写下'''
 1. ''例5.9下, Para 1'':一个类可以有同名的多个方法,但这些方法或者是参数个数不同,'''或''' <!> 参数的类型不同。 (!) 为保持一致, (./) '''或者是'''
 1. ''例5.9下, Para 2'':''Guido, the original author of Python, explains method overriding this way: "Derived classes may override methods of their base classes. Because methods have no special privileges when calling other methods of the same object, a method of a base class that calls another method defined in the same base class, may in fact end up calling a method of a derived class that overrides it. (For C++ programmers: all methods in Python are effectively virtual.)" If that doesn't make sense to you (it confuses the hell out of me), feel free to ignore it. I just thought I'd pass it along.''[[BR]]
 Python 的原作者 Guido 是这样解释方法覆盖的 “子类可以覆盖父类中的方法。因为方法没有特殊的优先级设置,在调用同一对象的另外方法时,父类中一个方法对另一个同类中的方法的调用,可能其实调用到的却是一个子类中覆盖父类同名方法的方法。(对于 C++ 程序员,所有的 Python 方法都非常有效)” 如果你不明白(它另我颇感困惑),不必在意。我想我要跳过它。[[BR]]
 (!) 明显这位兄台没有理解 Guido 的话,也不懂 C++。[[BR]]
 (./) Python 的原作者 Guido 是这样解释方法覆盖的:“子类可以覆盖父类中的方法。因为方法没有特殊的优先级设置,父类中的一个方法在调用同类中的另一方法时,可能其实调用到的却是一个子类中覆盖父类同名方法的方法。(C++ 程序员可能会这样想:所有的 Python 方法都是虚函数。)”如果你不明白(它另我颇感困惑),不必在意。我想我要跳过它。[[BR]]
 (./) 同时添加了一段译注,帮助读者理解。
 1. ''例5.10, (1), Line -1'':'''在你忘记的情况下''',字典的 clear 方法删除它的所有关键字和关键字相应的值。 (./) '''你可能已经忘了'''
 1. ''例5.10 (3)'':我们使用 `__class__` 属性来查看'''是否 self 是'''一个 UserDict…… (./) '''self 是否是'''

7-7<X5> fileinfo.xml 对象和面向对象

TableOfContents

概览

pass

使用 from module import 导入模块

  1. Para 3:添加了译注,指出文中的错误(和 Mark 联系上后移除)

类的定义

  1. 例5.4, (1):把原来的译注移到脚注<footnote>里面去了

  2. 例5.4下, 提示:不像在 Java 中有一个特殊的 extends 关键字。 (i) 多余,删去

  3. 例5.5:初始化 FileInfo Class (i) 没有翻译?! (./)

  4. 例5.5, (2), Line -1:……但 __init__ 是在 Python 中你可以得到的最接近构造函数的东西,并且它也扮演着非常相同 <!> 的角色。 (./) 相似

  5. 例5.5, (4)__init__ 方法可以接受任意个数的参数,就像函数一样,参数可以用缺省值定义,可以设置成对于调用者可选。BR (./) __init__ 方法可以接受任意数目的参数,就像函数一样,参数可以用缺省值定义,可以设置成对于调用者可选。

  6. 例5.6, (1):Python 不是这样,你必须显示地调用在父类中的适合 <!> 方法。 (./) 合适

类的实例化

  1. Para 1:……为了对类进行实例化,只要调用类,好像它是一个函数……BR (./) 对类进行实例化,只要调用类(就好像它是一个函数)……

  2. 例5.7, (4):修正一处格式化错误(不再列出)。

  3. 例5.8, (1):然后函数结束 {i} 没有释放 f

探索 UserDict:一个封装类

  1. Para 1:如你所见,FileInfo 是一个像字典一样动作的类。BR (./) 如你所见,FileInfo 是一个有着像字典一样的行为方式的类。

  2. 例5.9, (5), Line -1:你可以用这种语法,或者可以在后面的行拥有缩近代码…… (./) 写下

  3. 例5.9下, Para 1:一个类可以有同名的多个方法,但这些方法或者是参数个数不同, <!> 参数的类型不同。 (!) 为保持一致, (./) 或者是

  4. 例5.9下, Para 2Guido, the original author of Python, explains method overriding this way: "Derived classes may override methods of their base classes. Because methods have no special privileges when calling other methods of the same object, a method of a base class that calls another method defined in the same base class, may in fact end up calling a method of a derived class that overrides it. (For C++ programmers: all methods in Python are effectively virtual.)" If that doesn't make sense to you (it confuses the hell out of me), feel free to ignore it. I just thought I'd pass it along.BR Python 的原作者 Guido 是这样解释方法覆盖的 “子类可以覆盖父类中的方法。因为方法没有特殊的优先级设置,在调用同一对象的另外方法时,父类中一个方法对另一个同类中的方法的调用,可能其实调用到的却是一个子类中覆盖父类同名方法的方法。(对于 C++ 程序员,所有的 Python 方法都非常有效)” 如果你不明白(它另我颇感困惑),不必在意。我想我要跳过它。BR (!) 明显这位兄台没有理解 Guido 的话,也不懂 C++。BR (./) Python 的原作者 Guido 是这样解释方法覆盖的:“子类可以覆盖父类中的方法。因为方法没有特殊的优先级设置,父类中的一个方法在调用同类中的另一方法时,可能其实调用到的却是一个子类中覆盖父类同名方法的方法。(C++ 程序员可能会这样想:所有的 Python 方法都是虚函数。)”如果你不明白(它另我颇感困惑),不必在意。我想我要跳过它。BR (./) 同时添加了一段译注,帮助读者理解。

  5. 例5.10, (1), Line -1在你忘记的情况下,字典的 clear 方法删除它的所有关键字和关键字相应的值。 (./) 你可能已经忘了

  6. 例5.10 (3):我们使用 __class__ 属性来查看是否 self 是一个 UserDict…… (./) self 是否是

专用类方法

高级专用类方法

类属性介绍

私有函数

小结

反馈

PageComment2

DiveIntoPythonZh/2007-07-07 (last edited 2009-12-25 07:16:54 by localhost)