[Python-Dev] adding Construct to the standard library? (original) (raw)

Travis Oliphant oliphant.travis at ieee.org
Wed Apr 19 02:09:39 CEST 2006


Giovanni Bajo wrote:

tomer filiba <tomerfiliba at gmail.com> wrote:

the point is -- ctypes can define C types. not the TCP/IP stack. Construct can do both. it's a superset of ctype's typing mechanism. but of course both have the right to coexist -- ctypes is oriented at interop with dlls, and provides the mechanisms needed for that. Construst is about data structures of all sorts and kinds. ctypes is a very helpful library as a builtin, and so is Construct. the two don't compete on a spot in the stdlib. I don't agree. Both ctypes and construct provide a way to describe a binary-packed structure in Python terms: and this is an overload of functionality. When I first saw Construct, the thing that crossed my head was: "hey, yet another syntax to describe a binary-packed structure in Python". ctypes uses its description to interoperate with native libraries, while Construct uses its to interoperate with binary protocols. I didn't see a good reason why you shouldn't extend ctypes so to provide features that it is currently missing. It looks like it could be easily extended to do so.

For what it's worth, NumPy also defines a data-type object which it uses to describe the fundamental data-type of an array. In the context of this thread it is also yet another way to describe a binary-packed structure in Python.

This data-type object is a builtin object which provides information such as byte-order, element size, "kind" as well as the notion of fields so that nested structures can be easily defined.

Soon (over the next six months) a basic array object (a super class of NumPy) will be proposed for inclusion in Python. When that happens some kind of data-type object (a super class of the NumPy dtype object) will be needed as well.

I think some cross-talk between all of us different users of the notion of what we in the NumPy community call a data-type might be useful.

-Travis Oliphant



More information about the Python-Dev mailing list