首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python一个目录上以及子目录上所有文件里,内容每一行如果是空格若干+字符串开始"printf"+其他字符,这一行删除.用python怎么

2012-09-29 
python一个目录下以及子目录下所有文件里,内容每一行如果是空格若干+字符串开始printf+其他字符,这一行

python一个目录下以及子目录下所有文件里,内容每一行如果是空格若干+字符串开始"printf"+其他字符,这一行删除.用python如何写
一个目录下以及子目录下所有文件里,内容每一行如果是空格若干&&字符串开始"printf"&&其他字符,这一行删除.用python如何写
目的就是删除项目代码里的所有调试代码,清理干净.
例如

C/C++ code
   int a = 5;   printf("%d",a);    //打印a的值


上面就要把第二行代码全部删除

[解决办法]
意思就是删除带有 printf 的行?
Python code
#========================================================#              author:ago                                #              2012/09/20 10:08:42                  #========================================================import osDIR = 'dir_name'for root,dirs,files in os.walk(DIR):    for file in files:        print file        f = open(DIR+'/'+file)        data = f.read()        f.close()        alist = data.split('\n')        string = ''        for i in alist:            print i            if 'printf' not in i:                string += i + '\r\n'                        #print string        f = open(DIR+'/'+file , 'w')        f.write(string)        f.close()
[解决办法]
探讨

意思就是删除带有 printf 的行?
Python code
#========================================================
# author:ago
# 2012/09/20 10:08:42 ……

热点排行