我有一个日志文件,我必须解析。 日志文件可能有3种类型的行
cat- xxxxxxxxxxxxx
dog - xxxxxxxxxxxxxxx
rat - xxxxxxxxxxxxx
我在python脚本中的解析函数是
from django.utils import simplejson
simplejson.JSONEncoder.item_separator = ','
simplejson.JSONEncoder.key_separator = ':'
def parseFile(self):
thread.start_new_thread(self.part1,("rat",))
thread.start_new_thread(self.part1,("dog",))
thread.start_new_thread(self.part1,("cat",))
def part1(self, tag):
try:
print "eating %s feed statements\n"%tag
log_file = open(self.file,'r')
for line in log_file:
if line.find(tag) != -1:
msg = self.getJsonMessage(line)
print "hello1"
self.META_TAGS[tag](msg)
log_file.close()
print "finished eating %s\n"%tag
print self.positiveCount, self.negcount, self.nocount
except Exception,e:
print e
def getJsonMessage(self,line):
parts = line.split(' ')
jsonstr = ''
count = 4
while(count<len(parts)):
jsonstr += ' ' + parts[count]
#print parts[count]
count = count + 1
print jsonstr
msg = simplejson.loads(jsonstr) //LINE 1
date = parts[0].split('-')
time = parts[1].split(':')
seconds = time[2].split(',')
msg['feed_date'] = datetime(int(date[0]),int(date[1]),int(date[2]),int(time[0]),int(time[1]),int(seconds[0]),int(seconds[1]))
return msg
现在当代码到达LINE 1时抛出异常
我知道当前版本的django已弃用simplejson,但我使用的是旧版本。