代码片段整理
时间:2010-06-30 来源:hkebao
#coding:utf-8
import os,sys
import time
path = os.path.abspath(os.path.dirname(sys.argv[0]))
N = 10
#1.输出当前系统时间 文件名:20100630
tmplog = time.strftime("%Y%m%d", time.localtime())
fullpath = path + os.sep + tmplog
if not os.path.isdir( fullpath ):os.mkdir(fullpath)
file_object = open(fullpath + os.sep + currhour + '.txt', 'a')
#2.开始分析日志文件提取前N行日志到指定的文件里面去
currhour = time.strftime("%H", time.localtime())
for current_line_number,line in enumerate(open('tmplog.log','r+')):
if current_line_number < N:
file_object.write(line)
else:
lines = line
import os,sys
import time
path = os.path.abspath(os.path.dirname(sys.argv[0]))
N = 10
#1.输出当前系统时间 文件名:20100630
tmplog = time.strftime("%Y%m%d", time.localtime())
fullpath = path + os.sep + tmplog
if not os.path.isdir( fullpath ):os.mkdir(fullpath)
file_object = open(fullpath + os.sep + currhour + '.txt', 'a')
#2.开始分析日志文件提取前N行日志到指定的文件里面去
currhour = time.strftime("%H", time.localtime())
for current_line_number,line in enumerate(open('tmplog.log','r+')):
if current_line_number < N:
file_object.write(line)
else:
lines = line
相关阅读 更多 +