2012年10月7日星期日

Dive into Python 的我的翻译 XX


       3
[原文]P115
getattr raises an AttributeError if the method it's looking for doesn't exist in the object (or any of its descendants), but that's okay, because you wrapped the call to getattr inside a try...except block and explicitly caught the AttributeError.

[pope译] 如果method在对象(获其子类中)无法找到,getattr就抛出 AttributeError。这是可以的,因为 你封装(wrapped)此调用在try...except 块(block)中并且明确要捕获AttributeError.
[net 译 来源:http://woodpecker.org.cn/diveintopython/html_processing/dialect.html]
如果 getattr 所查找的方法在对象或它的任何继承者中不存在的话,它会引发一个 AttributeError 的异常。但没有关系,因为我们把对 getattr 的调用包装到一个try...except 块中了,并且显式地捕捉 AttributeError 异常。

[popexizhi:
but that's okay
[pope译]这是可以的
[net 译]但没有关系
[popexizhi]语义上连续下文,应该有转折的意思,不过调皮一下可以翻译为: "但这个正好"

wrapped the call to getattr inside a try...except block
[pope译]封装(wrapped)此调用在try...except 块(block)中
[net 译]把对 getattr 的调用包装到一个try...except 块中了
[popexizhi]  这里的the call to 是getattr 的定语,pope的翻译是中使用“此”指代是有问题的,这里的getattr 是首次提出,应该翻译的。语义上开始自己认为不通,是没有理解getattr的程序中的位置,引起的。
]


       4
[原文]P115
Since you didn't find a start_xxx method, you'll also look for a do_xxx method before giving up. This alternate naming scheme is generally used for standalone tags, like
, which have no corresponding end tag. But you can use either naming scheme; as you can see,SGMLParser tries both for every tag. (You shouldn't define both a start_xxx and do_xxx handler method for the same tag, though; only the start_xxx method will get called.)

[pope译]如果你没有找到start_xxx方法,放弃前可以尝试do_xxx 方法。这种代替(alternate)的命名方法是用来处理独立的tags的,像
,它没有相对应(corresponding)的结束tag.但你可以使用另外的命名方法,如你所见SGMLParser 尝试每个tag两次(你不能同时定义start_xxx和do_xxx 方法对同一个tag,尽管如此只有start_xxx 方法被执行)哦

[net 译 来源:http://woodpecker.org.cn/diveintopython/html_processing/dialect.html]
因为我们没有找到一个 start_xxx 方法,在放弃之前,我们将还要查找一个 do_xxx 方法。这个可替换的命名模式一般用于单独的标记,如 
,这些标记没有相应的结束标记。但是您可以使用任何一种模式,正如您看到的,SGMLParser 对每个标记尝试两次。(您不应该对相同的标记同时定义 start_xxx 和 do_xxx 处理方法,因为这样的话只有 start_xxx 方法会被调用。)

[popexizhi
but you can use either naming scheme
[pope译]但你可以使用另外的命名方法
[net 译] 但是您可以使用任何一种模式
[popexizhi] either naming scheme 任何一种命名方案,这个是直译,但应对上下问说的是对tage定义的方法是start_tage或是do_tage在这个结构下都是可以的的意思,所以net翻译使用"任何一种模式"更符合中文的表达。

only the start_xxx method will get called
[pope 译]尽管如此只有start_xxx 方法被执行
[net 译]因为这样的话只有 start_xxx 方法会被调用
[popexizhi] 这里没有因为的直译,但是though 的上下文语义自己感觉pope译是ok的,虽然定义两个不会引起错误并且第一个被正确调用,但是还是不合适定义同时存在的两种方法
]

       5
[原文]P115
Another AttributeError, which means that the call to getattr failed with do_xxx. Since you found neither a start_xxx nor a do_xxx method for this tag, you catch the exception and fall back on the default method, unknown_starttag.

[pope译]另一个AttributeError, 意味调用do_xxx的getatter失败。如果你对这个tag,没有发现如何可用的start_xxx 或者do_xxx ,及可以捕捉到异常并且失败返回默认的的方法 unknown_starttag.
[net 译 来源:http://woodpecker.org.cn/diveintopython/html_processing/dialect.html]
另一个 AttributeError 异常,它是说用 do_xxx 来调用 getattr 失败了。因为对同一个标记我们既没有找到 start_xxx 也没有找到 do_xxx 处理方法,这样我们捕捉到了异常并且求助于缺省方法:unknown_starttag

[popexizhi
ok 没什么可说的:)
]    


没有评论:

发表评论