계산 한 crc를 기존 바이너리 파일에 추가하고 싶습니다.파이썬으로 바이너리 파일에 데이터 바이트 추가하기
예를 들어, crc는 0x55667788입니다.
파일의 끝에 0x55, 0x66, 0x77 및 0x88을 추가하고 싶습니다.
예를 들어 파일을 HexEdit에서 열면 파일의 마지막 4 바이트에 0x55667788이 표시됩니다. 여기
내 코드는 지금까지 있습니다 :fileopen = askopenfilename()
filename = open(fileopen, 'rb+')
filedata = filename.read()
filecrc32 = hex(binascii.crc32(filedata))
filename.seek(0,2)
filename.write(filecrc32)
filename.close()
나는 다음과 같은 오류 얻을 :
File "C:\Users\cjackel\openfile.py", line 9, in <module>
filename.write(filecrc32)
TypeError: 'str' does not support the buffer interface
어떤 제안?
당신은에서 파일을 여는 것 * 바이너리 * 모드이지만 * 텍스트 * 문자열을 쓰려고합니다. 먼저 문자열에 대한 인코딩을 선택하거나 다른 이진 데이터를 작성해야합니다. – millimoose