db.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:evolvingcopter 作者: antocuni 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号