Beispiel #1
0
 def __getitem__(self, key):
     if isinstance(key, tuple):
         (ind, field) = key
         ind = _check_dims(self, ind)
         return self._get_field(field, index=ind)
     elif isinstance(key, str):
         if len(self) == 1:
             return self._get_field(key, index=0)
         else:
             return [self._get_field(key, index=ind) 
                     for ind in range(len(self))]
     elif isinstance(key, numbers.Number):
         ind = _check_dims(self, int(key))
         return dict((f,self[ind,f]) for f in self._get_fields())
     else:
         raise KeyError, ("I'm not sure what you want me to do "
                          "with a key of type %s" % type(key))
Beispiel #2
0
 def __setitem__(self, key, val):
     if isinstance(key, tuple):
         (ind, key) = key
     elif isinstance(key, str) and len(self) == 1:
         ind = 0
     else:
         raise KeyError, ("You'll have to set one index+field at "
                          "a time: self[ind, field] = foo")
     ind = _check_dims(self, ind)
     self._set_field(key, val, index=ind)
Beispiel #3
0
 def __getitem__(self, key):
     if isinstance(key, tuple):
         (ind, prop) = key
         ind = _check_dims(self, ind)
         return self._get_property(prop, index=ind)
     elif isinstance(key, str):
         if len(self) == 1:
             return self._get_property(key, index=0)
         else:
             return [self._get_property(key, index=ind) 
                     for ind in range(len(self))]
     ## We have no _get_properties function because MATLAB doesn't 
     ## provide it. Could probably try calling the "properties" method, 
     ## but that's a mex call.
     #elif isinstance(key, numbers.Number):
     #    ind = _check_dims(self, int(key))
     #    return dict((p,self[ind,p]) for p in self._get_properties())
     else:
         raise KeyError, ("I'm not sure what you want me to do with "
                          "a key of type %s" % type(key))
Beispiel #4
0
 def __call__(self, *ind):
     return _structel(self, _check_dims(self,ind))
Beispiel #5
0
 def __setitem__(self, ind, val):
     ind = _check_dims(self, ind)
     self._set_cell(ind, val)
Beispiel #6
0
 def __getitem__(self, ind):
     ind = _check_dims(self, ind)
     return self._get_cell(ind)