Python/C: unsigned Py_BuildValue, PyInt_FromLong

Mike C. Fletcher mcfletch at
Wed Feb 25 21:48:18 CET 2004

You're likely looking for:


Unsigned ints can be longer than Python 32-bit signed integers, so 
either do a check for the high-bit being set and use 
PyLong_FromUnsignedLong for that case and PyInt_FromLong otherwise, or 
just always use PyLong_FromUnsignedLong and eat the slight performance 
penalty of having longs everywhere.


Christian Vogel wrote:

>Hi comp.lang.python readers,
>are there routines to create a Python integer from unsigned C-integers?
>I only could find Py_BuildValue[1] and PyInt_FromLong[2] which both only use
>signed c-integers. Is there another way I overlooked?
>        ParseValue knows "k" for unsigned long, BuildValue doesn't.
>        PyInt_FromLong only uses a signed integer.
>        Chris
  Mike C. Fletcher
  Designer, VR Plumber, Coder

More information about the Python-list mailing list