def get_label(self, label): """Get label as identified by index or name :throws KeyError: when label is not found """ # first search for name, verbatim try: return self.labels[label] except KeyError: pass # then search for index if isinstance(label, int) or label.isdigit(): for i in self.labels.values(): if i.index == int(label): return i raise KeyError(label)
def get_label(self, label): '''Get label as identified by index or name :throws KeyError: when label is not found ''' # first search for name, verbatim try: return self.labels[label] except KeyError: pass # then search for index if label.isdigit(): for i in self.labels: if i.index == int(label): return i raise KeyError(label)