值为对象时如何打印字典(Python)

值为对象时如何打印字典(Python),python,object,dictionary,printing,mapping,Python,Object,Dictionary,Printing,Mapping,myDict={name1:object1、name2:object2等…} *对象如下所示: Color: Blue, Flies: True, etc... Item1: --> Key (it's the name of the object) Color: Blue --> Value (this is object[0]) Flies: True --> Value (this is object[1]) e

myDict={name1:object1、name2:object2等…}

*对象如下所示:

Color: Blue, Flies: True, etc...
Item1:              --> Key (it's the name of the object)
Color: Blue         --> Value (this is object[0])
Flies: True         --> Value (this is object[1])
etc....
编辑:包含在上面的字典中,以便您可以看到我正在使用的内容

在研究如何以美观易读的方式打印前面的词典时,我尝试了以下代码:

for key in myDict:
        print (key)
        for value in myDict[key]:
            print (value, ":", myDict[key][value])
这是可行的,但是,我的“值”都是对象,它表示它不能迭代(这很有意义)。我只是想知道,如果值是一个列表或是一些可编辑的东西,如何使它像它那样工作

我想要的输出格式如下:

Color: Blue, Flies: True, etc...
Item1:              --> Key (it's the name of the object)
Color: Blue         --> Value (this is object[0])
Flies: True         --> Value (this is object[1])
etc....

谢谢

您可以捕获在尝试迭代非iterable时发生的
TypeError
(不过可能希望对字符串进行例外)


什么是“跟随字典”?大多数对象都有
\uuuu dict\uuuu
字典。在您的情况下:您只需将
myDict[key]
替换为
myDict[key]。\uuuu dict\uuuu
@tessellingheckler刚刚做了一个edit@SuperSaiyan谢谢我知道有一个。我只是不太确定如何使用它。我会试试的。可能是重复的