python - python中如何将二进制转换为字符串?

标签 python python-3.x string binary

我一直在尝试将我的二进制文件转换为 python 中的字符串。根本就没有想出任何解决办法。有人有主意吗?下面是我如何将上述字符串转换为二进制的代码。不知道有用吗?

def binary_converter(string):
   for character in string:
        print(bin(ord(character))[2:].zfill(8))

binary_converter("Hello World!")

最佳答案

将其转换为字符串的最简单方法是str.decode()。例如,b"binary code".decode() 将返回字符串。

关于python - python中如何将二进制转换为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57025763/

相关文章:

python - 如何在 Flask 中访问重定向 URI 中的参数?

javascript如何对包含逗号分隔值的字符串进行排序

python - 使用 python 进行 Selenium 网络抓取 - 任何没有名字的下拉菜单

Python:Google API - 从消息中获取 mimeTypes

python - pygame以相反方向绘制项目

string - 在 Go 中拆分字符串列表中的字符串

java - 比较字符串引用

python - 我的 Flask 应用程序不在 Heroku 上运行,但它在本地运行

python - Pandas - 当字符串与格式匹配时出现 "time data does not match format "错误?

python - 与 multiprocessing.Pool 共享一个计数器