读取二进制文件(python) [英] read a binary file (python)
本文介绍了读取二进制文件(python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法读取文件,我不明白为什么:
I cant read a file, and I dont understand why:
f = open("test/test.pdf", "r")
data = list(f.read())
print data
返回: []
我想打开一个PDF,并提取每个字节,把它放在一个清单中。
I would like to open a PDF, and extract every bytes, and put it in a List.
我的代码出了什么问题? :(
What's wrong with my code ? :(
谢谢,
推荐答案
f = open("test/test.pdf", "rb")
你必须在Windows上读写时包含伪模式b用于二进制文件。否则操作系统会默默地翻译它认为是行结尾的内容,导致i / o损坏。
You must include the pseudo-mode "b" for binary when reading and writing on Windows. Otherwise the OS silently translates what it considers to be "line endings", causing i/o corruption.
这篇关于读取二进制文件(python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文