Seite 1 von 1

Problem mit RegEx

Verfasst: Samstag 21. April 2007, 19:30
von cyp++

Code: Alles auswählen

# -*- coding: utf-8 -*-
# SnakelogAnalyzer.py

import re
import os
import os.path
from pysqlite2 import dbapi2 as sqlite

SNAKELOG = file('E:\\server.log', 'r')

class SnakelogAnalyzer(object):

    '''
    Class for cleaving a Snakelog.
    '''

    def __init__(self, line):

        self.line = line

    def cleaveLine(self):

        '''
        Method to cleave one line of the Snakelog and group them.
        '''

        parser = re.compile('\[[0-3][0-9]\/[[0-3][0-9]\/0[0-9] [0-3][0-9]\:[0-5][0-9]\:[0-5][0-9]\,_*')
        result = parser.match(self.line)

        for i in range(result.lastindex):
            print result.group(i+1)

    def writeIntoDB(self):

        '''
        Method to write the grouped line into the DB.
        '''

        pass

def createDB():

    '''
    Function to create the DB.
    '''

    pass

if __name__ == '__main__':
    createDB()

    while True:

        # read on line
        line = SNAKELOG.readline()
        if not line: break
        print line

        analyzer = SnakelogAnalyzer(line)
        g = analyzer.cleaveLine()

Verfasst: Samstag 21. April 2007, 19:33
von cyp++
hi,

ich habe ein Problem mit RegEx. In Zeile 30 "result.lastindex" das gibt mir komischwerweise "None" zurück, ich wüsste gern wieso? die Datei ist NICHT! leer.

mfg

// edit

sorry, falschen Button erwischt.

// edit

vielleicht nützlich, die erste Zeile aus der Log-datei:
[01/31/05 11:26:11,__init__,INFO] ----------------------------------------
// edit

hat sich erledigt, programm ist komplett fertig und läuft