2
我正在做Python中的字典现在,我试图访问profile.keys
和profile.items
命令。发生的所有事情就像<dict_values object at 0x107fa50>
一样。我该怎么办?Python字典
我正在做Python中的字典现在,我试图访问profile.keys
和profile.items
命令。发生的所有事情就像<dict_values object at 0x107fa50>
一样。我该怎么办?Python字典
如果你想遍历键:
for x in profile.keys():
print x
或值
for x in profile.values():
print x
或键值对:
for x, y in profile.items():
print x, y
或只分配到供以后使用一个变量
x = profile.items()
等
你必须这样调用profile.keys()
和profile.items()
。他们是方法。
如果省略括号,则实际上不会调用该函数。 取而代之,您将获得对该函数对象的引用。
>>> mydict = {'foo':'bar'}
>>> mydict.keys
<built-in method keys of dict object at 0x01982540>
>>> mydict.keys()
['foo']
>>>
你可以发布返回这个代码吗? – MDT 2012-02-10 02:40:10