def new(self, c):
"""
Insert a new creature in the DB, and set c.id accordingly
"""
assert c.id is None
# create a new row in the DB, to generate an ID
self.cur.execute("INSERT INTO creatures(id) VALUES(NULL)")
c.id = self.cur.lastrowid
born_at = self.generation
pickled = pickle.dumps(c)
# save the updated c
self.cur.execute("""
UPDATE creatures
SET born_at = ?, pickled = ?
WHERE id = ?
""", (born_at, pickled, c.id))
评论列表
文章目录