如何从列表中提取解码数据?

How to extract Decoded data from a list?

[[Decoded(data=b'AZ:HP7CXNGSUFEPZCO4GS5RQPY6XY', rect=Rect(left=37, top=152, width=94, height=97)),Decoded(data=b'AZ:1EBWZS6F15BDFNK7SK5Y5N3X5U', rect=Rect(left=2616, top=1414, width=108, height=122))], [Decoded(data=b'AZ:9475EFWZCNARPEJEZEMXDFHIBI', rect=Rect(left=32, top=191, width=90, height=88)),Decoded(data=b'AZ:1EBWZS6F15BDFNK7SK5Y5N3X5U', rect=Rect(left=2616, top=1414, width=108, height=122))], [Decoded(data=b'AZ:6ECWZUQGEJCR5EZXDH9URCN53M', rect=Rect(left=48, top=183, width=88, height=89))], [Decoded(data=b'AZ:XZ9P6KTDGREM5KIXUO9IHCTKAQ', rect=Rect(left=73, top=121, width=91, height=94))]]

我有一个像上面这样的列表,上面的列表被命名为result

现在我只想从列表中的所有列表中提取 AZ:HP7CXNGSUFEPZCO4GS5RQPY6XY

我试过了

循环检测到的条形码

for barcode in result:

    # the barcode data is a bytes object so if we want to draw it on
    # our output image we need to convert it to a string first
    barcodeData = barcode.data.decode("utf-8")

但是我得到 list object has no attribute "data ",所以我对如何只提取重要信息感到困惑。

根据您的示例,条形码数据嵌套在单个元素列表中,因此您必须在列表创建期间注意这一点,或者使用 [0] 正确处理嵌套列表的索引 0:

data_list = list()
for entry in result:
    for barcode in entry:
        data_list.append(barcode.data.decode("utf-8"))