On 26 March 2013 00:17, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > On Mon, 25 Mar 2013 16:16:05 -0700, Ethan Furman wrote: > [snip] >> If you're working with >> numbers, and speed is an issue, you really should be using one of the >> numeric or scientific packages out there. > [snip] > What I would like to see though is a module where I can import fixed- > width signed and unsigned integers that behave like in C, complete with > overflow, for writing code that matches the same behaviour as other > languages.
Numpy can do this: >>> import numpy >>> a = numpy.array([0], numpy.uint32) >>> a array([0], dtype=uint32) >>> a[0] = -1 >>> a array([4294967295], dtype=uint32) Unfortunately it doesn't work with numpy "scalars", so to use this without the index syntax you'd need a wrapper class. Also it uses Python style floor rounding rather than truncation as in C (actually I seem to remember discovering that in C this is implementation defined). Presumably ctypes has something like this as well. Oscar -- http://mail.python.org/mailman/listinfo/python-list