I'm new to Python so please excuse if I've glazed over something simple to do this.
I have an object like this:
class myObject(object):
def __init__(self):
self.attr1 = None
self.attr2 = None
@property
def prop1(self):
return foo.some_func(self.attr1)
And I instantiate it like this:
a = myObject()
a.attr1 = 'Apple'
a.attr2 = 'Banana'
And the method it's all wrapped in expects a return of dict, so I do this:
return a.__dict__
but prop1
is not included in the return. I understand why this is, it's not in the object's __dict__
because it only holds real attributes.
So the question is, how can I make my return, return something like this:
{'attr1': 'Apple', 'attr2': 'Banana', 'prop1': 'ModifiedApple'}
other than right before the return doing:
a.prop1_1 = a.prop1