热门IT资讯网

python处理下数据小脚本

发表于:2024-11-29 作者:热门IT资讯网编辑
编辑最后更新 2024年11月29日,python处理下数据小脚本# -*- coding:UTF-8 -*-import osdef wenjchuli(file_path): with open(file_path) as f,

python处理下数据小脚本

# -*- coding:UTF-8 -*-import osdef 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")
0