python中的sqlite3 把一个链表当做一个元素插入到数据库_表中一行记录中的一个属性中
1个回答
展开全部
>>> import sqlite3
>>>
>>> conn = sqlite3.connect(":memory:")
>>> conn.executescript("""
... create table tester (id integer primary key, lst);
... """)
<sqlite3.Cursor object at 0xb7447460>
>>> conn.commit()
>>> curr = conn.cursor()
>>> curr.executemany("insert into tester (id, lst) values (?, ?)", [
... (1, repr(range(10))),
... (2, repr(range(20))),
... (3, repr(range(30))),
... ])
<sqlite3.Cursor object at 0xb7447be0>
>>> conn.commit()
>>> curr.execute("select * from tester")
<sqlite3.Cursor object at 0xb7447be0>
>>> for id, lst in curr:
... print id, eval(lst)
...
1 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
2 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
3 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
>>>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询