Home > Software engineering >  How to read element in list item in Python?
How to read element in list item in Python?

Time:03-13

I have the following output from a function and I need to read shape, labels, and domain from this stream.

[Annotation(shape=Rectangle(x=0.0, y=0.0, width=1.0, height=1.0), labels=[ScoredLabel(62282a1dc79ed6743e731b36, name=GOOD, probability=0.5143796801567078, domain=CLASSIFICATION, color=Color(red=233, green=97, blue=21, alpha=255), hotkey=ctrl 3)], id=622cc4d962f051a8f41ddf35)]

I need them as follows

shp = Annotation.shape
lbl = Annotation.labels
dmn = domain

It seems simple but I could not figure it out yet.

CodePudding user response:

Given output as a list of Annotation objects:

output = [Annotation(...)]

you ought to be able to simply do:

shp = output[0].shape
lbl = output[0].labels
dmn = labels[0].domain
  • Related