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

2024-09-25 00:32:58 发布

您现在位置:Python中文网/ 问答频道 /正文

[[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 ",所以我对如何只提取重要信息感到困惑


Tags: torect列表dataobjecttopresultwidth
1条回答
网友
1楼 · 发布于 2024-09-25 00:32:58

在您的示例中,条形码数据嵌套在单个元素列表中,因此您必须在创建列表期间处理该问题,或者使用[0]正确寻址嵌套列表的索引0:

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

相关问题 更多 >