[英]Python TypeError: argument of type 'int' is not iterable problem
[英]TypeError: argument of type 'int' is not iterable in python for a dict
從過去的兩天開始,我一直在苦苦掙扎,基本上我想為 Close 標簽具有“-1”值的每個項目獲取 MeetingName。 if str(-1) in contents['Close']:
,錯誤發生在行上,有時它有效,有時它給出錯誤
def meetingHandler(message):
# path = str(message['path']).replace('/', '')
data = message['data']
#ended_meetings = []
if data is not None:
for name, contents in data.items():
if str(-1) in contents['Close']:
#ended_meetings.append(str(name))
p1 = str(contents['Port_1'])
p2 = str(contents['Port_2'])
VoIP.close_ports(str(p1), str(p2))
results = Constants.db.child('OnGoingMeetings').child(str(name)).remove()
else:
pass
這是dicts中的輸入數據。
<class 'dict'>: {'path': '/', 'data': {'Meeting_15911478': {'Close': -1, 'Port_1': '1245', 'Port_2': '2810'}, 'Meeting_15919478': {'Close': 0, 'Port_1': '1925', 'Port_2': '2310'}}, 'event': 'put'}
我試過 try except 子句,但仍然存在同樣的問題。 有人可以幫忙嗎?
據我所知,您的情況下contents['Close']
是(標量)-1(分別為 0)。 沒有集合,沒有列表,沒有包含該值作為成員的元組,因此很明顯in
操作將失敗。
您可能想說contents['Close'] == -1
,因為它不是字符串,而且將-1
轉換為str
也沒有意義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.