首页 > 编程语言 > 详细

python 日志分割器 大文本处理

时间:2021-04-10 01:16:55      阅读:28      评论:0      收藏:0      [点我收藏+]
import math
i=0
filename=‘‘
write=‘‘
Rline = ‘‘

def writeFile(fileName,line):
    global filename
    global write
    global Rline

    if filename!=fileName and filename==‘‘:
        write = open(D:/soft/apache-tomcat-7.0.47/logs/+fileName+".log", a+)
        write.write(line)
    elif  filename!=fileName  and Rline!=‘‘:
        write.close()#新文件就关闭上个write的流
    else:
        write.write(line)
        filename = fileName
    Rline = line
with open(D:/soft/apache-tomcat-7.0.47/logs/cloudq.log,r) as infile:
    for line in infile:
        name = i/500#设置每一个文件500行。
        # print(math.floor(name))
        writeFile(str(math.floor(name)),line)
        i=i+1

如果代码报错,请去掉中文注释再试。

 

python 日志分割器 大文本处理

原文:https://www.cnblogs.com/QQmini/p/14637825.html

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