Long integers getting short shrift?

Charles G Waldman cgw at fnal.gov
Tue Apr 27 16:52:21 EDT 1999


The functions Py_BuildValue and PyArg_ParseTuple don't seem to be
listed in the index of the Python/C API documentation.  They are only
described in the Embedding and Extending docs.

The "L" format code for Long integers is not described anywhere,
AFAICT.  I discovered it by reading source.

It seems that if you are on a system without the "long long" type then 
the "L" format char is not available.   The "L" format performs the
same function as the "PyLong_FromLongLong" function, but there's no
format character to get me the equivalent of "PyLong_FromLong".  So,
if I am calling a Python function from C which is expecting a long int 
as an arg, I am forced to write

result = PyObject_CallFunction(func, "O", PyLong_FromLong(x));

which isn't terrible but isn't as nice as writing

result = PyObject_CallFunction(func, "L", x);

which I can only do if the system has "long long" and x is of that
type...  I'd like to be able to get regular C integers into Python
long's.

One reason for wanting this is that I often use long's in Python to
hold what would be in C an "unsigned int" - since there's no
"unsigned" type in Python, to represent a 32-bit value without
sign-bit I use a Python long.













More information about the Python-list mailing list