#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()

最新文章

  1. 利用DetachedCriteria构建HQL参数动态匹配
  2. 重新走过HTML,那些让我amazing 的标签
  3. Eddy's problem partI
  4. jq实现动态添加样式
  5. Neutron LBaaS Service(1)—— Neutron LBaaS Service基本知识
  6. TypeScript 素描 - 装饰器
  7. log4j 突然不打印记录,提示:No appenders could be found for logge,处理方法
  8. nodejs partials 分布视图
  9. QTextEdit控件使用
  10. sql优化原则与技巧
  11. Tag功能介绍—我们为什么打Tag?
  12. Angular2+ 实现组件交互的众多方式
  13. Java中关于quartz定时任务时间设置
  14. ubuntu搭建php开发环境记录
  15. 数据分析与挖掘 - R语言:贝叶斯分类算法(案例三)
  16. 11.8 开课二个月零四天 (Jquery取属性值,做全选,去空格)
  17. IT技术需求建立时需考虑的因素
  18. TCP 的连接建立:采用三报文握手
  19. Java并发编程之happens-before
  20. start_kernel之前的汇编代码分析

热门文章

  1. javascript的介绍,实现和输出以及语法-javascript学习之旅(1)
  2. Unity热更新之C#反射动态获取类属性及方法
  3. 开源网络监控管理系统:OpenNMS
  4. java工具类(四)之实现日期任意跳转
  5. ITU-R BT.1788建议书 对多媒体应用中视频质量的主观评估方法
  6. iOS监听模式系列之NSNotificationCenter的简单使用
  7. overridePendingTransition的简介
  8. LeetCode之“动态规划”:Maximal Square && Largest Rectangle in Histogram && Maximal Rectangle
  9. Stackoverflow上人气最旺的10个Java问题
  10. Struts-ValueStack和OGNL总结