我正在处理事件和数据库类。在
我创建了一个while循环,它将继续在数据库中追加事件(对象)。
还有一个命令,只要用户不输入“exit”命令,它就会一直在if主块中运行。在
我的问题是,每当命令要求添加一个事件时,以前的事件每次迭代都会被删除。在
单词“event”的作用类似于命令“exit”,因此每当这个单词与事件字符串一起键入时(我已经实现了一个将事件字符串转换为事件对象的函数)。它将继续向数据库中添加事件对象。在def parse(command):
'''Parse a command string.'''
# gist of event class Event(description, time, date, duration) not part of this function event string could be: '"Movie night" today 10:00pm'
store_event = Database() # where I should save my event objects
cmd_str = command.split()
a_lst =[]
while cmd_str[0] == "event": #while event is a command that the user wants
cmd_str = command.split()
cmd_str.pop(0) # I don't need the word "event" just the event string after it.
new_str = ' '.join(cmd_str)
an_event = parseevent(new_str) # converts string object to event objects
a_lst.append(an_event)
谢谢!在