我正试图建立/更新字典。我的昵称是temp_dict中的键,正在寻找要添加的id。
我的代码摘录。我想这足以让你看到我的错误。
d1 = {u'status': u'ok', u'count': 1, u'data': [{u'nickname': u'45sss', u'account_id': 553472}]}
temp_dict = {}
for key, value in d1.iteritems():
if "data" == key:
for dic2 in value:
x = dic2['nickname']
y = dic2['account_id']
temp_dict[x] = y;
我的错误:
Traceback (most recent call last):
File "untitled.py", line 36, in <module>
get_PlayerIds_Names_WowpApi_TJ_() #Easy going. Some issues with case letters.
File "g:\Desktop\Programming\WOWP API\functions.py", line 44, in get_PlayerIds_Names_WowpApi_TJ_
check_missing_player_ids(basket)
File "g:\Desktop\Programming\WOWP API\functions.py", line 195, in check_missing_player_ids
temp_dict[x] = y;
TypeError: 'unicode' object does not support item assignment
同一错误有多个SO条目。但没有人与这种字典操作有关联。
很有可能你把unicode字符串放在temp_dict的某个地方:
用空的dict初始化它,所有的都将工作:
相关问题 更多 >
编程相关推荐