代码为什么执行不起来

来源:3-5 案例:简历筛选

GEM意

2025-03-27 15:04:26

import glob

from docx import Document
class ReadDoc(object):
    def __init__(self,path):
        self.doc=Document(path)
        self.p_text=""
        self.table_text=""
        self.get_para()
        self.get_tables()

    def get_para(self):
        for p in self.doc.paragraphs:
            self.p_text+=p.text
    def get_tables(self):
        for table in self.doc.tables:
            for row in table.rows:
                _cell_str = ''
                for cell in row.cells:
                    _cell_str += cell.text + ','
                self.table_text += _cell_str + '\n'

def search(path,targets):
    result=glob.glob(path)
    a = []
    for i in result:
        isuse = True
        if glob.os.path.isfile(i):
            if i.endswith(".docx"):
                doc=ReadDoc(i)
                p_text=doc.p_text
                t_text=doc.table_text
                all_text=p_text+t_text
                for target in targets:
                    if target not in all_text:
                        isuse=False
                        break
                if not isuse:
                    continue
                a.append(i)
    return a
path=glob.os.path.join(glob.os.getcwd(),"*")
search(path,['python'])


写回答

1回答

好帮手慕小猿

2025-03-27

同学,你好!同学代码执行起来了,只是查找到的文件放在了search函数的返回值a中了,同学需要将函数返回值打印下就会出结果的,修改代码如下:

https://img1.sycdn.imooc.com/climg/e7ecc46709e5005604820099.jpg

祝学习愉快~

0

Python全能工程师

8阶段5大热门领域,从入门到实战,带你从零基础晋级全能,全面提升就业力

1606 学习 · 989 问题

查看课程