python-docx模块
# C:UsersBJ075BDesktopdiy-ask-bottest_docx.py # C:UsersBJ075BDesktopdiy-ask-bottcp.docx # import docx from colorama import init,Fore,Back,Style # import sphinx.quickstart init(autoreset=True) from datetime import datetime from docx import document import time import re # path = r"C:UsersBJ075BDesktopdiy-ask-bottcp.docx" path = 'C:\Users\BJ075B\Desktop\diy-ask-bot\tcp-all.docx' document = document(path) print("document type:", type(document)) print("document paragraphs type:", type(document.paragraphs)) # print(document.paragraphs[0].text) num_str = str(1) for paragraph in document.paragraphs: if paragraph.text.startswith("正确答案"):# 输入答案后 再来下一题 right_list = re.findall(r'd+', paragraph.text) right_ans = ','.join(right_list) myans = input("请输入您的选择(多选以英文逗号分割):") # print(Fore.RED + 'some red text') if myans == right_ans: print(Fore.BLUE + '答对了!' + Fore.BLUE + paragraph.text) else: print(Fore.RED + '答错喽~' + Fore.RED + paragraph.text) # print('33[1;34m', paragraph.text) elif paragraph.text.startswith( num_str + "0 、"): print('第10题到喽 、 paragraph.text.startwith 触发 , end.') break else: print(Fore.GREEN + paragraph.text)
#!/usr/bin/env python # -*- coding:utf-8 -*- lst = [1,2,3,4,5] str = '-'.join(str(n) for n in lst) print(str)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)