html tool

2013年1月13日星期日

Dive into Python 的我的翻译 IXXX------8.6 III


       Example 8.14. Dictionary−based string formatting in BaseHTMLProcessor.py
    def handle_comment(self, text):       
        self.pieces.append("<!−−%(text)s−−>" % locals())
  • [原文]P112
    Using the built−in locals function is the most common use of dictionary−based string formatting. It means that you can use the names of local variables within your string (in this case, text, which was passed to the class method as an argument) and each named variable will be replaced by its value. If text is 'Begin page footer', the string formatting "<!−−%(text)s−−>" % locals() will resolve to the string '<!−−Begin page footer−−>'.
    ---------------------------------------------------------------------------
    [?]按上面eg的理解"<!−−%(text)s−−>" % locals()  应该是将text的内容替换后 显示出来,那么self.pieces.append 是增加内容用的吗?如果是,self.pieces中到底成为什么样子了?晕不明白。两个问题吧!
    1."<!−−%(text)s−−>" % locals() 是在locals()中找到text替换吗?
    2.self.pieces.append 是什么?
    PS:self.pieces 的最后内容print吗?
    【popexizhi:这个还没有回答,先留着!】
    ---------------------------------------------------------------------------

    [pope改进译] 内置locals方法最常见的使用 就是 基于字典内容的字符串格式。这也就是说你可以在自己的字符串中使用  local 中变量的名称 (eg中text 最为参数传递给类方法) ,并且每个变量的名称都可以使用他的值来替代。如果text 是'Begin page footer',这个 "<!−−%(text)s−−>" % locals()格式化后 被修改为{resolve to}  '<!−−Begin page footer−−>'.

    [pope译] 使用内置locals方法  多数的命令使用 基于字典的字符串格式。这意味着你可以在自己的字符串中使用 local 中变量的名称(在这个例子中,text,使用通过类的方法作为论证方法([?] which was passed to the class method as an argument 中的argument 与class  method 之间是证明关系吗?) ) 并且每个变量的名称都可以使用他的值来替代。如果text 是'Begin page footer',这个 "<!−−%(text)s−−>" % locals()格式化后 被修改为{resolve to}  '<!−−Begin page footer−−>'.
    [net 译 来源:http://woodpecker.org.cn/diveintopython/html_processing/dictionary_based_string_formatting.html]
    使用内置的 locals 函数是最普通的基于 dictionary 的字符串格式化的应用。这就是说您可以在您的字符串 (本例中是 text,它作为一个参数传递给类方法) 中使用局部变量的名字,并且每个命名的变量将会被它的值替换。如果 text  'Begin page footer',字符串格式化 "" % locals()将得到字符串 ''

    [popexizhi]
    the most common
    [pope译] 多数的命令
    [net译]最普通
    [popexizhi]most of the command 和 the most common 好像差很多啊,还是最高级的使用,晕的很的表现,现在开始要注意这个“晕”了,不是一个感叹词那么简单,应该还是心理的习惯模式问题,分析一下吧pope你可不能连晕后面的是什么都不闻不到吧?!:)

    which was passed to the class method as an argument
    [pope译]使用通过类的方法作为论证方法
    [net 译]它作为一个参数传递给类方法
    [popexizhi] argument 好吧!pope的问题现在看来好可爱,argument这里不就是参数变量吗!证明关系,好吧!来刨一刨,证明关系中传递的是证据,函数关系中传递的变量,原来是做证据用的啊?!:)之前一直感觉函数间是服务的关系,这个样子看来,函数间的变量传递是要用来证明的关系,更类似的应该是司法的服务关系,而不是普通商店的服务关系。这样也对,数学的来源处当然是很严谨的法庭,而不会是肉铺了,如果那里产生的函数应该也是产生灌肠方法之类的指南,而不是发酵中菌类的产生和死亡证明吧:)好吧!自己又没limit了,argument 论证关系的自变量参数。    




没有评论:

发表评论