Name
PyArg_ParseTuple
Synopsis
int PyArg_ParseTuple(PyObject*tuple
,char*format
,...)
Returns 0
for errors, a value not equal to
0
for success. tuple
is
the PyObject*
that was the C
function’s second argument.
format
is a C string that describes
mandatory and optional arguments. The following arguments of
PyArg_ParseTuple
are the addresses of the C
variables in which to put the values extracted from the tuple. Any
PyObject*
variables among the C variables are
borrowed references. Table 24-1 lists the commonly
used code strings, of which zero or more are joined to form string
format
.
Table 24-1. Format codes for PyArg_ParseTuple
Code |
C type |
Meaning |
---|---|---|
c |
char |
A Python string of length |
d |
double |
A Python |
D |
Py_Complex |
A Python |
f |
float |
A Python |
i |
int |
A Python |
l |
long |
A Python |
L |
long long |
A Python |
O |
PyObject* |
Gets non- |
O! |
type + PyObject* |
Like code |
O& |
convert + void* |
Arbitrary conversion (see below) |
s |
char* |
Python string without embedded nulls to C |
s# |
char* + int |
Any Python string to C address and length |
t# |
char* + int |
Read-only single-segment buffer to C address and length |
u |
Py_UNICODE* |
Python Unicode without embedded nulls to C (UTF-16) |
u# |
Py_UNICODE* + int |
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.