【发布时间】:2011-04-27 05:27:37
【问题描述】:
如何使用 Python 将文件转换为 HEX 字符串?我已经在谷歌上搜索了这个,但似乎找不到任何有用的东西。
【问题讨论】:
如何使用 Python 将文件转换为 HEX 字符串?我已经在谷歌上搜索了这个,但似乎找不到任何有用的东西。
【问题讨论】:
import binascii
filename = 'test.dat'
with open(filename, 'rb') as f:
content = f.read()
print(binascii.hexlify(content))
【讨论】:
lscpu 检查机器的字节序。要获得 hexdump 输出以匹配上述代码的输出,请运行 hexdump -C /path/to/file。