python sqlite3等模块进行数据库操作

2022-05-23  本文已影响0人  孙广宁
6.8 我们想对数据库进行CRUD操作
>>> import sqlite3
>>> db = sqlite3.connect("db.sqlite3")
>>> c =db.cursor()

>>> for row in c.execute("select * from AppModel_examscore"):
...     print(row)
...
(1, '麦', '18', '111', 100, '5', '0', '2022-04-17 13:35:35.996402')
(2, '麦', '18', '111', 98, '5', '1', '2022-04-17 13:35:49.384957')
>>>
>>> c.execute("create table test( s text,sh integer)")
<sqlite3.Cursor object at 0x10ee6a180>
>>> db.commit()
>>> stocks =[(1,2,3,),(5,6,7)]
>>> c.executemany('instert into test value(?,?,?)',stocks)
>>> db.commit()
上一篇 下一篇

猜你喜欢

热点阅读