在python中多次打印功能打印

时间:2017-10-23 11:43:13

标签: python python-3.x python-docx

我在docx这个词中计算表格和行的脚本效果很好。我的问题是为什么我的打印声明打印直到条件失败。我附上图片供您参考

enter image description here

这是我的代码:

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)

帮帮我。谢谢!

1 个答案:

答案 0 :(得分:1)

上次打印语句缩进的问题 试试这个

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)