Re:Working with Binary Data in Python
by deathanatos on Monday December 07, 2015 @12:01PM
(#10690697)
> when manipulating real binary or in memory data, a little bit of C would really simplify
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.)
Re:Working with Binary Data in Python
by icebraining on Monday December 07, 2015 @11:33AM
(#10690467)
Distributing that becomes much more of a pain, though. Unless it's a major component of the software, I'd really rather keep it in pure Python.
Writing raw C extensions can be a pain, but with Cython or CFFI using C from Python has become extremely easy.