좋아, 내가 다음과 같이 여러 목록 상자에서 출력 한 후, 배열에 저장, ONLY ONE .log 파일의 내용을 복용하고있는 중이 야 :배열에 여러 파일에서 데이터의 목록을 저장
filelog_ext=".log" #log extension
#open one log file
f = open("%s\%s%s" % (path,filename,filelog_ext),"r")
#init aray
array = []
#copy contents of file to array
for line in f:
array.append(line)
f.close()
#insert each array content to multilistbox
self.mlb.insert (END, ('%s' % (array[0]),'%s' % (array[1]),'%s' % (array[2]),'%s' % array[3])))
self.mlb.pack (expand=YES,fill=BOTH)
내가 지금하고 싶은 것은 많은 .log 파일의 내용을 가져 와서 배열로 출력 한 다음 다중 목록 상자에서 출력하는 것입니다.
나는 시도 다음 그러나 작동하지 않습니다
for files in os.listdir("."):
if files.endswith(".log"): #this will take all my files ending with .log
#not sure how to go about and take all files ending with .log, copying them to array and saving them to the multilistbox mlb
사람이 좀 도와 주시겠습니까?
업데이트 : @john zwink 나는 당신의 코드를 통합하려고 시도했는데, 그것이 올바른 방법으로하고 있는지는 아직 알 수 없다.하지만 여전히 작동하지는 않는다. 오류는 "색인 목록이 범위를 벗어났습니다"
path = "C:\sdmdownloads"
array = []
for filename in glob.iglob(os.path.join(path, filelog_ext)):
with open(filename) as f:
array.extend(f)
self.mlb.insert (END, ('%s' % (array[0]),'%s' % (array[1]),'%s' % (array[2]),'%s' % (array[3])))
self.mlb.pack (expand=YES,fill=BOTH)
파일에 4 줄이 없습니까? – jamylak
첫 번째 줄의 첫 번째 토큰을 array [0]으로 가져 오거나 각 파일의 첫 줄을 array [0]으로 가져 오기를 기대합니까? –