访问字典中的对象列表

时间:2016-11-14 14:29:29

标签: python django

我如何打印出作为对象列表的字典值。更具体地说,来自对象的属性

字典打印的输出

    for keys,values in Dict.items():
        print(keys)
        print(values)

Five
[<VocabContent: Seven - 7>, <VocabContent: Ten - 10>, <VocabContent: Six - 6>, <VocabContent: Eight - 8>, <VocabContent: Five - 5>]
Eight
[<VocabContent: Ten - 10>, <VocabContent: Eight - 8>, <VocabContent: Six - 6>, <VocabContent: Five - 5>, <VocabContent: Seven - 7>]

这些对象具有西班牙语和音频属性。我试图用

打印对象spanish属性
for keys,values in Dict.items():
    print values.spanish

但它不起作用。我的网页只返回服务器错误500

如何从字典中访问对象属性

由于

1 个答案:

答案 0 :(得分:3)

你必须遍历列表的值

for keys,values in Dict.items():
    for value in values:
        print(value.spanish)