Size: 1637
Comment:
|
Size: 4330
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 对象和面向对象
概览
pass
使用 from module import 导入模块
Para 3:添加了译注,指出文中的错误(和 Mark 联系上后移除)
类的定义
例5.4, (1):把原来的译注移到脚注<footnote>里面去了
例5.4下, 提示:不像在 Java 中有一个特殊的像 extends 的关键字。 (i) 多余,删去
例5.5:初始化 FileInfo Class (i) 没有翻译?!
类
例5.5, (2), Line -1:……但 __init__ 是在 Python 中你可以得到的最接近构造函数的东西,并且它也扮演着非常相同
的角色。
相似
例5.5, (4):__init__ 方法可以接受任意个数的参数,就像函数一样,参数可以用缺省值定义,可以设置成对于调用者可选。BR
__init__ 方法可以接受任意数目的参数,就像函数一样,参数可以用缺省值定义,即可以设置成对于调用者可选。
例5.6, (1):Python 不是这样,你必须显示地调用在父类中的适合
方法。
合适
类的实例化
Para 1:……为了对类进行实例化,只要调用类,好像它是一个函数……BR
要对类进行实例化,只要调用类(就好像它是一个函数)……
例5.7, (4):修正一处格式化错误(不再列出)。
例5.8, (1):然后函数结束
时 没有释放 f
探索 UserDict:一个封装类
Para 1:如你所见,FileInfo 是一个像字典一样动作的类。BR
如你所见,FileInfo 是一个有着像字典一样的行为方式的类。
例5.9, (5), Line -1:你可以用这种语法,或者可以在后面的行拥有缩近代码……
写下
例5.9下, Para 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
同时添加了一段译注,帮助读者理解。
例5.10, (1), Line -1:在你忘记的情况下,字典的 clear 方法删除它的所有关键字和关键字相应的值。
你可能已经忘了
例5.10 (3):我们使用 __class__ 属性来查看是否 self 是一个 UserDict……
self 是否是
专用类方法
高级专用类方法
类属性介绍
私有函数
小结