[Python-ideas] Ideas for improving the struct module

Chris Angelico rosuav at gmail.com
Thu Jan 19 13:16:28 EST 2017


On Fri, Jan 20, 2017 at 5:08 AM, Elizabeth Myers
<elizabeth at interlinked.me> wrote:
> I do understand it might require a possible major rewrite or major
> changes the struct module, but in the long run, I think it's worth it
> (especially because the struct module is not all that big in scope). As
> it stands, the struct module simply is not suited for protocols where
> you have variable-length strings, and in my experience, that is the vast
> majority of modern binary protocols on the Internet.
>

To be fair, the name "struct" implies a C-style structure, which
_does_ have a fixed size, or at least fixed offsets for its members
(the last member can be variable-sized). A quick search of PyPI shows
up a struct-variant specifically designed for network protocols:

https://pypi.python.org/pypi/netstruct/1.1.2

It even uses the dollar sign as you describe. So perhaps what you're
looking for is this module coming into the stdlib?

ChrisA


More information about the Python-ideas mailing list