栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

2021-11-08

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/445102.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号