path = "F:/work/logs/newLog" #找到这个目录下的多有文件、目录集合 for fileName in os.listdir(path): #如果是目录 if os.path.isdir(os.path.join(path,fileName)): print fileName import time today1 = time.strftime('%Y%m',time.localtime(time.time())) today2 = time.strftime('%d ',time.localtime(time.time())) print today1 print today2 import gzip f=gzip.open("F:/temp/test/200906/01/access.log.2009060103.gz" ) line = f.readline() #读行 while line is not "" and len(line) >10: print line