Working with Binary Data in Python
devdungeon.com
devdungeon.com
np.fromfile('data.dat', dtype='uint8')
https://docs.scipy.org/doc/numpy/reference/generated/numpy.f...
EDIT: Obviously you have the added benefit that your data is returned into a numpy array for easy reshaping etc
What I mean by that is I literally have data stored in memory, and I want to deal with it in arbitrary groups of bits.
Sometimes 1 bit, sometimes 7 bits, rarely 13 bits.
My Google's haven't turned up much precedent.
</off topic complaint>
Edit: sorry, it was bitstring, not bitarray. bitstring.BitArray :).
Disclosure: I'm the primary author/maintainer of suitcase (https://github.com/digidotcom/python-suitcase). In your example, you can shave off a line by doing the following:
example = FIDOAttestation.from_data(a)I'm trying various not-regex syntaxes. My motivation is: we all agree regex is bad, but we keep using it because it's available everywhere and hence the least common denominator (a schelling point). What would it take to get beyond regex as the goto pattern matching/parsing? At least for casual use.
http://amnesia.gtisc.gatech.edu/~moyix/minidump.py
Explanation:
http://moyix.blogspot.com/2008/05/parsing-windows-minidumps....
A colleague of mine recently developed a similar (from the looks of it) library, in Python and Javascript:
Writing raw C extensions can be a pain, but with Cython or CFFI using C from Python has become extremely easy.
In what sense? Accessing an octet in a buffer and performing basic bitwise operations on it is equivalent:
# C _and_ Python
some_buffer[idx] & 0x80
Reading a buffer in Python is slightly less error-prone, as errors are automatically converted to exceptions, which can be caught at a more centralized location in the code; in C, one must check for errors (and manually propagate those errors) at every read; this applies a bit less in C++, though even there, the stdlib leaves some things to be desired (but generally speaking, they can be wrapped away).Text encoding/decoding, struct packing, and base64 aren't in C or its standard library.
Now, in terms of speed, C wins hands down. (I wrote a minecraft file parser in both C++ and Python, and the difference was several orders of magnitude.)
Cool thing about Elixir is of course that awesome Erlang binary handling is available and very easy to use.
Lots of people have been lobbying for something like this in Rust, given its low-level orientation, but there's been resistance to the idea from the core devs, who want it to be done using syntax extension.
1. https://rwmj.wordpress.com/2010/02/03/on-the-awesomeness-of-...
Unless you were implying that such work is best done in another language. I can buy that, but I found Python to be a convenient choice for it.