Tuesday, March 22, 2016

create read binary file in python

python bytes:
http://www.dotnetperls.com/bytes-python

Note:
1. file pointer always reads and writes strings (byte string and text string), NOT numbers
2. generally binary flag for open does not work properly - not needed
3. to convert the read bytes to hex string, use: .encode('hex')
Example: open('test.txt', 'r').read().encode('hex')
4. to write binary: create a byte string, then write that string: Example: str = '\x03\x04'
    open('test.txt', 'w').write('\x29')

No comments:

Post a Comment