Python 2.7 在python中访问元组成员

Python 2.7 在python中访问元组成员,python-2.7,Python 2.7,我正在访问元组的内容。每次运行代码时,我都会得到超出范围的错误消息索引。我尝试使用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 sel

我正在访问元组的内容。每次运行代码时,我都会得到超出范围的错误消息索引。我尝试使用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
#检查朋友选择
myTuple=chat\u FriList.get(0,结束)
tup=chat\u FriList.curselection()
selected_friends=Listbox()#保存所选好友进行群聊
所选朋友。删除(0,结束)
对于tup中的项:
user=myTuple[int(tup[item])]
所选朋友。插入(最终,用户)
如果(len(tup)!=0):
打印“所选名称:”+myTuple[int(tup[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]

哪一行给出了错误?您能显示完整的错误消息并进行回溯吗?您可以使用索引而不是项索引到元组中。因此,如果您的元组是
('a','b','c')
,那么
tup[0]
是'a',
tup['a']
是一个错误。您可以发布完整的回溯吗?索引器可以来自两个地方,因为您使用的是一行。为什么不进一步分解一行代码,看看哪个元组的索引不正确。文件“C:\Users\christos\Documents\PYTHON\u FILES\client\u guiVersion5\u groupchat.py”,第224行,在ClickAction user=myTuple[int(tup[item])]索引器中:元组索引超出范围