Returns a slice representing the range of field ids that belong to this field. This slice can be used to index a list of fields. E.g.: >>> s = Struct( >>> ('a', Scalar()), >>> ('b', Struct( >>> ('b1', Scalar()), >>>
(self)
| 150 | self._parent = (parent, relative_id) |
| 151 | |
| 152 | def slice(self): |
| 153 | """ |
| 154 | Returns a slice representing the range of field ids that belong to |
| 155 | this field. This slice can be used to index a list of fields. |
| 156 | |
| 157 | E.g.: |
| 158 | |
| 159 | >>> s = Struct( |
| 160 | >>> ('a', Scalar()), |
| 161 | >>> ('b', Struct( |
| 162 | >>> ('b1', Scalar()), |
| 163 | >>> ('b2', Scalar()), |
| 164 | >>> )), |
| 165 | >>> ('c', Scalar()), |
| 166 | >>> ) |
| 167 | >>> field_data = ['da', 'db1', 'db2', 'dc'] |
| 168 | >>> field_data[s.b.split()] |
| 169 | ['db1', 'db2'] |
| 170 | """ |
| 171 | base_id = self._child_base_id() |
| 172 | return slice(base_id, base_id + len(self.field_names())) |
| 173 | |
| 174 | def _child_base_id(self, child_index=None): |
| 175 | """Get the base id of the given child""" |
nothing calls this directly
no test coverage detected