I want to do some operation on binary file using python script. I have one binary file. And I want to append binary data to it.
Example:
File abc.bin is available.
Command:
python file_append.py abc.bin 1234 5678
I want to append "1234" and "5678" at the end of the binary file abc.bin.
So I opened the file with "ab" mode (append + binary). When I append a command line argument, it appends the ASCII value of the argument.
How can I append the hex value (here 1234 and 5678) at the end of the file?
Code:
fo = open(str(sys.argv[1]), 'ab')
fv = string.atoi(sys.argv[2])
ft = string.atoi(sys.argv[3])
fo.write(fv)