Convert File to HEX String Python

Question:

How would I convert a file to a HEX string using Python? I have searched all over Google for this, but can’t seem to find anything useful.

Asked By: Zac Brown

||

Answers:

import binascii
filename = 'test.dat'
with open(filename, 'rb') as f:
    content = f.read()
print(binascii.hexlify(content))
Answered By: unutbu
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.