PyArg_Parse vs PyArg_ParseTuple

David Brady chalain42 at
Wed Oct 17 18:11:40 CEST 2001

>-----Original Message-----
 > From: Ignacio Vazquez-Abrams [mailto:ignacio at]
 > Sent: Tuesday, October 16, 2001 7:42 PM
 > > I read in the documentatian that PyArg_Parse() is
 > deprecated, so I would
 > > like to get this working correctly.
 > You're misunderstanding what PyArg_Parse() and
 > PyArg_ParseTuple() are used
 > for. They are used for when a C function is called by a
 > Python program, not
 > the other way around. In your case you should probably be
 > using one of the
 > PyInt_As*() or PyLong_As*() functions.

Okay, two things.  First, thank you for replying!  The python list is as
responsive and useful as the language!

Second, I'm a little confused by your explanation.  The code I posted is
copied almost straight from Programming Python (2e, p1157,

Also, my reading of Programming Python, Python Essential Reference, and
the online Extending/Embedding Tutorial has led me to believe that
Py_BuildValue() for moving data from C types to Python types, and
PyArg_Parse*() are for going the other direction.  The only difference
between embedding and extending is that the order of their use is
reversed.  Extensions in C have to Parse the arguments passed in from
Python, and have to Build the return value, whereas embedding code has
to Build the arguments and Parse the return.  In both cases, C-to-Python
is a Build, where Python-to-C is a Parse.

I may be wrong.  But at least this lets you know I'm trying!  :-)

Thank you for pointing out PyInt_As* and PyInt_From*.  They appear to do
exactly what I need in this case as well.  After reading their
documentation, I think the difference between 'val = PyInt_AsLong(parg)'
and 'PyArg_Parse(parg, "d", &val)' is that PyArg_Parse() could handle
more than one object at a time, where PyInt_AsLong() requires that I
pass it a single PyObject that contains an integer.  Do I understand
this correctly?

Finally, this brings me back to my original question.  Why does
PyArg_ParseTuple() not work?  I should point out that this is ultimately 
intended for an embedded macro language, so there will have to be some 
extension code involved eventually as well.

Thank you again,

David Brady
dbrady at
I'm feeling very surreal today... or am I?

Get your FREE download of MSN Explorer at

More information about the Python-list mailing list