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

Python实战1-解析日记模块

2012-12-27 
Python实战1-解析日志模块根据用户提供的分隔符,分解日志数据?该模块作用有2个:1)提前检测能否正确解析日

Python实战1-解析日志模块

根据用户提供的分隔符,分解日志数据

?

该模块作用有2个:

1)提前检测能否正确解析日志,否则用户需要修改分隔符,或者日志格式

2)准备导入数据库的数据

?

?

logparse.pydef parselogline(line, tupleseperatorlist):    '''    input        line: line in log file        tupleseperatorlist: seperators in tuple    output        splited values    '''    data = []        for tupleseperator in tupleseperatorlist:        head = tupleseperator[0]        end = tupleseperator[1]                if not head :             endindex = line.find(end)            value = line[0:endindex]        elif not end:            headindex = line.find(head)            value = line[headindex + len(head) :]        else :            headindex = line.find(head)            endindex = line.find(end)            value = line[headindex + len(head): endindex]        data.append(value)     return data

?

热点排行