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

Changeset 264

Show
Ignore:
Timestamp:
11/30/09 12:59:15
Author:
cbc
Message:

Choose getattr as solution for adding keys as attributes to child of dict (Observation class). Doesn't duplicate data like updating dict. Doesn't create attributes on class object instead of instance like properties. Can be controlled with setattr and delattr.

Files:

Legend:

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

    r263 r264  
    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)]) 
     217     
     218    def __getattr__(self,name): 
     219        """ 
     220        """ 
     221         
     222        if name in self: 
     223            return self[name] 
     224        else: 
     225            raise AttributeError, ' '.join([repr(self.__class__.__name__), 
     226                                            'object has no attribute', 
     227                                            repr(name)]) 
    240228 
    241229def _test():