我正在访问元组的内容。每次运行代码时,我都会得到错误消息索引超出范围。我试图使用for循环来完成元组。 我已经尝试了一切并失败了。
代码如下:
# Check friend(s) selection
myTuple = chat_FriList.get(0,END)
tup = chat_FriList.curselection()
selected_friends = Listbox() # to hold selected friends for group chat
selected_friends.delete(0, END)
for item in tup:
user = myTuple[int(tup[item])]
selected_friends.insert(END, user)
if (len(tup) !=0):
print "Selected name:" + myTuple[int(tup[0])]
count=0
while count < len(friend_list):
msg = friend_list[count]
print selected_friends
if dpkg(msg)[3] in selected_friends: #dpkg(msg)[3] == myTuple[int(tup[0])]:
connect_client(myID, myPort, dpkg(msg)[1], int(dpkg(msg)[2]), 'C', EntryText)
count +=1
完整代码在此链接上。基本上我试图创建一个群聊。 大多数工作,但我努力与所选用户进行群聊。任何帮助将不胜感激。 看完整代码: client.py
答案 0 :(得分:0)
完全回答这个问题需要更多信息,但REPL中的以下示例应该会有所帮助。代表您进行更多调试可能是最好的策略。
a = ("a", "b", "c")
for item in a
print a[item]
a = (0, 1, 2)
for item in a
print a[item]
a = (10, 11, 21)
for item in a
print a[item]