I an new to Python, trying to overwrite the last 128 bytes of a file with zer0s. What am I doing wrong?
try:
f = open(outputFile, "wb")
for x in range(1, 128):
f.seek(x, 2) # seek relative to end of file
f.write(0)
f.close()
except Exception as e:
sys.exit('Error writing output file ' + str(e))
Error writing output file 'int' does not support the buffer interface
[Update]
this runs with no error, but the zer0s are not written (I mean \0 (end of string))
f = open(outputFile, "rb+")
zeros = bytearray(0 * 128)
f.seek(-128, 2) # seek relative to end of file
f.write(zeros)
f.close()
Note: when I tried f.write('\0'*128) I got Error writing output file 'str' does not support the buffer interface
bytearray(128)to get the array of NULsb'\0'*128to make abytesobjectbytearray(0 * 128)is same asbytearray(0)ie. emptybytearray. Writing that would have no effect of course!