Calling python function form C++ passing a dictionary

Thomas Heller theller at
Thu Jan 30 22:04:10 CET 2003

Michael Andersson <a98mican at> writes:

> Hi!
> I'm trying to call a python function form my c++ program but the
> function is never called. The function expect a dictionary as an
> argument so the call from C++ looks like this:
> PyObject* dict = PyDict_New();
> PyObject *time = PyInt_FromLong(0);
> PyDict_SetItemString(dict, "time", time);
> PyObject_CallObject(function, dict);
> It works fine for tuples but not for dictionarys.
> Any ideas?

Here's what the docs say about PyObject_CallObject:

  Call a callable Python object callable_object, with arguments given
  by the tuple args.
You probably want
  PyObject_CallFunction(function, "O", dict);

And you need to check the return value, if it's NULL, there has been an error!


More information about the Python-list mailing list