繁体   English   中英

在python中多次打印打印功能

[英]Print function printing multiple times in python

我用于计算 docx 一词中的表和行的脚本运行良好。 我的问题是为什么我的打印语句打印到条件失败。 我附上了图片供您参考

在此处输入图片说明

这是我的代码:

from docx import Document
doc = Document("sample2.docx")
i = 0
for t in doc.tables:
    for ro in t.rows:
        if ro.cells[0].text=="Test Type" and (ro.cells[2].text=="Black Box" or ro.cells[2].text=="Black-Box"):
            i=i+1
print("Total Black Box Tests are: ", i)

j=0
for table in doc.tables:
    for row in table.rows:
        if row.cells[0].text=="ID":
            j=j+1
            print("Total no of Tables:", j)

帮我。 谢谢!

最后一个打印语句的缩进问题试试这个

from docx import Document
doc = Document("sample2.docx")
i = 0
for t in doc.tables:
    for ro in t.rows:
        if ro.cells[0].text=="Test Type" and (ro.cells[2].text=="Black Box" or ro.cells[2].text=="Black-Box"):
            i=i+1
print("Total Black Box Tests are: ", i)

j=0
for table in doc.tables:
    for row in table.rows:
        if row.cells[0].text=="ID":
            j=j+1
print("Total no of Tables:", j)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM