PyArg_Parse vs PyArg_ParseTuple
David Brady
chalain42 at hotmail.com
Tue Oct 16 21:27:42 EDT 2001
Hello,
I'm new to Python, and I've searched the archives for more info but can't
seem to find the info I need. I am having trouble using PyArg_ParseTuple().
Here is the python code I'm embedding:
# TestModule.py
def NumberFunction(x):
return x+1
As you see, it's not too complex. :-) This is just a proof of concept I'm
working on to prove it can be done.
Here is the code I'm trying to embed it in. Note: this is C++, does that
make a difference in this case?
// TestEmbed.cpp
#include <stdio.h>
#include <Python.h>
void main(void)
{
long val = 7;
PyObject *pmod, *pfunc, *pargs, *pstr;
PyInitialize();
printf( "Processing data: %ld\n", val );
pmod = PyImport_ImportModule( "TestModule" );
pfunc = PyObject_GetAttrString( pmod, "NumberFunction" );
pargs = Py_BuildValue( "(l)", val );
pstr = PyEval_CallObject( pfunc, pargs );
// *** This code works ***
PyArg_Parse( pstr, "l", &val );
// *** This code does NOT work ***
//PyArg_ParseTuple( pstr, "l", &val );
printf( "Val returned was %d\n", val );
}
If I use the ParseTuple version, the code appears to run fine, but val is
unchanged. I've tried using "(l)" as the string but I'm grasping at straws
here.
I read in the documentatian that PyArg_Parse() is deprecated, so I would
like to get this working correctly.
Thank you!
Oh, this is Python 2.1.1 on Windows 2000. (Not ActivePython.)
-David
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
More information about the Python-list
mailing list