首页 > 解决方案 > 如何使用 Python 将值存储在数组中

问题描述

我有一个关于简历筛选软件的程序。在这个程序中,我将关键字与申请人的简历进行匹配,并在匹配的基础上对每份简历进行评分。现在我想将得分值存储在一个数组中,我尝试了许多逻辑来存储该值,但输出是

zs[t] = score
IndexError: list assignment index out of range

我的项目代码是

import re
import fitz
import os

# call the Resume files by calling the folder name
for filename in os.listdir('resume/'):

    # Select only PDF files
    if filename.endswith('.pdf'):
        print(filename)
        os.chdir('C:/Users/M. Abrar Hussain/Desktop/cv/resume')
        pdfFileObj = open(filename, 'rb')

        t = 0
        zs = []
        # Extract the text Data from resume files
        with fitz.open(pdfFileObj) as doc:
            text = ""
            for page in doc:
                text += page.getText()
            print(text)

            # Splitting the Resume Data into many indexes of Array
            p = doc.loadPage(0)
            p_text = p.getText()
            p_lines = p_text.splitlines()

            split_lst = [i.split(': ', 1) for i in p_lines]
            d = {a: b.rstrip() for a, b in split_lst}

            f = d["Name"]
            g = d["GPA"]
            h = d["Skills"]
            i = d["Experience"]
            p = re.findall(r"[-+]?\d*\.\d+|\d+", i)

            # search the keywords with the data that extract from resume
            search_keywords = ['Laravel', 'Java', 'Python']
            search_exp = ['1', '1.5', '2', '2.5', '3']
            search_gpa = ['2.5', '2.6', '2.7', '2.8', '2.9', '3.0', '3.1', '3.2', '3.3', '3.4', '3.5', '3.6', '3.7',
                          '3.8', '3.9', '4.0']

            # Comparing GPA data with the keywords
            lst = []
            for gpa in search_gpa:
                if gpa in g:
                    lst.append(gpa)

            # Comparing Skills data with keywords
            lst1 = []
            for word in search_keywords:
                if word in h:
                    lst1.append(word)

            # Comparing Experience data with keywords
            lst2 = []
            for exp in search_exp:
                if exp in p:
                    lst2.append(exp)

            # Scoring the Extracted data to see the best resume
            score = 0
            w1 = []

            # Scoring the GPA
            for w1 in lst:
                if '3.0' <= w1 < '3.5':
                    score += 1
                if '3.5' <= w1 <= '4':
                    score += 2

            # Scoring the SKills
            for w1 in lst1:
                if w1 == 'Laravel':
                    score += 2
                if w1 == 'Python':
                    score += 2
                if w1 == 'Java':
                    score += 1

            # Scoring the Experience
            for w1 in lst2:
                if '2.5' <= w1 < '3':
                    score += 0.5
                if '3' <= w1 < '3.5':
                    score += 1
                if '3.5' <= w1:
                    score += 2

            zs[t] = score
            t = t+1
            print("%s has Scored %s" % (f, score))
            print('\n')

            pdfFileObj.close()

print(zs[0])

这是我项目的完整程序。现在在这个程序中 zs[] 是一个存储分数值的数组,最后打印数组

标签: pythonarrays

解决方案


推荐阅读