[C++-sig] create a python object from scratch in boost.python?

Gary Oberbrunner garyo at genarts.com
Tue Jan 21 17:03:48 CET 2014



----- Original Message -----
> From: "Stefan Seefeld" <stefan at seefeld.name>
> To: "Development of Python/C++ integration" <cplusplus-sig at python.org>
> Sent: Tuesday, January 21, 2014 10:45:52 AM
> Subject: Re: [C++-sig] create a python object from scratch in boost.python?
> 
> On 01/21/2014 10:37 AM, Gary Oberbrunner wrote:
> > So now it returns a python list of python dicts. All I want now is
> > to
> > override __getattr__ on each ppinfo dict so it returns the dict
> > value
> > as the attribute value, so in python I can reference
> > effect_list[i].name instead of effect_list[i]['name']. Or any
> > alternative way to get the same effect. Is that possible?
> There are many ways to do that elegantly in Python. For example:
> 
> class Effect:
>   def __init__(self, mydict):
>     self.__dict__.update(mydict)

I like the idea of using self.__dict__.  If that's accessible from C++, then I suppose I could have an empty C++ class, export that as a simple container, and dynamically add attributes to it by manipulating its __dict__.  Does that seem possible?

-- 
Gary Oberbrunner


More information about the Cplusplus-sig mailing list