我意识到这是一个问题,在这个论坛上已经提出了多个解决方案,但我写了一个代码并得到了一个我不理解的错误,所以这主要是我所做的事情。我在这里问。
这是我的代码:
from datetime import datetime
class SMSstore:
store = []
read = []
unread =[]
def addNewArrival(number,time,text):
SMSstore.store.append(("From: {}, Recieved: {}, Msg: {}".format(number,time,text)))
def messageCount():
return print("Number of Messages in Inbox: {}".format(len(SMSstore.store)))
def viewall():
print(SMSstore.store)
def getUnreadIndexes():
for message in SMSstore.store:
if message[0] == False:
unread.append(self.__inbox.index(message))
return unread
def getMessage(i):
SMSstore.read.append(len(SMSstore.store))
print(SMSstore.store[i])
def delete(i):
try:
del SMSstore.store[i]
except IndexError:
print("Index is out of range. Cannot delete")
def clear():
del SMSstore.store
time = datetime.now().strftime('%H:%M:%S')
myInbox = SMSstore()
myInbox.addNewArrival("1234567890",time,"What is your name?")
myInbox.addNewArrival("0987654321",time,"What is your quest?")
myInbox.viewall()
myInbox.msgcount()
myInbox.delete(i)
myInbox.clear()
我得到的错误是:
line 37, in <module>
TypeError: addNewArrival() takes exactly 3 arguments (4 given)
答案 0 :(得分:0)
你需要把self作为一个类中所有方法的第一个arg。
示例:
def addNewArrival(self, number, time, text):
def messageCount(self):
def viewall(self):
更多信息here