Get the Field object at the specified index, which may be either an integer or the Field's string label. Note that the Field object is not the field's _value_ -- use the `get` method instead to retrieve the value (e.g. an integer) instead of a Field instance.
(self, index)
| 29 | self._layer = layer |
| 30 | |
| 31 | def __getitem__(self, index): |
| 32 | """ |
| 33 | Get the Field object at the specified index, which may be either |
| 34 | an integer or the Field's string label. Note that the Field object |
| 35 | is not the field's _value_ -- use the `get` method instead to |
| 36 | retrieve the value (e.g. an integer) instead of a Field instance. |
| 37 | """ |
| 38 | if isinstance(index, str): |
| 39 | i = self.index(index) |
| 40 | elif 0 <= index < self.num_fields: |
| 41 | i = index |
| 42 | else: |
| 43 | raise IndexError( |
| 44 | "Index out of range when accessing field in a feature: %s." % index |
| 45 | ) |
| 46 | return Field(self, i) |
| 47 | |
| 48 | def __len__(self): |
| 49 | "Return the count of fields in this feature." |