确保对模块, 函数, 方法和行内注释使用正确的风格,Python中的注释有单行注释和多行注释。如果希望去除文件中所有注释,如何做呢?
Python中的注释:
Python中单行注释以 # 开头,例如:
# 这是一个注释
print("Hello, World!")
多行注释用三个单引号 ''' 或者三个双引号 """ 将注释括起来,例如:
#!/usr/bin/python3
'''
这是多行注释,用三个单引号
这是多行注释,用三个单引号
这是多行注释,用三个单引号
'''
print("Hello, World!")
使用Python脚本快速去除文件中的注释:
#!/usr/bin/python
# -*- coding: GBK -*-
#writer:xmnathan
#py文件去注释
import re
import os
import ConfigParser
Python='CleanNote'
def ReadIni(path,section,option):#文件路径,章节,关键词
#读取ini
cf=ConfigParser.ConfigParser()
cf.read(path)
value=cf.get(section,option)#如果用getint()则直接读取该数据