将文件转换为HEX字符串Python [英] Convert File to HEX String Python

查看:1047
本文介绍了将文件转换为HEX字符串Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 <$ c 





$打印(binascii) .hexlify(content))


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.

解决方案

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

这篇关于将文件转换为HEX字符串Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆