如何在Python中打开和读取二进制文件? [英] How to open and read a binary file in Python?

查看:788
本文介绍了如何在Python中打开和读取二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个二进制文件(链接)想要使用Python打开和读取其中的内容.如何用Python打开和读取此类二进制文件?用于此操作的任何特定模块.

I have a binary file (link) that I would like to open and read contents of with Python. How are such binary files opened and read with Python? Any specific modules to use for such an operation.

推荐答案

'b'标志将使python将文件视为二进制文件,因此不需要任何模块.另外,您还没有提供让python读取带有此类问题的二进制文件的目的.

The 'b' flag will get python to treat the file as a binary, so no modules are needed. Also you haven't provided a purpose for having python read a binary file with a question like that.

f = open('binaryfile', 'rb')
print(f.read())

这篇关于如何在Python中打开和读取二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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