NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

Changeset 263

Show
Ignore:
Timestamp:
11/30/09 12:55:39
Author:
cbc
Message:

Document three solutions for adding keys as attributes to child of dict (Observation class).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sodar/branches/scintec-branch/sodar/scintec/maindata.py

    r262 r263  
    211211        True 
    212212        """ 
    213  
     213         
    214214        super(Observation, self).__init__() 
    215215         
    216216        self.update(dict(zip(variables,data))) 
     217        #self.__dict__.update(self) 
     218     
     219        def _getPropertyFactory(name): 
     220            """ 
     221            """ 
     222             
     223            def _getProperty(self): 
     224                return self[name] 
     225            return _getProperty 
     226         
     227        for variable in variables: 
     228            setattr(self.__class__,variable,property(_getPropertyFactory(variable))) 
     229     
     230    #def __getattr__(self,name): 
     231    #    """ 
     232    #    """ 
     233    #     
     234    #    if name in self: 
     235    #        return self[name] 
     236    #    else: 
     237    #        raise AttributeError, ' '.join([repr(self.__class__.__name__), 
     238    #                                        'object has no attribute', 
     239    #                                        repr(name)]) 
    217240 
    218241def _test():