Python_doc文件写入SQLite数据库
2024-09-20 05:30:06
#docx文档题库包含很多段,每段一个题目,格式为:问题。(答案)
#数据库datase.db中tiku表包含kechengmingcheng、zhanngji、timu、daan四个字段
import sqlite3
from docx import Document doc = Document('《Python程序设计》题库.docx') #连接数据库
conn = sqlite3.connect('database.db')
cur = conn.cursor() #先清空原来的题目,可选操作
# cur.execute('delete from tiku')
# conn.commit() for p in doc.paragraphs:
text = p.text
if '(' in text and ')'in text:
index = text.index('(')
#分离问题和答案
question=text[:index]
if '___' in question:
question = '填空题:' + question
else:
question = '判断题:' + question
answer=text[index+1:-1]
#将数据写入数据库
sql = 'insert into tiku(kechengmingcheng,zhanngji,timu,daan)values("Python程序设计","未分类","'+question+'","'+answer+'")'
cur.execute(sql)
conn.commit()
#关闭数据库连接
conn.close()
最新文章
- 利用DetachedCriteria构建HQL参数动态匹配
- 重新走过HTML,那些让我amazing 的标签
- Eddy's problem partI
- jq实现动态添加样式
- Neutron LBaaS Service(1)—— Neutron LBaaS Service基本知识
- TypeScript 素描 - 装饰器
- log4j 突然不打印记录,提示:No appenders could be found for logge,处理方法
- nodejs partials 分布视图
- QTextEdit控件使用
- sql优化原则与技巧
- Tag功能介绍—我们为什么打Tag?
- Angular2+ 实现组件交互的众多方式
- Java中关于quartz定时任务时间设置
- ubuntu搭建php开发环境记录
- 数据分析与挖掘 - R语言:贝叶斯分类算法(案例三)
- 11.8 开课二个月零四天 (Jquery取属性值,做全选,去空格)
- IT技术需求建立时需考虑的因素
- TCP 的连接建立:采用三报文握手
- Java并发编程之happens-before
- start_kernel之前的汇编代码分析
热门文章
- javascript的介绍,实现和输出以及语法-javascript学习之旅(1)
- Unity热更新之C#反射动态获取类属性及方法
- 开源网络监控管理系统:OpenNMS
- java工具类(四)之实现日期任意跳转
- ITU-R BT.1788建议书 对多媒体应用中视频质量的主观评估方法
- iOS监听模式系列之NSNotificationCenter的简单使用
- overridePendingTransition的简介
- LeetCode之“动态规划”:Maximal Square &;&; Largest Rectangle in Histogram &;&; Maximal Rectangle
- Stackoverflow上人气最旺的10个Java问题
- Struts-ValueStack和OGNL总结