将文件转换为HEX String Python

时间:2020-12-05 15:44:17

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.

如何使用Python将文件转换为HEX字符串?我已经在谷歌搜索了这个,但似乎找不到任何有用的东西。

1 个解决方案

#1


39  

import binascii
filename = 'test.dat'
with open(filename, 'rb') as f:
    content = f.read()
print(binascii.hexlify(content))

#1


39  

import binascii
filename = 'test.dat'
with open(filename, 'rb') as f:
    content = f.read()
print(binascii.hexlify(content))