我的sc :::
if 'recheck' == msg.lower():
with open('Output.txt','r') as rr:
contactArr = rr.readlines()
for v in xrange(len(contactArr) -1,0,-1):
num = re.sub(r'\n', "", contactArr[v])
contacts.append(num)
pass
contacts = list(set(contacts))
for z in range(len(contacts)):
arg = contacts[z].split('|')
if arg[1] == receiver.id :
userList.append(arg[0])
timelist.append(arg[2])
uL = list(set(userList))
# print uL
for ll in range(len(uL)):
try:
getIndexUser = userList.index(uL[ll])
timeSeen.append(strftime("%H:%M:%S", localtime(int(timelist[getIndexUser]) / 1000)))
recheckData.append(userList[getIndexUser])
except IndexError:
conName.append('nones')
pass
contactId = client._getContacts(recheckData)
for v in range(len(recheckData)):
dataResult.append(contactId[v].displayName + '['+timeSeen[v]+']')
pass
# # print len(recheckData)
tukang = "V=ON Members=V\n[*]"
grp = '\n[*] '.join(str(f) for f in dataResult)
receiver.sendMessage("%s %s" % (tukang, grp))
但终端错误:
Traceback (most recent call last):
File "echobot.py", line 117, in <module>
if arg[1] == receiver.id :
IndexError: list index out of range
你能帮助我吗?
答案 0 :(得分:0)
错误来自
arg = contacts[z].split('|')
if arg[1] == receiver.id :
userList.append(arg[0])
timelist.append(arg[2])
您应该仔细检查您的联系人是否格式正确。 根据此代码,每个联系人应格式化为
用户| ID |时间
如果联系人中的每个联系人都没有完全按照这种方式格式化,则会抛出此错误。看起来你的分裂('|')功能没有找到任何'|'分裂。