Python比特流实现 [英] Python Bitstream implementations

查看:345
本文介绍了Python比特流实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Python编写 huffman 实现,作为学习练习.我已经到了将可变长度霍夫曼代码写到缓冲区(或文件)的地步.才发现似乎没有Python实现的位流类!我看过 array struct 模块,但如果没有这些模块,它们似乎无法满足我的需求额外的工作.

I am writing a huffman implementation in Python as a learning exercise. I have got to the point of writing out my variable length huffman codes to a buffer (or file). Only to find there does not seem to be a bitstream class implemented by Python! I have had a look at the array and struct modules but they do not seem to do what I need without extra work.

有点眼神比特流实现,这更像是什么我想要. Python标准库中真的没有可比的比特流类吗?

A bit of goggling turned up this bitstream implementation, which is more like what I am wanting. Is there really no comparable bitstream class in the Python standard library?

推荐答案

您是对的,标准库中没有任何内容,但是您是否尝试过有据可查,因此我认为它应该很适合您的需求.

You're right that there's nothing in the standard library, but have you tried the bitstring module? It's pretty much designed for this kind of application, is stable and well documented, so I think it should suit your needs.

构造,读取,切片等都是按位完成的,它是纯Python.过去,我已经很成功地看到霍夫曼编码示例.

Construction, reading, slicing, etc. are all done bitwise, and it's pure Python. I've seen Huffman coding examples done with it quite successfully in the past.

另一个不错的选择是 bitarray ,它没有那么多功能,但可以由于它是C扩展,因此速度要快得多.另外,它具有作为源代码包的一部分分发的霍夫曼编码示例.

Another good option is bitarray, which doesn't have as many features but can be considerably faster as it's a C extension. As a bonus it has a Huffman coding example distributed as part of the source package.

这篇关于Python比特流实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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