News for hackers. Stuff that matters.
Re:Working with Binary Data in Python by joiguru on Monday December 07, 2015 @07:08AM (#10688897)
While I understand the ease of use pure Python provides, I think when manipulating real binary or in memory data, a little bit of C would really simplify and speed things up.

Writing raw C extensions can be a pain, but with Cython or CFFI using C from Python has become extremely easy.

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.
Re:Working with Binary Data in Python by rch on Monday December 07, 2015 @10:37AM (#10690056)
This seems intuitively obvious, but can you think of an example that wouldn't be answered with a competitive implementation using Cython or Numba?