xlrd를 사용하여 두 개의 .xls 시트 사이의 값을 비교하는 스크립트가 있습니다. 기본적으로 유사점을 찾아서 txt 파일에 씁니다. 인수를 전달하면 각 .xls에 고유 한 장치를 찾아서 txt 파일에 쓸 수 있습니다. 지금은 각 .xls의 행을 반복하고 두 파일 간의 유사성을 발견하면 플래그를 True로 표시합니다. 플래그가 False로 표시되면 첫 번째 시트의 호스트 만 씁니다.파이썬에서 객체를 반복 할 때 플래그를 사용하는 대신
else:
for row1 in range(sheet1.nrows):
inboth = False
for row2 in range(sheet2.nrows):
if sheet2.row_values(row2)[0].split(".")[0] == sheet1.row_values(row1)[0].split(".")[0]:
inboth = True
if not inboth:
outfile.write(sheet1.row_values(row1)[0].split(".")[0] + ",File1\n")
for row2 in range(sheet2.nrows):
inboth = False
for row1 in range(sheet1.nrows):
if sheet1.row_values(row1)[0].split(".")[0] == sheet2.row_values(row2)[0].split(".")[0]:
inboth = True
if not inboth:
outfile.write(sheet2.row_values(row2)[0].split(".")[0] + ",File2\n")
은 "inboth"플래그를 사용하지 않고이 작업을 수행 할 수있는보다 효율적인 방법이 있습니다 : 여기에 플래그 코드의 비트는? 두 시트를 두 번 반복 할 필요가없는 솔루션이 있습니까?
총 테스트 수는 2xNxM입니다. 여기서 N과 M은 scheet1과 scheet2의 행 수입니다. 이것은 컴퓨터 과학에서 O (N^2)이며 대용량 데이터 세트의 경우 매우 느리게 코드를 작성합니다. – Ber