본문 바로가기

Programming/Python

[Python] Byte Array Compare

import sys
 
file1_b = bytearray(open(sys.argv[1], 'rb').read())
file2_b = bytearray(open(sys.argv[2], 'rb').read())

size = len(file1_b) if file1_b < file2_b else len(file2_b)
_byte_array = bytearray(size)
 
# file compare after calc
for i in range(size):
	if file1_b[i] != file2_b[i]:
	    _byte_array[i] = file1_b[i] # 다른 부분 저장

open(sys.argv[3], 'wb').write(_byte_array)


파일을 Byte Array로 불러와서 크기를 비교하고 더 큰 파일은 기준으로 for문을 돌린다. 


'Programming > Python' 카테고리의 다른 글

[Python] port scan (socket)  (0) 2018.03.27