python读取文件通过正则过滤需要信息然后保存到新文件里

时间:2024-05-25 20:33:44

import os
import re
import fileinput

def getDataFromFile():
        rt = "/(.*)/(.*).apk"
        for line in fileinput.input("./test.log"):
                data = line
                array = re.findall(rt, data)
                if len(array)>0:
                        print array[0][1]
                        f = open('md5_value.txt', 'a')
                        f.writelines(array[0][1]+'\n')
                else:
                        print "list has none"
if __name__== "__main__":
        print "begin to test"
        getDataFromFile()