class ParameterObject: def __init__( self, sParameterName ): self.name = sParameterName self.value = True class ParameterCollection: def __init__( self ): self.name = 'Parameters' def __call__( self, sParameterName ): if sParameterName == 'viewvis': return ParameterObject( sParameterName ) else: return None class PropertyObject: def __init__( self, sPropertyName ): self.name = sPropertyName def __getattr__( self, sAttribute ): if sAttribute == 'Parameters': return ParameterCollection() else: return None class PropertyCollection: def __init__( self ): self.name = 'Properties' def __call__( self, sPropertyName ): """ Let's intercept the calls made to this instance. If the name used matches a set of predefined properties, return the corresponding class instance. """ if sPropertyName == 'visibility': return PropertyObject( sPropertyName ) else: return None def __getitem__( self, i ): """ Let's do some loop over this instance! For each iteration, return a new instance of PropertyObject. """ return PropertyObject( aPROPERTIES[i] ) class X3DObject: def __init__( self ): self.name = 'object' self.type = 'polymsh' def __getattr__( self, sAttribute ): """ Let's intercept some of the attribute qualifications attempted on this instance. If these attributes match a set of predefined attributes, return the corresponding class instance. """ if sAttribute == 'Properties': # User is using "Properties", let's give him an instance return PropertyCollection() else: return None oObject = X3DObject() print oObject.Properties( 'visibility' ).name print oObject.Properties( 'visibility' ).Parameters( 'viewvis' ).value