Python-如何从构造解析器访问Container函数内的嵌套值

时间:2019-07-12 08:33:38

标签: python construct

因此,我正在使用在Python中使用Construct模块的项目。我正在尝试访问容器中的值,但是抛出一个错误。

要获得以下声明,我使用了types[i].fieldlist

**Container Structure:**
 length = 90
 tpi_idx = 4407
 leaf_type = (enum) LF_FIELDLIST 4611
 substructs = ListContainer
    Container:
       leaf_type = (enum) LF_MEMBER 5389
       ....

到目前为止,我已经尝试过

`str(types[i].fieldlist.length)` = AttributeError: 'EnumIntegerString' object has no attribute 'length'

`str(types[i].fieldlist[0]) = Just returns 'T'

`str(types[i].fieldlist['length'] = Sting indices must be integers

代码如下:

for i in types:
        if types[i].leaf_type == "LF_FIELDLIST":
            types[i].substructs = ListContainer([resolve_typerefs(t, types, min) for t in types[i].substructs])
            # f.write(str(types[i].substructs))
        elif types[i].leaf_type == "LF_STRUCTURE":
            if types[i].name == "stack_st":

                types[i] = resolve_typerefs(types[i], types, min)
                #
                # items = types[i].items()
                # # for k, v in items:
                # #     print(str(k), str(v))
                f.write(str(types[i]))
                # print(types[i])
                print(str(types[i].fieldlist['length']))
        else:
            types[i] = resolve_typerefs(types[i], types, min)

到目前为止,我已经尝试过 str(types[i].fieldlist.length) = AttributeError:“ EnumIntegerString”对象没有属性“ length”

`str(types [i] .fieldlist [0])=仅返回'T'

`str(types [i] .fieldlist ['length'] =索引索引必须为整数

0 个答案:

没有答案