[Keith Dart] > In SNMP, for example, a Counter32 is basically an unsigned int, defined > as "IMPLICIT INTEGER (0..4294967295)". One cannot efficiently translate > and use that type in native Python. Currently, I have defined an > "unsigned" type as a subclass of long, but I don't think that would be > speed or storage efficient.
In my experience you can just use Python longs whenever a C API needs an "unsigned" long. There's no need to subtype, and your assumption that it would not be efficient enough is mistaken (unless you are manipulating arrays with millions of them, in which case you should be using Numeric, which has its own types for this purpose). (Want to argue about the efficiency? Write a typical use case and time it.) By far the easiest way to do arithmetic mod 2**32 is to just add "& 0xFFFFFFFF" to the end of your expression. For example, simulating the effect of multiplying an unsigned long by 3 would be x = (x * 3) & 0xFFFFFFFF. If there is a problem with ioctl() not taking long ints, that would be a bug in ioctl, not a lacking data type or a problem with long ints. -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com