首页 > 编程语言 > 详细

python处理下数据小脚本

时间:2018-07-11 10:28:18      阅读:149      评论:0      收藏:0      [点我收藏+]
python处理下数据小脚本

# -*- coding:UTF-8 -*-
import os
def wenjchuli(file_path):
    with open(file_path) as f, open(file_path+".bak", ‘w‘) as f2:
        for line in f:
            if("Location" in line):
                new_line=line.replace(line,"")
            elif("Qualified Name" in line):
                new_line=line.replace(line,"")
            elif ("JD-Core Version" in line):
                new_line = line.replace(line, "")
            elif ("/*" in line):
                new_line = line[12:].replace("/", "")
            else:
                new_line = line
            f2.write(new_line)
    os.remove(file_path)
    os.rename(file_path+".bak",file_path)

def gci(filepath):
    # 遍历filepath下所有文件,包括子目录
    files = os.listdir(filepath)
    for fi in files:
        fi_d = os.path.join(filepath, fi)
        if os.path.isdir(fi_d):
            gci(fi_d)
        else:
            wenjchuli(fi_d)

gci("C:\\Users\\lw\\Desktop\\letv")

python处理下数据小脚本

原文:http://blog.51cto.com/357712148/2140144

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!