[C++-sig] create a python object from scratch in boost.python?
Stefan Seefeld
stefan at seefeld.name
Tue Jan 21 16:45:52 CET 2014
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)
If you want to combine that with existing classes / APIs, you could also
consider merging the new attributes in via metaclasses.
Stefan
--
...ich hab' noch einen Koffer in Berlin...
More information about the Cplusplus-sig
mailing list