2.
[原文]P115
The "magic" of SGMLParser is nothing more than your old friend, getattr. What you may not have realized before is that getattr will find methods defined in descendants of an object as well as the object itself. Here the object is self, the current instance. So if tag is 'pre', this call to getattr will look for a start_pre method on the current instance,
which is an instance of the Dialectizer class.
[pope译] SGMLParser 的“魔法”没有多过你的老朋友gettattr.可能之前你没有意识到getattr寻找object子类的方法和查找object本身一样。当前的例子中object 就是它自己,so 所以如果tag 是‘pre’,在当前例子中,调用gettattr就查找start_pre方法,这个就是Dialectizer类的调用例子。
[doing]嘻嘻,找一下原文吧,有点儿郁闷,翻译后倒是明白什么意思了,但看着自己的翻译结果好奇怪啊:)
[net 译来源: http://woodpecker.org.cn/diveintopython/html_processing/dialect.html ]
SGMLParser 的 “神奇” 之处除了我们的老朋友 getattr 之外就没有什么了。您以前可能没注意到,getattr 将查找定义在一个对象的继承者中或对象自身的方法。这里对象是 self,即当前实例。所以,如果 tag 是 'pre',这里对 getattr 的调用将会在当前实例 (它是 Dialectizer 类的一个实例) 中查找一个名为 start_pre 的方法。
[popexizhi
the "magic"
[pope译]魔法
[net 译]神奇
[popexizhi]magic是魔法,也是很神奇,这里要的是net翻译的很是贴切,神奇之处 :)
is nothing more than your old friend
[pope译]没有多过你的老朋友gettattr.
[net 译]除了我们的老朋友 getattr 之外就没有什么了。
[popexizhi] pope的直译,导致了读起来的效果如何都不像是中文,但net很好表达了SGMLParser 与 gettattr 相同之处,不错很好的“之外就没有什么了” nothing more
[pope改进译] “神奇”的SGMLParser 没比熟悉的getattr多什么。
getattr will find methods defined in descendants of an object as well as the object itself
[pope译] getattr寻找object子类的方法和查找object本身一样。
[net 译]getattr 将查找定义在一个对象的继承者中或对象自身的方法
[popexizhi] 解释一个问题getattr的作用是返回查找方法的地址入口,这个在连接中的4.4节是讲过了,好了,有这个背景就好说下文了。 这里描述的是getatter的第一个参数self,说的是getattr是在自身或其子类中查找这个方法。pope的翻译的问题是 句子结构没有搞明白,翻译出来好晕,net的至少句子结构搞明白了。
[pope改进译] getattr 将在对象的其子类和对象的自身中,查找此方法。
]
没有评论:
发表评论