2021-11-08

2021-11-08,第1张

2021-11-08

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)

PYTHON JOIN()逗号分割列表
以 ‘=分割’

#!/usr/bin/env python
# -*- coding:utf-8 -*-

lst = [1,2,3,4,5]
str = '-'.join(str(n) for n in lst)
print(str)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5160489.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-18
下一篇 2022-11-18

发表评论

登录后才能评论

评论列表(0条)

保存