Can python objects have nested properties?
hierarchy, nested, nested-properties, object, python
Solution
The traceback is because your property doesn't have a `return` statement, hence it returns `NoneType`, which obviously can't have attributes of its own. Your property would probably need to return an instance of a different class, that has its own `prop` attribute. Something like this:
class a():
def __init__(self):
self.b = b()
@property
def prop(self):
print("hello from object.prop")
return self.b
class b():
@property
def prop(self):
print("Hello from object.prop.prop")
x = a()
print x.prop.prop
>> hello from object.prop
>> Hello from object.prop.prop
>> None
Problem
I have an object defined as follows ``` class a(): @property def prop(self): print("hello from object.prop") @property def prop1(self): print("Hello from object.prop.prop") ``` When I call ``` >>> obj = a() >>> obj.prop hello from object.prop >>> obj.prop.prop ``` I get the following traceback error ``` Traceback (most recent call last): File "object_property.py", line 13, in <module> a.prop.prop1 AttributeError: 'NoneType' object has no attribute 'prop1' ``` What I am trying to figure out is if I can define nested properties for objects?