本人刚学python,作业要求是用python写html的页面然后把log文件的东西打印在网页上,网页打印什么的都没问题了,就是要把在同一时间访问同一页面的IP全都删掉,我用ifor如果三项有一项...
本人刚学python,作业要求是用python写html的页面然后把log文件的东西打印在网页上,网页打印什么的都没问题了,就是要把在同一时间访问同一页面的IP全都删掉,我用if or 如果三项有一项不一样就打印(就没有重复的了)
底下是我代码,总出错,错误也截图了
#!C:/Python27/python.exe
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# File handling test
#
#
#
text_file = open("access.log", "r")
entire_file = text_file.readlines()
text_file.close()
print ""
print ""
print "
Python Test"print ""
print "
"print ""
print ""
print "
"print "
print "
IPDateAction"for line in reversed(entire_file):
try:
arr = line.split(' ')
date = arr[3]
matchIP = arr[0]
matchDate = date[1:]
matchAct = arr[6]
if( matchIP is not a | b is not matchDate | c is not matchAct):
print "
", matchIP, "", matchDate, "", matchAct, ""a = matchIP
b = matchDate
c = matchAct
except IndexError, e:
error = e
print "
"print ""
print ""
展开