[C++-sig] Creating a dictionary to pass to python
David Sveningsson
eXt at sidvind.com
Sat Jan 13 22:34:10 CET 2007
Stefan Seefeld skrev:
> David Sveningsson wrote:
>> Hi, using boost I would like to create a dictionary and pass it to
>> python. Is this possible?
>
> Yes.
>
> (To get a more substantial answer you'd need to provide a more substantial
> question. ;-) )
>
> Regards,
> Stefan
>
I might have partially solved it.
At the moment I use this code:
PyObject* getDict(){
PyObject* m = PyDict_New();
PyDict_SetItem(m, PyString_FromString("test"), PyFloat_FromDouble(4.6f);
return m;
}
And have exported it like this:
def("getDict", &getDict);
But this seems to leak some memory. I guess I should use
manage_new_object as a return policy but when I do I get a segfault. It
seems like it tries to use free but should use delete instead.
Is this the "right" way or should I do it some other way? What about
memory leakage?
--
//*David Sveningsson [eXt]*
Freelance coder | Game Development Student
http://sidvind.com
Thou shalt make thy program's purpose and structure clear to thy fellow
man by using the One True Brace Style, even if thou likest it not, for
thy creativity is better used in solving problems than in creating
beautiful new impediments to understanding.
More information about the Cplusplus-sig
mailing list