【发布时间】:2016-09-03 18:38:22
【问题描述】:
我找到了this handy answer,了解如何使用字典创建新表条目。
现在我想用同样的方法更新一个条目。但我不知道如何处理我想更新的特定表条目。
我当前的版本是这样的:
entries = Fruit.select().order_by(Fruit.name.desc())
#... all entries are listed with the index number
entry_index = int(input("Please enter entry number: "))
#...
entry_index -= 1
name = "Banana"
color = "yellow"
if input('Update entry? [Yn] ').lower() != 'n':
entries[entry_index].name = name
entries[entry_index].color = color
如您所见,我明确地处理了每个字段。 我想将变量(名称、颜色)放入字典中,并使用前面提到的双星快捷方式like in this answer 更新位置“entry_index”处的条目。 但我找不到proper method in the docs。
有谁知道如何做到这一点?
感谢您的帮助!
马夫
【问题讨论】:
标签: python dictionary peewee