前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python sqlite 增删改查 操作

python sqlite 增删改查 操作

作者头像
用户5760343
发布2022-05-13 09:25:17
3240
发布2022-05-13 09:25:17
举报
文章被收录于专栏:sktj

from sqlite3 import connect conn = connect('dbase1') curs = conn.cursor() try: curs.execute('drop table people') except: pass # did not exist curs.execute('create table people (name char(30), job char(10), pay int(4))')

curs.execute('insert into people values (?, ?, ?)', ('Bob', 'dev', 50000)) curs.execute('insert into people values (?, ?, ?)', ('Sue', 'dev', 60000))

curs.execute('select * from people') for row in curs.fetchall(): print(row)

curs.execute('select * from people') colnames = [desc[0] for desc in curs.description] while True: print('-' * 30) row = curs.fetchone() if not row: break for (name, value) in zip(colnames, row): print('%s => %s' % (name, value))

conn.commit() # save inserted records

把TXT文件中的数据插入数据库

image.png

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-05-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 把TXT文件中的数据插入数据库
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档