weixin_37608417 2018-04-08 10:10 采纳率: 0%
浏览 940
已结题

PYTHON的 NAMEDTUPLE 有关问题

在 pyzbar (通过它解析图片中的条形码) 里,

from pyzbar.pyzbar import (decode, Decoded)
from PIL import Image
decode(Image.open("Image"))
[Decoded(data='', type='',rect=Rect())]

在这里中,
Decoded 为

Results of reading a barcode
Decoded = namedtuple('Decoded', ['data', 'type', 'rect'])

这样的namedtuple

我想把 decode 后出来的 'data' 这个部分的字段拿出来继续用,
试过
Decoded.data
结果 = property object at xxxxxxx

试过
result = decode(Image.open("Image"))
result.data
结果 = AttributeError : 'list' object has no attribute 'data'

求帮忙。。

  • 写回答

2条回答 默认 最新

  • oyljerry 2018-04-08 12:17
    关注

    先打印Decoded的数据和类型,然后再对应的取字段

    评论

报告相同问题?