十二 072009
 

Python语言本身是没有注释多行的支持的,如果需要注册多行,可以用一个取巧的方法,就是把需要注释的代码块用三个引号括起来,赋值为一个永远都不会使用的字符串变量,例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
__devilcomment = '''
if bCmpLog == "True":
        self.appendAdsLogToCmpLog("")
 
if bCmpBinaryLog == "True":
        self.appendBinaryAdsLogToCmpLog(res)
 
if bCompareResp == "True":
    self.appendResponseToCmpLog(response_strs)
 
print "move new and debug logs"
self.tools.move (src_db,dst_db)
'''

Related posts:

  1. 用PDB库调试Python程序

  3 Responses to “Python多行注释技巧”

  1. 应该是三个引号吧

  2. 嗯,三重引号表示一个多行字符串,一般用于doc string。
    用来注释挺方便的。

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">