我有这个 Python 代码:
sm.GetSMSStatus()
sm.GetSMSFolders()
sms = sm.GetNextSMS(Start = True, Folder=0)
sms = sm.GetNextSMS(Location = sms['Location'], Folder=0)
sms = sm.GetSMS(Location = loc, Folder = 0)
我得到了错误:
Traceback (most recent call last):
File "sms_teste.py", line 43, in <module>
sms = sm.GetNextSMS(Location = sms['Location'], Folder=0)
TypeError: list indices must be integers, not str
我做了什么试图解决:
首先,我一直在寻找相同问题的答案,但是我找不到任何相似的问题。
根据 sms 变量的打印,看看它返回什么,看看是如何分配 'Location' 的,这是打印上的:
[{'RejectDuplicates': 0, 'SMSCDateTime': datetime.datetime(2014, 7, 1, 16, 31, 58), 'Class': 1, 'Name': u'', 'InboxFolder': 0, 'Text': u'dsgfzggzdfrg', 'SMSC': {'DefaultNumber': u'', 'Format': 'Text', 'Number': u'+#####', 'Validity': 'Max', 'Location': 0, 'Name': u''}, 'ReplaceMessage': 0, 'Coding': 'Default_No_Compression', 'Number': u'+#####', 'DateTime': None, 'DeliveryStatus': 0, 'State': 'UnSent', 'MessageReference': 0, 'Length': 12, 'Location': 0, 'Memory': 'SM', 'ReplyViaSameSMSC': 0, 'UDH': {'Text': '', 'ID16bit': 0, 'AllParts': 0, 'ID8bit': 0, 'PartNumber': -1, 'Type': 'NoUDH'}, 'Type': 'Submit', 'Folder': 2}]
我注意到'Location'等于0,但是你到达那里的关键是'Location'但是现在我陷入了死胡同,当变量本身被制作时,如何将键字符串转换为整数字符串键?我正在使用 gammu,因此返回表单,因为函数的结果是预先格式化的。
有人可以帮我一把吗?
我希望我的信息对您有用,以便您理解我的问题 PS电话号码在###上是故意的