Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我从网页中获得了一些大文件。它们是二进制的。我需要扫描它们以检测它们的编码,因为 chardet.detect 让我的脚本太慢了。我很难使用 readline 但我不能因为我只有二进制文件。可以在二进制对象上执行类似 readline 的操作吗?
您无法知道何时有换行符,因为您不知道它是如何编码的。您可以简单地获取一小部分二进制数据data[:100]并chardet.detect在其上运行。
data[:100]
chardet.detect