Asked
Active
Viewed 353 times
8
-
2Nope, an *octet* is 8 bits. Incidentally, most bytes nowadays are an octet wide. :) – Michael Foukarakis Jun 03 '11 at 05:25
1 Answers
6
C/C++ function signatures are written with C/C++ types, like "int" or "double" or "uint32_t". All of these have corresponding ctypes equivalents, so normally you do not care about the number of bits.
That said...
import os
print os.sysconf('SC_CHAR_BIT')
...is about as close as you will get, I think. Does not work on non-Unix platforms. And as tMC points out in the comments, it does not even work on all Unix platforms; I believe it is a GNU extension.
[update]
Actually, the POSIX spec appears to mandate CHAR_BIT == 8. So on any system that supports the SC_CHAR_BIT sysconf selector, you do not actually need it :-).

Nemo
- 70,042
- 10
- 116
- 153
-
2FWIW- on OSX 10.7 on the included Python 2.6; that conf doesn't exist. `os.sysconf('SC_CHAR_BIT')` - `ValueError: unrecognized configuration name` – tMC Jun 03 '11 at 05:35
-