html tool

2013年1月30日星期三

Dive into Python 的我的翻译 XXXI------8.6 V


[原文]P113

self.pieces.append("<%(tag)s%(strattrs)s> " % locals())
Now, using dictionary−based string formatting, you insert the value of tag and strattrs into a string. So if tag is 'a', the final result would be '',  and that is what gets appended to self.pieces.
[popexizhi]strattrs 是上面定义过的,tag 是def 的input .原文的eg said:if tag = ‘a’,then 结果是''。直接翻译”that is what gets appended to self.pieces.“ 就是追加这个结果到self.pieces中。问题是这样看来这个self.pieces.append就是追加的意思,嘻嘻,再看吧!
[pope译]
现在,使用基于字典的字符串格式,你插入tag的值和strattrs 到字符串中。也就是说 如果tag是‘a’,最后的结果将是  '',这些将加到self.pieces中。

[net 译 来源:http://woodpecker.org.cn/diveintopython/html_processing/dictionary_based_string_formatting.html]
现在,使用基于 dictionary 的字符串格式化,我们将 tag 和 strattrs 的值插入到一个字符串中。所以,如果 tag 是 'a',最终的结果会是 '',并且这就是追加到 self.pieces 后面的东西。

[popexizhi]这里说说关于self.pieces的问题吧!记得前面的翻译下文中说到了self.pieces的问题,说它的内容是如何一片一片的重写每个tag的,当时想查看内容,大致是这个情节,现在这里的内容,是tag在self.pieces如何被构建出来的。  

-----------------------------------------------------------------------

       [原文]P113
Using dictionary−based string formatting with locals is a convenient way of making complex string formatting expressions more readable, but it comes with a price. There is a slight performance hit in making the call to locals, since locals builds a copy of the local namespace.

[popexizhi]use locals 格式化字符串是方便,但是有代价。就是调用locasls时,系统要给一个locasls的拷贝。这样分析就是每一次使用一个locasls时,就copy一个,要是比较大时,确实资源使用比较多

[pope译]使用locals ,这个字典的字符串格式化 ,是一个简便的{convenient}方法处理复杂的字符串格式化表示{expressions} 更多的可读信息,但是这是要付出代价的。在使用locals时有轻度的性能问题,因为locals 创建了local命名空间的备份

[net 译 来源:http://woodpecker.org.cn/diveintopython/html_processing/dictionary_based_string_formatting.html]
使用 locals 来应用基于 dictionary 的字符串格式化是一种方便的作法,它可以使复杂的字符串格式化表达式更易读。但它需要花费一定的代价。在调用locals 方面有一点性能上的问题,这是由于 locals 创建了局部名字空间的一个拷贝引起的。

[popexizhi
complex string formatting expressions more readable
[pope译]复杂的字符串格式化表示{expressions} 更多的可读信息
[net 译]复杂的字符串格式化表达式更易读
[popexizhi]pope的直译没有问题,但是中文的表述不是这样的,改进译一下net说的就和好的
]  

没有评论:

发表评论