[C++-sig] create a python object from scratch in boost.python?
Gary Oberbrunner
garyo at genarts.com
Tue Jan 21 00:14:46 CET 2014
I'd like to create a python object with some attributes in C++, and return it to python. Something like this:
Plugin_Info *pinfo = get_plugin_info_i(i);
bp::object plugin; // this creates None; how can I make an empty class?
plugin.attr("name") = std::string(pinfo->plugin_name);
plugin.attr("category") = std::string(pinfo->category);
plugin.attr("n_effects") = (int)pinfo->n_effects;
plugin.attr("n_inputs") = (int)pinfo->n_inputs;
plugin.attr("custom_p") = (int)pinfo->custom_p;
effect_list.append(plugin);
But this fails on the third line, because the "plugin" object is None, and None has no attributes. Instead of None, I'd like to create a simple empty python class I can add attributes to. How can I do that? (Yes, I could use a dict instead but the python side would like to see attributes with values rather than a dict.)
--
. . . . . . . . . . . . . . . . . . . . . .
Gary Oberbrunner garyo at genarts.com
VP Engineering Tel: 617-492-2888
GenArts, Inc. www.genarts.com
More information about the Cplusplus-sig
mailing list