PyArg_ParseTuple and float/double

Michael Gross mdgrosse at sbox.tugraz.at
Tue Jul 29 19:09:30 EDT 2003


I want to use Python to make it possible to do scripting in my 
application. So I write wrappers for my C++ classes. Everything works 
fine, but it seems, that I cant use float and double arguments with 
PyArg_ParseTuple:

PyArg_ParseTuple(args, "d", &double_1)  and
PyArg_ParseTuple(args, "f", &float_1)

always returns false.
I even looked at the args directly:
     PyObject* s = PyObject_Str(args);
     char *ss = PyString_AsString(s);

then ss maybe has the value "(2.5339999999999998,)".

It works, when I use an integer instead:

PyArg_ParseTuple(args, "i", &int_1)

But then of course the value is floored.
I tried with Python 2.2.2 and 2.2.3. I use PyRun_SimpleString to run the 
script.

tia
   Michael





More information about the Python-list mailing list